2018-11-06 10:46:40 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdlib.h>
|
2018-11-17 15:56:09 +01:00
|
|
|
#include <fcntl.h>
|
2018-11-06 10:46:40 +01:00
|
|
|
#include <assert.h>
|
2018-10-26 11:16:56 +02:00
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
2019-02-03 12:38:03 +01:00
|
|
|
const char* input_file = argc > 1 ? argv[1] : "/dev/stdin";
|
|
|
|
|
int fd = open(input_file, O_RDONLY);
|
2018-10-26 11:16:56 +02:00
|
|
|
if (fd == -1) {
|
2019-02-03 12:38:03 +01:00
|
|
|
printf("failed to open %s: %s\n", input_file, strerror(errno));
|
2018-10-26 11:16:56 +02:00
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
for (;;) {
|
2018-11-08 01:23:23 +01:00
|
|
|
char buf[4096];
|
2018-10-26 11:16:56 +02:00
|
|
|
ssize_t nread = read(fd, buf, sizeof(buf));
|
|
|
|
|
if (nread == 0)
|
|
|
|
|
break;
|
|
|
|
|
if (nread < 0) {
|
|
|
|
|
printf("read() error: %s\n", strerror(errno));
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
2018-11-08 01:23:23 +01:00
|
|
|
write(1, buf, nread);
|
2018-10-26 11:16:56 +02:00
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|