summaryrefslogtreecommitdiff
path: root/system/csvutils/csvcheck_exit_status.diff
blob: df395e061fdf9dff7c23bc3a40f119c71921127e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
diff -Naur csvutils-0.9.3+20161218_e57951b/src/csvcheck.c csvutils-0.9.3+20161218_e57951b.patched/src/csvcheck.c
--- csvutils-0.9.3+20161218_e57951b/src/csvcheck.c	2022-01-26 02:05:12.660602834 -0500
+++ csvutils-0.9.3+20161218_e57951b.patched/src/csvcheck.c	2022-01-26 02:33:11.553450216 -0500
@@ -89,6 +89,8 @@
   }
 }
 
+int errcnt = 0;
+
 void
 check_file(char *filename)
 {
@@ -112,6 +114,7 @@
     fp = fopen(filename, "rb");
     if (fp == NULL) {
       fprintf(stderr, "Failed to open file %s: %s\n", filename, strerror(errno));
+      errcnt++;
       csv_free(&p);
       return;
     }
@@ -121,18 +124,21 @@
     if ((retval = csv_parse(&p, buf, bytes_read, NULL, NULL, NULL)) != bytes_read) {
       if (csv_error(&p) == CSV_EPARSE) {
         printf("%s: malformed at byte %lu\n", filename ? filename : "stdin", (unsigned long)pos + retval + 1);
+        errcnt++;
         goto end;
       } else {
         printf("Error while processing %s: %s\n", filename ? filename : "stdin", csv_strerror(csv_error(&p)));
+        errcnt++;
         goto end;
       }
     }
     pos += 1024;
   }
 
-  if (csv_fini(&p, NULL, NULL, NULL) != 0)
+  if (csv_fini(&p, NULL, NULL, NULL) != 0) {
     printf("%s: missing closing quote at end of input\n", filename ? filename : "stdin");
-  else
+    errcnt++;
+  } else
     printf("%s well-formed\n", filename ? filename : "data is");
 
   end:
@@ -186,5 +192,5 @@
     check_file(NULL);
   }
 
-  return EXIT_SUCCESS;
+  return (errcnt ? EXIT_FAILURE : EXIT_SUCCESS);
 }