Skip to content

Instantly share code, notes, and snippets.

@bakyeono
Created March 20, 2014 14:35
Show Gist options
  • Save bakyeono/92df2b4446bc1eebe410 to your computer and use it in GitHub Desktop.
Save bakyeono/92df2b4446bc1eebe410 to your computer and use it in GitHub Desktop.
#include <unistd.h>
#include <stdlib.h>
#define STDIN 0
#define STDOUT 1
#define STDERR 2
int main (int argc, char** argv) {
const int buffer_size = 128;
char buffer[buffer_size];
// Reads a c-string from standard input
int nread;
nread = read(STDIN, buffer, buffer_size);
if (nread == -1) {
write(STDERR, "A read error has occurred\n", 26);
}
// Writes a c-string to standard output (or to standard error).
size_t nwrite;
nwrite = write(STDOUT, buffer, nread);
if (nwrite == nread) {
return 0;
}
write(STDERR, "A write error has occured on file descriptor 1\n", 46);
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment