Moved to using optind

This commit is contained in:
Gitea 2020-12-13 14:17:23 -06:00
parent ae31e82b64
commit c21c4b2739

9
tee.c
View file

@ -17,20 +17,13 @@ int main(int argc, char * argv[]) {
case 'i': signal(SIGINT, SIG_IGN); break;
}
}
while(strcmp("-a", argv[start_arg]) == 0 ||
strcmp("-i", argv[start_arg]) == 0 ||
strcmp("-ai", argv[start_arg]) == 0 ||
strcmp("-ia", argv[start_arg]) == 0) {
start_arg++;
}
FILE * files[27] = { 0 };
char * mode = append_mode == 1 ? "a+" : "w+";
int j = 0;
for(int i = start_arg; i < argc && j < 27; i++) {
for(int i = optind; i < argc && j < 27; i++) {
files[j++] = fopen(argv[i], mode);
if(files == NULL) {
fprintf(stderr, "%s: could not open/create file %s\n", argv[0], argv[i]);