From: Kevin Day Date: Tue, 1 Dec 2020 03:48:15 +0000 (-0600) Subject: Update: provide file mode macros in f_file. X-Git-Tag: 0.5.2~48 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=2242f9a1d20fb0f9df109da0b9dfb401bb5173af;p=fll Update: provide file mode macros in f_file. 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. --- diff --git a/level_0/f_file/c/file-common.h b/level_0/f_file/c/file-common.h index c7ef2b7..47bcb1c 100644 --- a/level_0/f_file/c/file-common.h +++ b/level_0/f_file/c/file-common.h @@ -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_ /** diff --git a/level_0/f_file/c/private-file.c b/level_0/f_file/c/private-file.c index 2ecb8a7..1e3b506 100644 --- a/level_0/f_file/c/private-file.c +++ b/level_0/f_file/c/private-file.c @@ -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_)