Use read () rather than fread () to make sure to catch end-of-file.
2001-06-18 Bradford Hovinen <hovinen@ximian.com> * capplets/new-*/main.c (do_set_xml): Use read () rather than fread () to make sure to catch end-of-file. Gracefully handle no-data case.
This commit is contained in:
parent
057372f928
commit
c7af228de9
7 changed files with 172 additions and 105 deletions
|
@ -1,3 +1,9 @@
|
|||
2001-06-18 Bradford Hovinen <hovinen@ximian.com>
|
||||
|
||||
* capplets/new-*/main.c (do_set_xml): Use read () rather than
|
||||
fread () to make sure to catch end-of-file. Gracefully handle
|
||||
no-data case.
|
||||
|
||||
2001-06-07 Christian Rose <menthos@menthos.com>
|
||||
|
||||
* capplets/desktop-links/Appearances.directory,
|
||||
|
|
|
@ -157,28 +157,41 @@ do_set_xml (gboolean apply_settings)
|
|||
int len = 0;
|
||||
int bytes_read = 0;
|
||||
|
||||
while (!feof (stdin)) {
|
||||
if (!len) buffer = g_new (char, 16385);
|
||||
else buffer = g_renew (char, buffer, len + 16385);
|
||||
bytes_read = fread (buffer + len, 1, 16384, stdin);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 16384;
|
||||
}
|
||||
fflush (stdin);
|
||||
|
||||
if (len > 0 && bytes_read + len - 16384 > 0) {
|
||||
doc = xmlParseMemory (buffer, strlen (buffer));
|
||||
do {
|
||||
if (!len) buffer = g_new (char, 4097);
|
||||
else buffer = g_renew (char, buffer, len + 4097);
|
||||
bytes_read = read (fileno (stdin), buffer + len, 4096);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 4096;
|
||||
} while (bytes_read == 4096);
|
||||
|
||||
if (len >= 4096 && len > 0) {
|
||||
doc = xmlParseMemory (buffer, len - 4096 + bytes_read);
|
||||
g_free (buffer);
|
||||
|
||||
if (doc != NULL) {
|
||||
prefs = preferences_read_xml (doc);
|
||||
|
||||
if (prefs) {
|
||||
if (prefs != NULL) {
|
||||
preferences_save (prefs);
|
||||
|
||||
if (apply_settings)
|
||||
preferences_apply_now (prefs);
|
||||
|
||||
return;
|
||||
}
|
||||
else if (prefs != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
xmlFreeDoc (doc);
|
||||
}
|
||||
} else {
|
||||
g_critical ("No data to apply");
|
||||
}
|
||||
|
||||
g_warning ("Error while reading the background config file");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -146,28 +146,41 @@ do_set_xml (gboolean apply_settings)
|
|||
int len = 0;
|
||||
int bytes_read = 0;
|
||||
|
||||
while (!feof (stdin)) {
|
||||
if (!len) buffer = g_new (char, 16385);
|
||||
else buffer = g_renew (char, buffer, len + 16385);
|
||||
bytes_read = fread (buffer + len, 1, 16384, stdin);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 16384;
|
||||
}
|
||||
fflush (stdin);
|
||||
|
||||
if (len > 0 && bytes_read + len - 16384 > 0) {
|
||||
doc = xmlParseMemory (buffer, strlen (buffer));
|
||||
do {
|
||||
if (!len) buffer = g_new (char, 4097);
|
||||
else buffer = g_renew (char, buffer, len + 4097);
|
||||
bytes_read = read (fileno (stdin), buffer + len, 4096);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 4096;
|
||||
} while (bytes_read == 4096);
|
||||
|
||||
if (len >= 4096 && len > 0) {
|
||||
doc = xmlParseMemory (buffer, len - 4096 + bytes_read);
|
||||
g_free (buffer);
|
||||
|
||||
if (doc != NULL) {
|
||||
prefs = preferences_read_xml (doc);
|
||||
|
||||
if (prefs) {
|
||||
if (prefs != NULL) {
|
||||
preferences_save (prefs);
|
||||
|
||||
if (apply_settings)
|
||||
preferences_apply_now (prefs);
|
||||
|
||||
return;
|
||||
}
|
||||
else if (prefs != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
xmlFreeDoc (doc);
|
||||
}
|
||||
} else {
|
||||
g_critical ("No data to apply");
|
||||
}
|
||||
|
||||
g_warning ("Error while reading the keyboard config file");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -146,28 +146,36 @@ do_set_xml (gboolean apply_settings)
|
|||
int len = 0;
|
||||
int bytes_read = 0;
|
||||
|
||||
while (!feof (stdin)) {
|
||||
if (!len) buffer = g_new (char, 16385);
|
||||
else buffer = g_renew (char, buffer, len + 16385);
|
||||
bytes_read = fread (buffer + len, 1, 16384, stdin);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 16384;
|
||||
}
|
||||
fflush (stdin);
|
||||
|
||||
if (len > 0 && bytes_read + len - 16384 > 0) {
|
||||
doc = xmlParseMemory (buffer, strlen (buffer));
|
||||
do {
|
||||
if (!len) buffer = g_new (char, 4097);
|
||||
else buffer = g_renew (char, buffer, len + 4097);
|
||||
bytes_read = read (fileno (stdin), buffer + len, 4096);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 4096;
|
||||
} while (bytes_read == 4096);
|
||||
|
||||
if (len >= 4096 && len > 0) {
|
||||
doc = xmlParseMemory (buffer, len - 4096 + bytes_read);
|
||||
g_free (buffer);
|
||||
|
||||
if (doc != NULL) {
|
||||
prefs = preferences_read_xml (doc);
|
||||
|
||||
if (prefs && apply_settings) {
|
||||
preferences_save (prefs);
|
||||
return;
|
||||
}
|
||||
else if (prefs) {
|
||||
else if (prefs != NULL) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
g_warning ("Error while reading the keyboard config file");
|
||||
xmlFreeDoc (doc);
|
||||
}
|
||||
} else {
|
||||
g_critical ("No data to apply");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -264,30 +264,39 @@ do_set_xml (gboolean apply_settings)
|
|||
xmlDocPtr doc;
|
||||
char *buffer = NULL;
|
||||
int len = 0;
|
||||
int bytes_read;
|
||||
int bytes_read = 0;
|
||||
|
||||
while (!feof (stdin)) {
|
||||
if (!len) buffer = g_new (char, 16385);
|
||||
else buffer = g_renew (char, buffer, len + 16385);
|
||||
bytes_read = fread (buffer + len, 1, 16384, stdin);
|
||||
fflush (stdin);
|
||||
|
||||
do {
|
||||
if (!len) buffer = g_new (char, 4097);
|
||||
else buffer = g_renew (char, buffer, len + 4097);
|
||||
bytes_read = read (fileno (stdin), buffer + len, 4096);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 16384;
|
||||
}
|
||||
len += 4096;
|
||||
} while (bytes_read == 4096);
|
||||
|
||||
if (len > 0 && bytes_read + len - 16384 > 0) {
|
||||
doc = xmlParseMemory (buffer, strlen (buffer));
|
||||
if (len >= 4096 && len > 0) {
|
||||
doc = xmlParseMemory (buffer, len - 4096 + bytes_read);
|
||||
g_free (buffer);
|
||||
|
||||
if (doc != NULL) {
|
||||
prefs = preferences_read_xml (doc);
|
||||
|
||||
if (prefs && apply_settings) {
|
||||
preferences_save (prefs);
|
||||
return;
|
||||
}
|
||||
else if (prefs) {
|
||||
else if (prefs != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
xmlFreeDoc (doc);
|
||||
}
|
||||
} else {
|
||||
g_critical ("No data to apply");
|
||||
}
|
||||
|
||||
g_warning ("Error while reading the screensaver config file");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -145,28 +145,37 @@ do_set_xml (gboolean apply_settings)
|
|||
int len = 0;
|
||||
int bytes_read = 0;
|
||||
|
||||
while (!feof (stdin)) {
|
||||
if (!len) buffer = g_new (char, 16385);
|
||||
else buffer = g_renew (char, buffer, len + 16385);
|
||||
bytes_read = fread (buffer + len, 1, 16384, stdin);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 16384;
|
||||
}
|
||||
fflush (stdin);
|
||||
|
||||
if (len > 0 && bytes_read + len - 16384 > 0) {
|
||||
doc = xmlParseMemory (buffer, strlen (buffer));
|
||||
do {
|
||||
if (!len) buffer = g_new (char, 4097);
|
||||
else buffer = g_renew (char, buffer, len + 4097);
|
||||
bytes_read = read (fileno (stdin), buffer + len, 4096);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 4096;
|
||||
} while (bytes_read == 4096);
|
||||
|
||||
if (len >= 4096 && len > 0) {
|
||||
doc = xmlParseMemory (buffer, len - 4096 + bytes_read);
|
||||
g_free (buffer);
|
||||
|
||||
if (doc != NULL) {
|
||||
prefs = preferences_read_xml (doc);
|
||||
|
||||
if (prefs && apply_settings) {
|
||||
preferences_save (prefs);
|
||||
return;
|
||||
}
|
||||
else if (prefs) {
|
||||
else if (prefs != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
xmlFreeDoc (doc);
|
||||
}
|
||||
} else {
|
||||
g_critical ("No data to apply");
|
||||
}
|
||||
|
||||
g_warning ("Error while reading the sound config file");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -138,28 +138,37 @@ do_set_xml (gboolean apply_settings)
|
|||
int len = 0;
|
||||
int bytes_read = 0;
|
||||
|
||||
while (!feof (stdin)) {
|
||||
if (!len) buffer = g_new (char, 16385);
|
||||
else buffer = g_renew (char, buffer, len + 16385);
|
||||
bytes_read = fread (buffer + len, 1, 16384, stdin);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 16384;
|
||||
}
|
||||
fflush (stdin);
|
||||
|
||||
if (len > 0 && bytes_read + len - 16384 > 0) {
|
||||
doc = xmlParseMemory (buffer, strlen (buffer));
|
||||
do {
|
||||
if (!len) buffer = g_new (char, 4097);
|
||||
else buffer = g_renew (char, buffer, len + 4097);
|
||||
bytes_read = read (fileno (stdin), buffer + len, 4096);
|
||||
buffer[len + bytes_read] = '\0';
|
||||
len += 4096;
|
||||
} while (bytes_read == 4096);
|
||||
|
||||
if (len >= 4096 && len > 0) {
|
||||
doc = xmlParseMemory (buffer, len - 4096 + bytes_read);
|
||||
g_free (buffer);
|
||||
|
||||
if (doc != NULL) {
|
||||
prefs = preferences_read_xml (doc);
|
||||
|
||||
if (prefs && apply_settings) {
|
||||
preferences_save (prefs);
|
||||
return;
|
||||
}
|
||||
else if (prefs) {
|
||||
else if (prefs != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
xmlFreeDoc (doc);
|
||||
}
|
||||
} else {
|
||||
g_critical ("No data to apply");
|
||||
}
|
||||
|
||||
g_warning ("Error while reading the ui config file");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue