version 1.15, 2016/08/14 18:34:48 |
version 1.16, 2016/10/28 07:22:59 |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
#include <locale.h> |
|
|
|
#include "extern.h" |
#include "extern.h" |
|
|
int lflag, sflag; |
int lflag, sflag; |
|
|
static void usage(void); |
static void __dead usage(void); |
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
|
|
int ch, fd1, fd2, special; |
int ch, fd1, fd2, special; |
char *file1, *file2; |
char *file1, *file2; |
|
|
setlocale(LC_ALL, ""); |
|
|
|
if (pledge("stdio rpath", NULL) == -1) |
if (pledge("stdio rpath", NULL) == -1) |
err(ERR_EXIT, "pledge"); |
err(ERR_EXIT, "pledge"); |
|
|
|
|
case 's': /* silent run */ |
case 's': /* silent run */ |
sflag = 1; |
sflag = 1; |
break; |
break; |
case '?': |
|
default: |
default: |
usage(); |
usage(); |
} |
} |
|
|
file1 = "stdin"; |
file1 = "stdin"; |
} else if ((fd1 = open(file1, O_RDONLY, 0)) < 0) { |
} else if ((fd1 = open(file1, O_RDONLY, 0)) < 0) { |
if (sflag) |
if (sflag) |
exit(ERR_EXIT); |
return ERR_EXIT; |
else |
else |
err(ERR_EXIT, "%s", file1); |
err(ERR_EXIT, "%s", file1); |
} |
} |
if (strcmp(file2 = argv[1], "-") == 0) { |
if (strcmp(file2 = argv[1], "-") == 0) { |
if (special) { |
if (special) { |
if (sflag) |
if (sflag) |
exit(ERR_EXIT); |
return ERR_EXIT; |
else |
else |
errx(ERR_EXIT, |
errx(ERR_EXIT, |
"standard input may only be specified once"); |
"standard input may only be specified once"); |
|
|
file2 = "stdin"; |
file2 = "stdin"; |
} else if ((fd2 = open(file2, O_RDONLY, 0)) < 0) { |
} else if ((fd2 = open(file2, O_RDONLY, 0)) < 0) { |
if (sflag) |
if (sflag) |
exit(ERR_EXIT); |
return ERR_EXIT; |
else |
else |
err(ERR_EXIT, "%s", file2); |
err(ERR_EXIT, "%s", file2); |
} |
} |
|
|
if (!special) { |
if (!special) { |
if (fstat(fd1, &sb1)) { |
if (fstat(fd1, &sb1)) { |
if (sflag) |
if (sflag) |
exit(ERR_EXIT); |
return ERR_EXIT; |
else |
else |
err(ERR_EXIT, "%s", file1); |
err(ERR_EXIT, "%s", file1); |
} |
} |
|
|
else { |
else { |
if (fstat(fd2, &sb2)) { |
if (fstat(fd2, &sb2)) { |
if (sflag) |
if (sflag) |
exit(ERR_EXIT); |
return ERR_EXIT; |
else |
else |
err(ERR_EXIT, "%s", file2); |
err(ERR_EXIT, "%s", file2); |
} |
} |
|
|
return 0; |
return 0; |
} |
} |
|
|
static void |
static void __dead |
usage(void) |
usage(void) |
{ |
{ |
|
|