From: mmj Date: Mon, 22 Nov 2004 12:25:01 +0000 (+1100) Subject: Change statctrl to only return a file is not there, if stat() explicitly said so X-Git-Tag: RELEASE_1_1_0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2a483d4cea31367a2ee7b5be87f778657793a58b;p=thirdparty%2Fmlmmj.git Change statctrl to only return a file is not there, if stat() explicitly said so --- diff --git a/src/mygetline.c b/src/mygetline.c index 84bb3002..2959713e 100644 --- a/src/mygetline.c +++ b/src/mygetline.c @@ -33,9 +33,9 @@ char *mygetline(int fd) { size_t i = 0, res, buf_size = BUFSIZE; /* initial buffer size */ - char *buf = mymalloc(buf_size); - char ch; + char *buf, ch; + buf = mymalloc(buf_size); buf[0] = '\0'; while(1) { res = read(fd, &ch, 1); diff --git a/src/statctrl.c b/src/statctrl.c index 99c1b042..137132d0 100644 --- a/src/statctrl.c +++ b/src/statctrl.c @@ -24,10 +24,12 @@ #include #include #include +#include #include "strgen.h" #include "statctrl.h" #include "memory.h" +#include "log_error.h" int statctrl(const char *listdir, const char *ctrlstr) { @@ -38,8 +40,15 @@ int statctrl(const char *listdir, const char *ctrlstr) res = stat(filename, &st); myfree(filename); - if(res == 0) - return 1; + if(res < 0) { + if(errno == ENOENT) { + return 0; + } else { + log_error(LOG_ARGS, "Could not stat %s/control/%s. " + "Bailing out.", listdir, ctrlstr); + exit(EXIT_FAILURE); + } + } - return 0; + return 1; }