diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-24 22:50:04 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-24 22:50:04 +0200 |
commit | 9033e315203d34c5b6a95d31dbd857aef5e5e19a (patch) | |
tree | dc2521e8f08b619c80d061156db2bfa070cec939 | |
parent | c7a4b43a671dd9cdde1fad781e80c59e8cde5e56 (diff) | |
download | when-master.tar.gz |
-rw-r--r-- | when.c | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -10,7 +10,7 @@ #define MAXFD 127 /* FD + MAXFILES */ int -main(int argc, char *argv[argc]) +main(int argc, char *argv[]) { char *filenames[MAXFD]; int fd, i, kq, n; @@ -18,29 +18,29 @@ main(int argc, char *argv[argc]) struct kevent ev[MAXFILES]; /* parse arguments */ - if (argc-1 == 0) goto usage; - if (argv[1][0] == '-') { - if (argv[1][1] == 'i') + if(argc-1 == 0) goto usage; + if(argv[1][0] == '-'){ + if(argv[1][1] == 'i') for (i = 2; i < argc; i++) printf("%s\n", argv[i]); - else if (argv[1][1] == '-') ; + else if(argv[1][1] == '-') ; else goto usage; argv++; argc--; } - if (argc-1 == 0) goto usage; - if (argc-1 > MAXFILES) + if(argc-1 == 0) goto usage; + if(argc-1 > MAXFILES) errx(1, "more than %d files", MAXFILES); /* disable buffering even non-interactively */ setbuf(stdout, NULL); /* initialize kqueue */ - if ((kq = kqueue()) == -1) + if((kq = kqueue()) == -1) err(1, "kqueue"); /* process each file */ - for (i = 1; i < argc; i++) { - if ((fd = open(argv[i], O_RDONLY)) == -1) + for (i = 1; i < argc; i++){ + if((fd = open(argv[i], O_RDONLY)) == -1) err(1, "%s", argv[i]); filenames[fd] = argv[i]; @@ -49,19 +49,19 @@ main(int argc, char *argv[argc]) } /* register events to watch for */ - if (kevent(kq, ev, argc-1, NULL, 0, NULL) == -1) + if(kevent(kq, ev, argc-1, NULL, 0, NULL) == -1) err(1, "kevent"); - for (;;) { - if ((n = kevent(kq, NULL, 0, evs, argc-1, NULL)) == -1) + for (;;){ + if((n = kevent(kq, NULL, 0, evs, argc-1, NULL)) == -1) err(1, "kevent"); - for (i = 0; i < n; i++) { - if (evs[i].fflags & NOTE_WRITE) + for (i = 0; i < n; i++){ + if(evs[i].fflags & NOTE_WRITE) printf("%s\n", filenames[evs[i].ident]); - if (evs[i].flags & EV_ERROR) + if(evs[i].flags & EV_ERROR) fprintf(stderr, "event error: %s\n", strerror(evs[i].data)); - if (evs[i].fflags & NOTE_DELETE) { + if(evs[i].fflags & NOTE_DELETE){ fprintf(stderr, "%s deleted\n", filenames[evs[i].ident]); close(evs[i].ident); |