Source

pcw / cw.c

Diff from to
 #include <err.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 
 int main(int argc, char **argv)
 {
-	int evq, len;
+	int evq, len, fd;
 	int in_wd = 0, out_wd = 0;
 	struct inotify_event *cur;
 	fd_set rd;
 	if ((in_wd = inotify_add_watch(evq, argv[1], IN_MODIFY)) < 0)
 		err(1, "failed inotify_add_watch on %s", argv[1]);
 
-	if ((out = fopen(argv[2], "w")) == NULL)
-		err(1, "failed to fopen %s", argv[2]);
+	if ((fd = open(argv[2], O_WRONLY)) < 0)
+		err(1, "failed to open %s", argv[2]);
+	if ((out = fdopen(fd, "w")) == NULL)
+		err(1, "failed to fdopen %s on fd %d", argv[2], fd);
 	if ((out_wd = inotify_add_watch(evq, argv[2], IN_CLOSE_NOWRITE)) < 0)
 		err(1, "failed inotify_add_watch on %s", argv[2]);