]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
depmod: use ferror and fclose to check for error
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Sat, 16 Jun 2012 01:14:00 +0000 (22:14 -0300)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Sat, 16 Jun 2012 01:14:00 +0000 (22:14 -0300)
Thanks to hpa for point this out.

tools/depmod.c

index 790cc7636b4280ef67da8fd01f25a591439e2ec2..834bb059cfc39fafa749d1cf34dc72925b542699 100644 (file)
@@ -2236,8 +2236,7 @@ static int depmod_output(struct depmod *depmod, FILE *out)
        for (itr = depfiles; itr->name != NULL; itr++) {
                FILE *fp = out;
                char tmp[NAME_MAX] = "";
-               int r;
-               long eof;
+               int r, ferr;
 
                if (fp == NULL) {
                        int flags = O_CREAT | O_TRUNC | O_WRONLY;
@@ -2263,8 +2262,8 @@ static int depmod_output(struct depmod *depmod, FILE *out)
                if (fp == out)
                        continue;
 
-               eof = ftell(fp);
-               fclose(fp);
+               ferr = ferror(fp) | fclose(fp);
+
                if (r < 0) {
                        if (unlinkat(dfd, tmp, 0) != 0)
                                ERR("unlinkat(%s, %s): %m\n", dname, tmp);
@@ -2283,10 +2282,10 @@ static int depmod_output(struct depmod *depmod, FILE *out)
                        break;
                }
 
-               if (eof == EOF) {
+               if (ferr) {
                        err = -ENOSPC;
-                       ERR("Could not create index: output truncated: %s\n",
-                                                               strerror(-err));
+                       ERR("Could not create index '%s'. Output is truncated: %s\n",
+                                               itr->name, strerror(-err));
                        break;
                }
        }