diff --git a/osdd-file.c b/osdd-file.c index 3929bf4a5f34ef11a37f4b17eb9f560b0abe1349..e4f210eecabf1404aa849a8e6802764bcf0b69d0 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);