11 |
|
#include <string.h> |
12 |
|
|
13 |
|
#include "platform.h" |
14 |
+ |
#include "rtprocess.h" |
15 |
|
#include "resolu.h" |
16 |
|
|
17 |
|
#ifdef getc_unlocked /* avoid nasty file-locking overhead */ |
18 |
+ |
#undef getc |
19 |
|
#undef getchar |
20 |
|
#undef putchar |
21 |
+ |
#define getc getc_unlocked |
22 |
|
#define getchar getchar_unlocked |
23 |
|
#define putchar putchar_unlocked |
24 |
|
#endif |
25 |
|
|
23 |
– |
#ifdef _WIN32 |
24 |
– |
#define execvp _execvp |
25 |
– |
#endif |
26 |
– |
|
26 |
|
static gethfunc tabstr; |
27 |
|
static void getdim(FILE *fp); |
28 |
|
static void copycat(void); |
61 |
|
} else if (argc > 2 && !strcmp(argv[1], "-c")) { |
62 |
|
SET_FILE_BINARY(stdin); |
63 |
|
SET_FILE_BINARY(stdout); |
64 |
+ |
setvbuf(stdin, NULL, _IONBF, 2); |
65 |
|
getheader(stdin, (gethfunc *)fputs, stdout); |
66 |
|
printargs(argc-2, argv+2, stdout); |
67 |
|
fputc('\n', stdout); |
69 |
|
execvp(argv[2], argv+2); |
70 |
|
perror(argv[2]); |
71 |
|
return 1; |
72 |
+ |
} else if (argc > 2 && !strcmp(argv[1], "-a")) { |
73 |
+ |
SET_FILE_BINARY(stdin); |
74 |
+ |
SET_FILE_BINARY(stdout); |
75 |
+ |
getheader(stdin, (gethfunc *)fputs, stdout); |
76 |
+ |
for (i = 2; i < argc; i++) { |
77 |
+ |
int len = strlen(argv[i]); |
78 |
+ |
if (!len) continue; |
79 |
+ |
fputs(argv[i], stdout); |
80 |
+ |
if (argv[i][len-1] != '\n') |
81 |
+ |
fputc('\n', stdout); |
82 |
+ |
} |
83 |
+ |
fputc('\n', stdout); |
84 |
+ |
copycat(); |
85 |
+ |
return 0; |
86 |
|
} else if (argc == 2 && !strcmp(argv[1], "-")) { |
87 |
|
SET_FILE_BINARY(stdin); |
88 |
|
SET_FILE_BINARY(stdout); |
159 |
|
copycat(void) /* copy input to output */ |
160 |
|
{ |
161 |
|
char buf[8192]; |
162 |
< |
ssize_t n; |
162 |
> |
int n; |
163 |
|
|
164 |
|
fflush(stdout); |
165 |
|
while ((n = fread(buf, 1, sizeof(buf), stdin)) > 0) |
166 |
< |
if (write(fileno(stdout), buf, n) != n) |
166 |
> |
if (writebuf(fileno(stdout), buf, n) != n) |
167 |
|
break; |
168 |
|
} |