diff options
author | EuAndreh <eu@euandre.org> | 2024-04-06 11:37:04 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-04-06 11:37:04 -0300 |
commit | 3b32f5a1abbec9655a93a184ed0a3c5e6e5134fd (patch) | |
tree | 03969b7b76835f2507ccd1a8aeb057bb1d7f7201 | |
parent | src/: Remove unused "infallible" tag (diff) | |
download | pindaiba-3b32f5a1abbec9655a93a184ed0a3c5e6e5134fd.tar.gz pindaiba-3b32f5a1abbec9655a93a184ed0a3c5e6e5134fd.tar.xz |
Start "rc = -1" instead of 0
-rw-r--r-- | src/catalog.c | 20 | ||||
-rw-r--r-- | src/random.c | 5 | ||||
-rw-r--r-- | tests/catalog.c | 39 | ||||
-rw-r--r-- | tests/i18n.c | 4 | ||||
-rw-r--r-- | tests/logerr.c | 26 | ||||
-rw-r--r-- | tests/random.c | 10 | ||||
-rw-r--r-- | tests/slurp.c | 9 | ||||
-rw-r--r-- | tests/testing.c | 6 |
8 files changed, 38 insertions, 81 deletions
diff --git a/src/catalog.c b/src/catalog.c index e56ca0b..6c3bdad 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -27,13 +27,12 @@ NLSPATH_KEY = "NLSPATH"; int i18n_init(void) { - int rc = 0; + int rc = -1; static const int should_overwrite = 0; if (setenv(NLSPATH_KEY, NLSPATH, should_overwrite)) { logerr("setenv(\"%s\", \"%s\", 0): %s\n", NLSPATH_KEY, NLSPATH, strerror(errno)); - rc = -1; goto out; } @@ -41,26 +40,26 @@ i18n_init(void) { if (catalog_descriptor && catalog_descriptor == (nl_catd)-1) { logerr("catopen(\"%s\", 0): %s\n", CATALOG_NAME, strerror(errno)); catalog_descriptor = NULL; - rc = -1; goto out; } + rc = 0; out: return rc; } int i18n_destroy(void) { - int rc = 0; + int rc = -1; if (catalog_descriptor) { if (catclose(catalog_descriptor)) { logerr("catclose(...): %s\n", strerror(errno)); - rc = -1; goto out; } } + rc = 0; out: if (catalog_descriptor) { catalog_descriptor = NULL; @@ -97,17 +96,17 @@ s_print_msgs( const int msg_begin, const int msg_end ) { - int rc = 0; + int rc = -1; for (int i = msg_begin; i <= msg_end; i++) { if (fprintf(stream, "%s", s(MSGS, i)) < 0) { logerr("fprintf(stream, \"%%s\", _(%d)): %s\n", i, strerror(errno)); - rc = -1; goto out; } } + rc = 0; out: return rc; } @@ -119,12 +118,11 @@ s_print_msg(const char *const MSGS[], FILE *const fd, const int msg_id) { int dump_translatable_strings(const char *const MSGS[]) { - int rc = 0; + int rc = -1; for (size_t i = 1; MSGS[i]; i++) { if (printf("%ld ", i) < 0) { logerr("printf(\"%%ld\", %d): %s\n", i); - rc = -1; goto out; } @@ -133,7 +131,6 @@ dump_translatable_strings(const char *const MSGS[]) { if (printf("\\n") < 0) { logerr("printf(\"\\\\n\"): %s\n", strerror(errno)); - rc = -1; goto out; } } else { @@ -141,7 +138,6 @@ dump_translatable_strings(const char *const MSGS[]) { logerr("printf(\"%%c\", " "MSGS[%ld][%ld]): %s\n", i, j, strerror(errno)); - rc = -1; goto out; } } @@ -149,11 +145,11 @@ dump_translatable_strings(const char *const MSGS[]) { if (printf("\n\n") < 0) { logerr("printf(\"\\n\\n\"): %s\n", strerror(errno)); - rc = -1; goto out; } } + rc = 0; out: return rc; } diff --git a/src/random.c b/src/random.c index 3ec9e24..7574074 100644 --- a/src/random.c +++ b/src/random.c @@ -13,25 +13,24 @@ int urandom_bytes(const size_t n, uint8_t (*const addr)[]) { - int rc = 0; + int rc = -1; FILE *f = NULL; f = fopen("/dev/urandom", "r"); if (!f) { logerr("fopen(\"/dev/urandom\", \"r\"): %s\n", strerror(errno)); - rc = -1; goto out; } const size_t read_count = fread(addr, 1, n, f); if (ferror(f)) { logerr("fread(addr, 1, n, f): %s\n", strerror(errno)); - rc = -1; goto out; } assert(read_count == n); + rc = 0; out: if (f) { if (fclose(f)) { diff --git a/tests/catalog.c b/tests/catalog.c index d357175..5e5a430 100644 --- a/tests/catalog.c +++ b/tests/catalog.c @@ -28,7 +28,7 @@ TEST_MSGS[] = { static int test_i18n_init(void) { - int rc = 0; + int rc = -1; test_start("i18n_init()"); @@ -39,19 +39,18 @@ test_i18n_init(void) { if (setenv(NLSPATH_KEY, "src/%N.en.cat", should_overwrite)) { logerr("setenv(\"%s\", \"src/%%N.en.cat\", 1): %s\n", NLSPATH_KEY, strerror(errno)); - rc = -1; goto out; } if (i18n_init()) { logerr("i18n_init()\n"); - rc = -1; goto out; } test_ok(); } + rc = 0; out: if (i18n_destroy()) { logerr("i18n_destroy()\n"); @@ -62,7 +61,7 @@ out: static int test_s_print_msgs(void) { - int rc = 0; + int rc = -1; test_start("s_print_msgs()"); FILE *file = NULL; @@ -74,13 +73,11 @@ test_s_print_msgs(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } if (s_print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_LAST)) { logerr("print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_LAST)\n"); - rc = -1; goto out; } @@ -88,13 +85,11 @@ test_s_print_msgs(void) { file = NULL; if (ret) { logerr("fclose(file): %s\n", strerror(errno)); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { logerr("slurp_for_tests(FNAME, &str)\n"); - rc = -1; goto out; } @@ -118,13 +113,11 @@ test_s_print_msgs(void) { file = fopen(FNAME, "w"); if (!file) { logerr("fopen(FNAME, \"w\"): %s\n", strerror(errno)); - rc = -1; goto out; } if (s_print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_FIRST)) { logerr("s_print_msgs(TEST_MSGS, file, MSG_X_FIRST, MSG_X_FIRST)\n"); - rc = -1; goto out; } @@ -132,13 +125,11 @@ test_s_print_msgs(void) { file = NULL; if (ret) { logerr("fclose(file): %s\n", strerror(errno)); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { logerr("slurp_for_tests(FNAME, &str)\n"); - rc = -1; goto out; } @@ -153,6 +144,7 @@ test_s_print_msgs(void) { test_ok(); } + rc = 0; out: if (str) { free(str); @@ -168,7 +160,7 @@ out: static int test_s(void) { - int rc = 0; + int rc = -1; test_start("_()"); FILE *file = NULL; @@ -180,7 +172,6 @@ test_s(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -191,6 +182,7 @@ test_s(void) { test_ok(); } + rc = 0; out: if (str) { free(str); @@ -206,7 +198,7 @@ out: static int test_i18n_destroy(void) { - int rc = 0; + int rc = -1; test_start("i18n_destroy()"); @@ -215,20 +207,20 @@ test_i18n_destroy(void) { if (i18n_destroy()) { logerr("i18n_destroy()\n"); - rc = -1; goto out; } test_ok(); } + rc = 0; out: return rc; } static int test_s_print_msg(void) { - int rc = 0; + int rc = -1; test_start("s_print_msg()"); FILE *file = NULL; @@ -240,13 +232,11 @@ test_s_print_msg(void) { file = fopen(FNAME, "w"); if (!file) { logerr("fopen(FNAME, \"w\"): %s\n"); - rc = -1; goto out; } if (s_print_msg(TEST_MSGS, file, MSG_STANDALONE)) { logerr("s_print_msg(TEST_MSGS, file, MSG_STANDALONE)\n"); - rc = -1; goto out; } @@ -254,13 +244,11 @@ test_s_print_msg(void) { file = NULL; if (ret) { logerr("fopen(file): %s\n", strerror(errno)); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { logerr("slurp_for_tests(FNAME, &str)\n"); - rc = -1; goto out; } @@ -275,6 +263,7 @@ test_s_print_msg(void) { test_ok(); } + rc = 0; out: if (str) { free(str); @@ -290,38 +279,34 @@ out: int main(void) { - int rc = 0; + int rc = -1; if (test_i18n_init()) { logerr("test_i18n_init()\n"); - rc = -1; goto out; } if (test_i18n_destroy()) { logerr("test_i18n_destroy()\n"); - rc = -1; goto out; } if (test_s()) { logerr("test_s()\n"); - rc = -1; goto out; } if (test_s_print_msgs()) { logerr("test_s_print_msgs()\n"); - rc = -1; goto out; } if (test_s_print_msg()) { logerr("test_s_print_msg()\n"); - rc = -1; goto out; } + rc = 0; out: return !!rc; } diff --git a/tests/i18n.c b/tests/i18n.c index 60e4620..369a63d 100644 --- a/tests/i18n.c +++ b/tests/i18n.c @@ -8,16 +8,16 @@ int main(void) { - int rc = 0; + int rc = -1; if (getenv("DUMP_TRANSLATABLE_STRINGS")) { if (dump_translatable_strings(MSGS)) { logerr("dump_translatable_strings(MSGS)\n"); - rc = -1; goto out; } } + rc = 0; out: return !!rc; } diff --git a/tests/logerr.c b/tests/logerr.c index 78cdf10..86b6b1c 100644 --- a/tests/logerr.c +++ b/tests/logerr.c @@ -14,7 +14,7 @@ FNAME = __FILE__ ".txt"; static int test_vlogerr(void) { - int rc = 0; + int rc = -1; test_start("vlogerr()"); FILE *file = NULL; @@ -26,7 +26,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -38,13 +37,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -63,7 +60,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -75,13 +71,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -100,7 +94,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -112,13 +105,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -137,7 +128,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -149,13 +139,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -174,7 +162,6 @@ test_vlogerr(void) { file = fopen(FNAME, "w"); if (!file) { perror("fopen(FNAME, \"w\")"); - rc = -1; goto out; } @@ -189,13 +176,11 @@ test_vlogerr(void) { file = NULL; if (ret) { perror("fclose(file)"); - rc = -1; goto out; } if (slurp_for_tests(FNAME, &str)) { perror("slurp_for_tests(FNAME, &str)"); - rc = -1; goto out; } @@ -210,6 +195,7 @@ test_vlogerr(void) { test_ok(); } + rc = 0; out: if (str) { free(str); @@ -225,7 +211,7 @@ out: static int test_logerr(void) { - int rc = 0; + int rc = -1; test_start("logerr()"); @@ -258,26 +244,26 @@ test_logerr(void) { test_ok(); } + rc = 0; return rc; } int main(void) { - int rc = 0; + int rc = -1; if (test_vlogerr()) { perror("test_vlogerr()"); - rc = -1; goto out; } if (test_logerr()) { perror("test_logerr()"); - rc = -1; goto out; } + rc = 0; out: return !!rc; } diff --git a/tests/random.c b/tests/random.c index eec83c5..e56e747 100644 --- a/tests/random.c +++ b/tests/random.c @@ -4,7 +4,7 @@ static int test_urandom_bytes(void) { - int rc = 0; + int rc = -1; test_start("urandom_bytes()"); @@ -17,7 +17,6 @@ test_urandom_bytes(void) { for (size_t n = 0; n < LEN; n++) { if (urandom_bytes(n, &arr)) { logerr("urandom_bytes(n, &arr);\n"); - rc = -1; goto out; } for (size_t i = n; i < LEN; i++) { @@ -37,7 +36,6 @@ test_urandom_bytes(void) { if (urandom_bytes(LEN, &arr1)) { logerr("urandom_bytes(LEN, &arr1);\n"); - rc = -1; goto out; } @@ -45,7 +43,6 @@ test_urandom_bytes(void) { for (size_t n = 0; n < attempts; n++) { if (urandom_bytes(LEN, &arr2)) { logerr("urandom_bytes(LEN, &arr2);\n"); - rc = -1; goto out; } assert(memcmp(arr1, arr2, LEN) != 0); @@ -54,20 +51,21 @@ test_urandom_bytes(void) { test_ok(); } + rc = 0; out: return rc; } int main(void) { - int rc = 0; + int rc = -1; if (test_urandom_bytes()) { logerr("test_urandom_bytes();\n"); - rc = -1; goto out; } + rc = 0; out: return !!rc; } diff --git a/tests/slurp.c b/tests/slurp.c index 7b5936f..6ea8618 100644 --- a/tests/slurp.c +++ b/tests/slurp.c @@ -7,7 +7,7 @@ int slurp_for_tests(const char *const FNAME, char **strref) { - int rc = 0; + int rc = -1; FILE *file = NULL; char *str = NULL; @@ -15,45 +15,40 @@ slurp_for_tests(const char *const FNAME, char **strref) { file = fopen(FNAME, "r"); if (!file) { perror("fopen(FNAME, \"r\")"); - rc = -1; goto out; } if (fseek(file, 0L, SEEK_END)) { perror("fseek(file, 0L, SEEK_END)"); - rc = -1; goto out; } const long lsize = ftell(file); if (lsize == -1) { perror("ftell(file)"); - rc = -1; goto out; } const size_t size = (size_t)lsize + sizeof(char); if (fseek(file, 0L, SEEK_SET)) { perror("fseek(file, 0L, SEEK_SET)"); - rc = -1; goto out; } str = malloc(size); if (!str) { perror("malloc(...)"); - rc = -1; goto out; } if (fread(str, sizeof(char), size - 1, file) != size - 1) { perror("fread(...)"); - rc = -1; goto out; } str[size - 1] = '\0'; *strref = str; + rc = 0; out: if (file) { if (fclose(file)) { diff --git a/tests/testing.c b/tests/testing.c index 65012f9..eeb0a39 100644 --- a/tests/testing.c +++ b/tests/testing.c @@ -3,14 +3,13 @@ int main(void) { - int rc = 0; + int rc = -1; test_start("testing.c"); const int should_overwrite = 1; if (unsetenv(ENVVAR_NAME)) { perror("unsetenv(\"NO_COLOR\")"); - rc = -1; goto out; } { @@ -20,7 +19,6 @@ main(void) { if (setenv(ENVVAR_NAME, "", should_overwrite)) { perror("setenv(\"NO_COLOR\", \"\", 1)"); - rc = -1; goto out; } { @@ -30,7 +28,6 @@ main(void) { if (setenv(ENVVAR_NAME, "something", should_overwrite)) { perror("setenv(\"NO_COLOR\", \"something\", 1)"); - rc = -1; goto out; } { @@ -38,6 +35,7 @@ main(void) { test_ok(); } + rc = 0; out: return !!rc; } |