]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
c++-ize unlinkd
authorFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 9 Jul 2015 09:20:31 +0000 (11:20 +0200)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Thu, 9 Jul 2015 09:20:31 +0000 (11:20 +0200)
src/unlinkd_daemon.cc

index c39817437f3c50f6c1a2a1e204ec7a297d301af4..fa0d0e0fcbf86ef77d7bc33020e66acb878aef7b 100644 (file)
@@ -12,6 +12,8 @@
 
 #include "squid.h"
 
+#include <iostream>
+#include <cstdio>
 #if HAVE_PATHS_H
 #include <paths.h>
 #endif
 int
 main(int, char *[])
 {
-    char buf[UNLINK_BUF_LEN];
-    char *t;
-    int x;
-    setbuf(stdin, NULL);
-    setbuf(stdout, NULL);
+    std::string sbuf;
     close(2);
     if (open(_PATH_DEVNULL, O_RDWR) < 0) {
         ; // the irony of having to close(2) earlier is that we cannot report this failure.
     }
-
-    while (fgets(buf, sizeof(buf), stdin)) {
-        if ((t = strchr(buf, '\n')))
-            *t = '\0';
-        x = unlink(buf);
-        if (x < 0)
-            printf("ERR\n");
+    while (getline(std::cin, sbuf)) {
+        // tailing newline is removed by getline
+        const int rv = remove(sbuf.c_str());
+        if (rv < 0)
+            std::cout << "ERR" << std::endl; // endl flushes
         else
-            printf("OK\n");
+            std::cout << "OK" << std::endl;
     }
 
     return 0;