home · contact · privacy
Remove redundant uses of NULL.
[plomrogue] / src / common / readwrite.c
index f05c1285a9d5cdda58ee909d4814aea019318b03..a206c9c2f2e7eb61ca215d1392ab015b580d7f3b 100644 (file)
 
 
 
-/* Return "path" + suffix "_tmp". Value is malloc'd, must be free externally. */
-static char * build_temp_path(char * path);
-
-
-
-static char * build_temp_path(char * path)
-{
-    char * suffix_tmp = "_tmp";
-    uint16_t size = strlen(path) + strlen(suffix_tmp) + 1;
-    char * path_tmp = try_malloc(size, __func__);
-    int test = sprintf(path_tmp, "%s%s", path, suffix_tmp);
-    exit_trouble(test < 0, __func__, "sprintf");
-    return path_tmp;
-}
-
-
-
 extern FILE * try_fopen(char * path, char * mode, const char * f)
 {
     char * msg1 = "Trouble in ";
@@ -43,7 +26,7 @@ extern FILE * try_fopen(char * path, char * mode, const char * f)
     int test = sprintf(msg, "%s%s%s%s%s%s%s", msg1,f,msg2,mode,msg3,path,msg4);
     exit_trouble(test < 0, __func__, "sprintf");
     FILE * file_p = fopen(path, mode);
-    exit_err(NULL == file_p, msg);
+    exit_err(!file_p, msg);
     free(msg);
     return file_p;
 }
@@ -85,12 +68,24 @@ extern int try_fgetc(FILE * file, const char * f)
 extern char * try_fgets(char * line, int linemax, FILE * file, const char * f)
 {
     char * test = fgets(line, linemax, file);
-    exit_trouble(NULL == test && ferror(file), f, "fgets");
+    exit_trouble(!test && ferror(file), f, "fgets");
     return test;
 }
 
 
 
+extern char * build_temp_path(char * path)
+{
+    char * suffix_tmp = "_tmp";
+    uint16_t size = strlen(path) + strlen(suffix_tmp) + 1;
+    char * path_tmp = try_malloc(size, __func__);
+    int test = sprintf(path_tmp, "%s%s", path, suffix_tmp);
+    exit_trouble(test < 0, __func__, "sprintf");
+    return path_tmp;
+}
+
+
+
 extern FILE * atomic_write_start(char * path, char ** path_tmp)
 {
     *path_tmp = build_temp_path(path);