Skip to content
Snippets Groups Projects
Commit 348fbff1 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

File module: end by NULL character

parent 174c2eae
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment