Commits

Robert Lowry committed 7c4f934

added #ifdef __linux__'s to the linux specific code

Comments (0)

Files changed (1)

 
 #include <sys/ioctl.h>
 #include <sys/select.h>
+
+#ifdef __linux__
 #include <sys/inotify.h>
+#endif
 
-#define STDOUT 1
 #define MAX(a,b) (((a) > (b)) ? (a) : (b))
 
 FILE *in, *out;
 
 int main(int argc, char **argv)
 {
+#ifdef __linux__
 	int evq, in_wd;
+#endif
 	fd_set rd;
 
 	if (argc != 3) {
 		printf("cw-"VERSION" © Evan Gates\n");
 		exit(1);
 	}
+
 	if (signal(SIGWINCH, sigwinch) == SIG_ERR)
 		err(1, "failed to install sigwinch handler");
 
 	if ((in = fopen(argv[1], "r")) == NULL)
 		err(1, "failed to fopen %s", argv[1]);
 
+#ifdef __linux__
 	if ((evq = inotify_init()) < 0)
 		err(1, "failed inotify_init()");
-
 	if ((in_wd = inotify_add_watch(evq, argv[1], IN_MODIFY)) < 0)
 		err(1, "failed inotify_add_watch()");
+#endif
 
 	while (fgets(buf, sizeof(buf), in))
 		fputs(buf, stdout);
 		FD_SET(evq, &rd);
 		FD_SET(fileno(stdin), &rd);
 
+#ifdef __linux__
 		if (select(evq + 1, &rd, 0, 0, NULL) < 0) {
+#else
+		if (select(fileno(stdin) + 1, &rd, 0, 0, NULL) < 0) {
+#endif
 		    if (errno == EINTR)
 			continue;
 		    else
 			warn("error on select");
 		}
 
+#ifdef __linux__
 		if (FD_ISSET(evq, &rd)) {
 			if (read(evq, buf, sizeof(buf)) < 0 && errno != EINTR)
 				err(1, "failed read() on evq");
 				fputs(buf, stdout);
 			fflush(stdout);
 		}
+#endif
 		if (FD_ISSET(fileno(stdin), &rd)) {
 			if (fgets(buf, sizeof(buf), stdin))
 				fputs(buf, out);