t_truncate_self: describe self better in error message
authorAmir Goldstein <amir73il@gmail.com>
Wed, 19 Oct 2016 08:52:31 +0000 (11:52 +0300)
committerEryu Guan <eguan@redhat.com>
Fri, 21 Oct 2016 15:20:14 +0000 (23:20 +0800)
Include the name of the program that is trying to trucate itself
to error messages to distinguish between output for different
test cases (e.g. test_lower and test_upper in overlay/013).

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
src/t_truncate_self.c

index d14dec397e5f650d9667418305bc31452c92fd11..3f1c8e6fde8072e3699c4013383d30fa9bbaf71f 100644 (file)
@@ -1,18 +1,21 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
+#include <libgen.h>
 
 int main(int argc, char *argv[])
 {
+       const char *progname = basename(argv[0]);
        int ret;
 
        ret = truncate(argv[0], 4096);
        if (ret != -1) {
-               fprintf(stderr, "truncate(argv[0]) should have failed\n");
+               fprintf(stderr, "truncate(%s) should have failed\n",
+                       progname);
                return 1;
        }
        if (errno != ETXTBSY) {
-               perror("truncate(argv[0])");
+               perror(progname);
                return 1;
        }