mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-23 20:46:14 +01:00
tests/: Avoid closing invalid fd's
...and only include unistd.h when we are on *NIX. Newer Visual C++ runtimes (8.0/2005 and later) will cause the program to crash with an internal abort() call when they detect instances of close() being called on an invalid fd, such as when the fd is -1, and these should be purged anyways. https://bugzilla.gnome.org/show_bug.cgi?id=711047
This commit is contained in:
parent
172aaa3a01
commit
ccba409d34
@ -24,8 +24,6 @@
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#undef G_DISABLE_ASSERT
|
||||
#undef G_LOG_DOMAIN
|
||||
|
||||
@ -39,7 +37,7 @@
|
||||
|
||||
#include <gstdio.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#ifdef G_OS_UNIX
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
@ -62,14 +60,18 @@ test_mkstemp (void)
|
||||
strcpy (template, "foobar");
|
||||
fd = g_mkstemp (template);
|
||||
if (fd != -1)
|
||||
{
|
||||
g_warning ("g_mkstemp works even if template doesn't contain XXXXXX");
|
||||
close (fd);
|
||||
}
|
||||
|
||||
strcpy (template, "foobarXXX");
|
||||
fd = g_mkstemp (template);
|
||||
if (fd != -1)
|
||||
{
|
||||
g_warning ("g_mkstemp works even if template contains less than six X");
|
||||
close (fd);
|
||||
}
|
||||
|
||||
strcpy (template, "fooXXXXXX");
|
||||
fd = g_mkstemp (template);
|
||||
|
@ -24,8 +24,6 @@
|
||||
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#undef GLIB_COMPILATION
|
||||
|
||||
#include <stdio.h>
|
||||
@ -37,7 +35,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#ifdef G_OS_UNIX
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
@ -938,7 +936,7 @@ test_file_functions (void)
|
||||
chars[n] = 0;
|
||||
if (strcmp (chars, hello) != 0)
|
||||
g_error ("wrote '%s', but got '%s'\n", hello, chars);
|
||||
|
||||
if (fd != -1)
|
||||
close (fd);
|
||||
remove (template);
|
||||
|
||||
@ -969,6 +967,7 @@ test_file_functions (void)
|
||||
else
|
||||
g_print ("g_file_open_tmp correctly returns error: %s\n", error->message);
|
||||
}
|
||||
if (fd != -1)
|
||||
close (fd);
|
||||
g_clear_error (&error);
|
||||
g_free (name_used);
|
||||
@ -981,6 +980,7 @@ test_file_functions (void)
|
||||
g_error ("g_file_open_tmp didn't work for template '%s': %s\n", template, error->message);
|
||||
else if (g_test_verbose())
|
||||
g_print ("g_file_open_tmp for template '%s' used name '%s'\n", template, name_used);
|
||||
if (fd != -1)
|
||||
close (fd);
|
||||
g_clear_error (&error);
|
||||
remove (name_used);
|
||||
@ -990,6 +990,7 @@ test_file_functions (void)
|
||||
fd = g_file_open_tmp (NULL, &name_used, &error);
|
||||
if (fd == -1)
|
||||
g_error ("g_file_open_tmp didn't work for a NULL template: %s\n", error->message);
|
||||
else
|
||||
close (fd);
|
||||
g_clear_error (&error);
|
||||
remove (name_used);
|
||||
|
Loading…
Reference in New Issue
Block a user