mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
delay memory allocation until after the first read. Saves a bunch of
2005-03-10 Sven Neumann <sven@gimp.org> * glib/gfileutils.c (get_contents_stdio): delay memory allocation until after the first read. Saves a bunch of reallocs. Also increased the buffer size to 4096 bytes. (bug #165954) * tests/file-test.c (test_get_contents): added a (very basic) test for g_file_get_contents().
This commit is contained in:
committed by
Sven Neumann
parent
2d7ada2898
commit
aec8923fa6
@@ -24,6 +24,7 @@ date-test
|
||||
dirname-test
|
||||
env-test
|
||||
file-test
|
||||
file-test-get-contents
|
||||
hash-test
|
||||
iochannel-test
|
||||
iochannel-test-outfile
|
||||
|
@@ -131,11 +131,36 @@ test_readlink (void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
test_get_contents (void)
|
||||
{
|
||||
const gchar *text = "abcdefghijklmnopqrstuvwxyz";
|
||||
const gchar *filename = "file-test-get-contents";
|
||||
gchar *contents;
|
||||
gsize len;
|
||||
FILE *f;
|
||||
GError *error = NULL;
|
||||
|
||||
f = g_fopen (filename, "w");
|
||||
fwrite (text, 1, strlen (text), f);
|
||||
fclose (f);
|
||||
|
||||
g_assert (g_file_test (filename, G_FILE_TEST_IS_REGULAR));
|
||||
|
||||
if (! g_file_get_contents (filename, &contents, &len, &error))
|
||||
g_error ("g_file_get_contents() failed: %s", error->message);
|
||||
|
||||
g_assert (strcmp (text, contents) == 0 && "content mismatch");
|
||||
|
||||
g_free (contents);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
test_mkstemp ();
|
||||
test_readlink ();
|
||||
test_get_contents ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user