Compare commits
No commits in common. "670e38e25147b1630f1c7f22d43e2164dbea7484" and "44cbb986944a0f96937ea4bd8ed991da8c0ae7fc" have entirely different histories.
670e38e251
...
44cbb98694
|
@ -1,26 +0,0 @@
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int usage(char *argv0) {
|
|
||||||
printf("Usage: %s\n", argv0);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
|
||||||
int opt;
|
|
||||||
while ((opt = getopt(argc, argv, ":")) != -1) {
|
|
||||||
switch (opt) {
|
|
||||||
case '?':
|
|
||||||
fprintf(stderr, "%s: invalid option -- '%c'\n", argv[0], optopt);
|
|
||||||
return usage(argv[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getlogin() != NULL) {
|
|
||||||
printf("%s\n", getlogin());
|
|
||||||
} else {
|
|
||||||
perror(argv[0]);
|
|
||||||
}
|
|
||||||
return errno;
|
|
||||||
}
|
|
50
src/tee.c
50
src/tee.c
|
@ -1,50 +0,0 @@
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <signal.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int usage(char *argv0) {
|
|
||||||
printf("Usage: %s [-ai] [file ...]\n", argv0);
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
|
||||||
int opt;
|
|
||||||
bool append = false;
|
|
||||||
bool iflag = false;
|
|
||||||
while ((opt = getopt(argc, argv, ":ai")) != -1) {
|
|
||||||
switch (opt) {
|
|
||||||
case 'a':
|
|
||||||
append = true;
|
|
||||||
break;
|
|
||||||
case 'i':
|
|
||||||
iflag = true;
|
|
||||||
break;
|
|
||||||
case '?':
|
|
||||||
fprintf(stderr, "%s: invalid option -- '%c'\n", argv[0], optopt);
|
|
||||||
return usage(argv[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (iflag && signal(SIGINT, SIG_IGN) == SIG_ERR) {} // FIXME
|
|
||||||
|
|
||||||
int arg = optind;
|
|
||||||
void *buf[BUFSIZ];
|
|
||||||
FILE *file;
|
|
||||||
ssize_t n;
|
|
||||||
|
|
||||||
while ((n = read(0, buf, sizeof(buf))) > 0) {
|
|
||||||
optind = arg;
|
|
||||||
if (optind < argc) {
|
|
||||||
for (; optind < argc; optind++) {
|
|
||||||
file = fopen(argv[optind], append ? "w" : "a+");
|
|
||||||
fwrite(buf, BUFSIZ, 1, file);
|
|
||||||
fclose(file);
|
|
||||||
append = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
fwrite(buf, BUFSIZ, 1, stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue