From 348fbff1e7d94d0f4cd0c21bcbbc135e7dd7c235 Mon Sep 17 00:00:00 2001 From: Jiri Kalvoda <jirikalvoda@kam.mff.cuni.cz> Date: Sun, 20 Nov 2022 23:16:41 +0100 Subject: [PATCH] File module: end by NULL character --- osdd-file.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/osdd-file.c b/osdd-file.c index 3929bf4..e4f210e 100644 --- a/osdd-file.c +++ b/osdd-file.c @@ -22,6 +22,7 @@ struct file_state char * file_name; char * open_mode; struct osd_to_string_state to_string; + bool end_by_null_char; }; // ************************* MAIN FUNCTIONS ******* @@ -34,6 +35,8 @@ void file_write(struct file_state *state, VECTOR(char) out) if(f) { fprintf(f,"%s", out); + if(state->end_by_null_char) + putc(0, f); fclose(f); } VFREE(out); @@ -49,6 +52,7 @@ void file_new_help(FILE * f) fprintf(f,"\ Module FILE help:\n\ -a, --append \t\tAppend to file (do not overwrite)\n\ +-n, --end-by-null-char\tAppend \\0 to end of each message\n\ " OSDD_TO_STRING_HELP "\ \n\ "); @@ -60,9 +64,10 @@ struct osd_abstract file_new(int argc, char ** argv, Display * nope) (void)nope; argc++;argv--; struct osd_abstract r; - static const char short_opts[] = "+b" OSDD_TO_STRING_SHORTOP; + static const char short_opts[] = "+b+n" OSDD_TO_STRING_SHORTOP; static const struct option long_opts[] = { { "append", no_argument, NULL, 'b' }, + { "end-by-null-char", no_argument, NULL, 'n' }, OSDD_TO_STRING_LONGOP { NULL, 0, NULL, 0 }, }; @@ -83,6 +88,9 @@ struct osd_abstract file_new(int argc, char ** argv, Display * nope) case 'b': state->open_mode = "a"; break; + case 'n': + state->end_by_null_char = true; + break; default: fprintf(stderr,"Option %c not exist\n\n",opt); file_new_help(stderr); -- GitLab