From: Francesco Chemolli Date: Thu, 9 Jul 2015 09:20:31 +0000 (+0200) Subject: c++-ize unlinkd X-Git-Tag: merge-candidate-3-v1~58 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee74db84d2cf476c8f4a1d4942eae9f94c677678;p=thirdparty%2Fsquid.git c++-ize unlinkd --- diff --git a/src/unlinkd_daemon.cc b/src/unlinkd_daemon.cc index c39817437f..fa0d0e0fcb 100644 --- a/src/unlinkd_daemon.cc +++ b/src/unlinkd_daemon.cc @@ -12,6 +12,8 @@ #include "squid.h" +#include +#include #if HAVE_PATHS_H #include #endif @@ -49,24 +51,18 @@ 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;