# define uintptr_t unsigned long
#endif
+#if !GNULIB_FCNTL_SAFER
+/* The results of open() in this file are not used with fchdir,
+ therefore save some unnecessary work in fchdir.c. */
+# undef open
+# undef close
+#endif
+
/* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5))
ensure that while constructing or modifying the data structures, the field
static bool
string_equals (const void *x1, const void *x2)
{
- const char *s1 = x1;
- const char *s2 = x2;
+ const char *s1 = (const char *) x1;
+ const char *s2 = (const char *) x2;
return strcmp (s1, s2) == 0;
}
static size_t
string_hash (const void *x)
{
- const char *s = x;
+ const char *s = (const char *) x;
size_t h = 0;
for (; *s; s++)
struct tempdir * volatile *tmpdirp = NULL;
struct tempdir *tmpdir;
size_t i;
- char *template;
+ char *xtemplate;
char *tmpdirname;
/* See whether it can take the slot of an earlier temporary directory
size_t old_allocated = cleanup_list.tempdir_allocated;
size_t new_allocated = 2 * cleanup_list.tempdir_allocated + 1;
struct tempdir * volatile *new_array =
- (struct tempdir * volatile *)
- xmalloc (new_allocated * sizeof (struct tempdir * volatile));
+ XNMALLOC (new_allocated, struct tempdir * volatile);
if (old_allocated == 0)
/* First use of this facility. Register the cleanup handler. */
}
/* Initialize a 'struct tempdir'. */
- tmpdir = (struct tempdir *) xmalloc (sizeof (struct tempdir));
+ tmpdir = XMALLOC (struct tempdir);
tmpdir->dirname = NULL;
tmpdir->cleanup_verbose = cleanup_verbose;
tmpdir->subdirs = gl_list_create_empty (GL_LINKEDHASH_LIST,
string_equals, string_hash, false);
/* Create the temporary directory. */
- template = (char *) xallocsa (PATH_MAX);
- if (path_search (template, PATH_MAX, parentdir, prefix, parentdir == NULL))
+ xtemplate = (char *) xallocsa (PATH_MAX);
+ if (path_search (xtemplate, PATH_MAX, parentdir, prefix, parentdir == NULL))
{
error (0, errno,
_("cannot find a temporary directory, try setting $TMPDIR"));
goto quit;
}
block_fatal_signals ();
- tmpdirname = mkdtemp (template);
+ tmpdirname = mkdtemp (xtemplate);
if (tmpdirname != NULL)
{
tmpdir->dirname = tmpdirname;
{
error (0, errno,
_("cannot create a temporary directory using template \"%s\""),
- template);
+ xtemplate);
goto quit;
}
/* Replace tmpdir->dirname with a copy that has indefinite extent.
block because then the cleanup handler would not remove the directory
if xstrdup fails. */
tmpdir->dirname = xstrdup (tmpdirname);
- freesa (template);
+ freesa (xtemplate);
return (struct temp_dir *) tmpdir;
quit:
- freesa (template);
+ freesa (xtemplate);
return NULL;
}