Created
April 7, 2022 17:58
-
-
Save potatosalad/14aa525e5cce402c03922e161796e6b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <inttypes.h> | |
#include <stdint.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
int | |
main(void) | |
{ | |
uint8_t buffer[65536]; // 64KB | |
ssize_t bytes_read; | |
ssize_t bytes_written; | |
ssize_t i; | |
do { | |
bytes_read = read(STDIN_FILENO, buffer, sizeof(buffer) / sizeof(uint8_t)); | |
if (bytes_read > 0) { | |
bytes_written = 0; | |
do { | |
if ((i = write(STDOUT_FILENO, buffer + bytes_written, bytes_read - bytes_written)) <= 0) { | |
return 0; | |
} | |
bytes_written += i; | |
} while (bytes_written < bytes_read); | |
} | |
} while (bytes_read > 0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment