Created
March 20, 2014 14:35
-
-
Save bakyeono/92df2b4446bc1eebe410 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 <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