tThe configuration file is now read in (up to the header), rewound, and then wr… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit bf1956fb9811da51db35f13b89f643347538b9c8 | |
parent 86756a22b3d292d6b4c4c33d3f3e17c01ed8353d | |
Author: Ben Webb <[email protected]> | |
Date: Sat, 2 Mar 2002 18:57:13 +0000 | |
The configuration file is now read in (up to the header), rewound, and then | |
written out again. The previous approach (using ftruncate) was getting | |
confused by the Windows \n -> \r\n conversion. | |
Diffstat: | |
M src/gui_client/optdialog.c | 31 +++++++++++++++++------------… | |
1 file changed, 17 insertions(+), 14 deletions(-) | |
--- | |
diff --git a/src/gui_client/optdialog.c b/src/gui_client/optdialog.c | |
t@@ -462,17 +462,19 @@ static void list_row_unselect(GtkCList *clist, gint row,… | |
} | |
} | |
-static gboolean ReadFileToString(FILE *fp, gchar *str) | |
+static void ReadFileToString(FILE *fp, gchar *str) | |
{ | |
- int len, mpos, numread; | |
+ int len, mpos; | |
gchar *match, ch; | |
+ GString *file; | |
+ file = g_string_new(""); | |
len = strlen(str); | |
match = g_new(gchar, len); | |
- mpos = numread = 0; | |
+ mpos = 0; | |
- while ((ch = fgetc(fp)) != EOF && mpos < len) { | |
- numread++; | |
+ while (mpos < len && (ch = fgetc(fp)) != EOF) { | |
+ g_string_append_c(file, ch); | |
match[mpos++] = ch; | |
if (ch != str[mpos - 1]) { | |
int start; | |
t@@ -492,13 +494,15 @@ static gboolean ReadFileToString(FILE *fp, gchar *str) | |
} | |
g_free(match); | |
- if (mpos == len) { | |
- fseek(fp, numread, SEEK_SET); | |
- ftruncate(fileno(fp), numread); | |
- return TRUE; | |
- } else { | |
- return FALSE; | |
- } | |
+ | |
+ rewind(fp); | |
+ ftruncate(fileno(fp), 0); | |
+ fprintf(fp, file->str); | |
+ | |
+ if (mpos < len) | |
+ fprintf(fp, str); | |
+ | |
+ g_string_free(file, TRUE); | |
} | |
static void UpdateLocalConfig(void) | |
t@@ -527,8 +531,7 @@ static void UpdateLocalConfig(void) | |
return; | |
} | |
- if (!ReadFileToString(fp, header)) | |
- fprintf(fp, header); | |
+ ReadFileToString(fp, header); | |
WriteConfigFile(fp); | |
fclose(fp); |