]> Kevux Git Server - fll/commitdiff
Update: provide file mode macros in f_file.
authorKevin Day <thekevinday@gmail.com>
Tue, 1 Dec 2020 03:48:15 +0000 (21:48 -0600)
committerKevin Day <thekevinday@gmail.com>
Tue, 1 Dec 2020 05:02:51 +0000 (23:02 -0600)
I would rather provide static constant strings, but the Posix file string functions that use this expect a non-constant string.
This is unsafe, so just stick with macros.

level_0/f_file/c/file-common.h
level_0/f_file/c/private-file.c

index c7ef2b7b6650ec5b07ffd7c9e6ecfe0df700c750..47bcb1c79345ed63f118a847540e21d7685bc9b0 100644 (file)
@@ -84,6 +84,13 @@ extern "C" {
   #define f_macro_file_type_is_link(mode)      f_macro_file_type_get(mode) == f_file_type_link
   #define f_macro_file_type_is_regular(mode)   f_macro_file_type_get(mode) == f_file_type_regular
   #define f_macro_file_type_is_socket(mode)    f_macro_file_type_get(mode) == f_file_type_socket
+
+  #define f_macro_file_open_mode_append        "a"
+  #define f_macro_file_open_mode_read          "r"
+  #define f_macro_file_open_mode_read_append   "a+"
+  #define f_macro_file_open_mode_read_truncate "w+"
+  #define f_macro_file_open_mode_read_write    "r+"
+  #define f_macro_file_open_mode_truncate      "w"
 #endif // _di_f_file_type_
 
 /**
index 2ecb8a7beaa70051f6bcb24f14ad0006d120df34..1e3b50655a3d7f782e05e92143aedd76e15416ec 100644 (file)
@@ -727,26 +727,26 @@ extern "C" {
 
     if (flag & f_file_flag_read_write) {
       if (flag & f_file_flag_truncate) {
-        return "w+";
+        return f_macro_file_open_mode_read_truncate;
       }
       else if (flag & f_file_flag_append) {
-        return "a+";
+        return f_macro_file_open_mode_read_append;
       }
 
       // failsafe to read write prepend.
-      return "r+";
+      return f_macro_file_open_mode_read_write;
     }
     else if (flag & f_file_flag_write_only) {
       if (flag & f_file_flag_truncate) {
-        return "w";
+        return f_macro_file_open_mode_truncate;
       }
 
       // failsafe to append.
-      return "a";
+      return f_macro_file_open_mode_append;
     }
 
     // failsafe to read only.
-    return "r";
+    return f_macro_file_open_mode_read;
   }
 #endif // !defined(_di_f_file_stream_descriptor_) || !defined(_di_f_file_stream_open_) || !defined(_di_f_file_stream_reopen_)