1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
char buf[BUFSIZ];
const char * const utf8bom = "\xef\xbb\xbf";
static void usage(const char *);
static void
usage(const char * const prog)
{
fprintf(stderr, "usage: %s\n", prog);
exit(1);
}
int
main(const int argc, const char * const argv[])
{
size_t nread;
if (argc > 1)
usage(argv[0]);
nread = fread(buf, 1, strlen(utf8bom), stdin);
if (nread == 0)
return 0;
if (strcmp(buf, utf8bom) != 0)
if (fwrite(buf, 1, nread, stdout) < nread)
exit(1);
for (;;) {
nread = fread(buf, 1, sizeof buf, stdin);
if (nread == 0)
return ferror(stdin) && 1;
if (fwrite(buf, 1, nread, stdout) < nread)
exit(1);
}
return 0;
}
|