Skip to content

Instantly share code, notes, and snippets.

@potatosalad
Created April 7, 2022 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save potatosalad/14aa525e5cce402c03922e161796e6b7 to your computer and use it in GitHub Desktop.
Save potatosalad/14aa525e5cce402c03922e161796e6b7 to your computer and use it in GitHub Desktop.
#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