diff options
author | Eric Blake <ebb9@byu.net> | 2006-10-27 13:51:23 +0000 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2006-10-27 13:51:23 +0000 |
commit | a8753bfd5b8e2d2d440febce6355fc719eb469b4 (patch) | |
tree | 0ad6728246a66e61caf6fbcacf347708dcfd7786 | |
parent | 7f6be5eeffbc0e1aa1fbcd44fef901f1178591bc (diff) | |
download | gnulib-a8753bfd5b8e2d2d440febce6355fc719eb469b4.tar.gz |
* MODULES.html.sh: Document tempname.
* modules/mkstemp (Depends-on): Add tempname, and drop transitive
dependencies.
(Files): Move lib/tempname.c...
* modules/tempname: ...to this new module.
* m4/mkstemp.m4 (gl_FUNC_MKSTEMP): Remove tempname checks.
(gl_PREREQ_TEMPNAME): Move...
* m4/tempname.m4: ...to this new file.
* lib/mkstemp.c (includes) [!_LIBC]: Use tempname.h.
* modules/sys_stat (Depends-on): Add stat-macros.
* lib/stat_.h (includes): Pick up stat macros.
* m4/sys_stat_h.m4 (gl_HEADER_SYS_STAT_H): Replace <sys/stat.h>
if stat macros are broken.
* lib/tempname.c (includes): No need to include "stat-macros.h".
(__gen_tempname) [!_LIBC]: Expose as gen_tempname.
(direxists, __path_search) [!_LIBC]: Don't compile these in
gnulib; the tmpdir module covers that.
* lib/tempname.h: New file.
-rw-r--r-- | ChangeLog | 21 | ||||
-rwxr-xr-x | MODULES.html.sh | 3 | ||||
-rw-r--r-- | lib/mkstemp.c | 4 | ||||
-rw-r--r-- | lib/stat_.h | 4 | ||||
-rw-r--r-- | lib/tempname.c | 20 | ||||
-rw-r--r-- | lib/tempname.h | 40 | ||||
-rw-r--r-- | m4/mkstemp.m4 | 13 | ||||
-rw-r--r-- | m4/sys_stat_h.m4 | 6 | ||||
-rw-r--r-- | m4/tempname.m4 | 24 | ||||
-rw-r--r-- | modules/mkstemp | 5 | ||||
-rw-r--r-- | modules/sys_stat | 1 | ||||
-rw-r--r-- | modules/tempname | 26 |
12 files changed, 147 insertions, 20 deletions
@@ -1,3 +1,24 @@ +2006-10-27 Eric Blake <ebb9@byu.net> + + * MODULES.html.sh: Document tempname. + * modules/mkstemp (Depends-on): Add tempname, and drop transitive + dependencies. + (Files): Move lib/tempname.c... + * modules/tempname: ...to this new module. + * m4/mkstemp.m4 (gl_FUNC_MKSTEMP): Remove tempname checks. + (gl_PREREQ_TEMPNAME): Move... + * m4/tempname.m4: ...to this new file. + * lib/mkstemp.c (includes) [!_LIBC]: Use tempname.h. + * modules/sys_stat (Depends-on): Add stat-macros. + * lib/stat_.h (includes): Pick up stat macros. + * m4/sys_stat_h.m4 (gl_HEADER_SYS_STAT_H): Replace <sys/stat.h> + if stat macros are broken. + * lib/tempname.c (includes): No need to include "stat-macros.h". + (__gen_tempname) [!_LIBC]: Expose as gen_tempname. + (direxists, __path_search) [!_LIBC]: Don't compile these in + gnulib; the tmpdir module covers that. + * lib/tempname.h: New file. + 2006-10-26 Paul Eggert <eggert@cs.ucla.edu> * COPYING: Explain how gnulib-tool converts licence headers. diff --git a/MODULES.html.sh b/MODULES.html.sh index 9b3f333246..b10ae1cd85 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1848,11 +1848,12 @@ func_all_modules () func_module inet_ntop func_module inet_pton func_module mkdir - func_module mkstemp func_module mkdtemp + func_module mkstemp func_module poll func_module readlink func_module lstat + func_module tempname func_module time_r func_module timespec func_module nanosleep diff --git a/lib/mkstemp.c b/lib/mkstemp.c index eabee0c11f..34c9e474c0 100644 --- a/lib/mkstemp.c +++ b/lib/mkstemp.c @@ -18,7 +18,9 @@ #if !_LIBC # include <config.h> # include "mkstemp.h" -int __gen_tempname (); +# include "tempname.h" +# define __gen_tempname gen_tempname +# define __GT_FILE GT_FILE #endif #include <stdio.h> diff --git a/lib/stat_.h b/lib/stat_.h index 8c2e552f1f..f646dbb82b 100644 --- a/lib/stat_.h +++ b/lib/stat_.h @@ -1,4 +1,4 @@ -/* Provide a complete sys/stat header file. +/* Provide a more complete sys/stat header file. Copyright (C) 2006 Free Software Foundation, Inc. Written by Eric Blake. @@ -24,6 +24,8 @@ needed by an application. Start with what the system provides. */ #include @ABSOLUTE_SYS_STAT_H@ +#include "stat-macros.h" + /* mingw does not support symlinks, therefore it does not have lstat. But without links, stat does just fine. */ #if ! HAVE_LSTAT diff --git a/lib/tempname.c b/lib/tempname.c index 6fef5e9a1e..fd31acc444 100644 --- a/lib/tempname.c +++ b/lib/tempname.c @@ -17,8 +17,11 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +/* Extracted from glibc sysdeps/posix/tempname.c. See also tmpdir.c. */ + #if !_LIBC # include <config.h> +# include "tempname.h" #endif #include <sys/types.h> @@ -63,10 +66,10 @@ # define small_open __open # define large_open __open64 #else -# include "stat-macros.h" # define struct_stat64 struct stat # define small_open open # define large_open open +# define __gen_tempname gen_tempname # define __getpid getpid # define __gettimeofday gettimeofday # define __mkdir mkdir @@ -106,6 +109,7 @@ # define uint64_t uintmax_t #endif +#if _LIBC /* Return nonzero if DIR is an existent directory. */ static int direxists (const char *dir) @@ -176,6 +180,7 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx, sprintf (tmpl, "%.*s/%.*sXXXXXX", (int) dlen, dir, (int) plen, pfx); return 0; } +#endif /* _LIBC */ /* These are the characters used in temporary file names. */ static const char letters[] = @@ -195,6 +200,7 @@ static const char letters[] = __GT_DIR: create a directory, which will be mode 0700. We use a clever algorithm to get hard-to-predict names. */ +#if _LIBC || !HAVE___GEN_TEMPNAME int __gen_tempname (char *tmpl, int kind) { @@ -315,3 +321,15 @@ __gen_tempname (char *tmpl, int kind) __set_errno (EEXIST); return -1; } + +#else /* !_LIBC && HAVE___GEN_TEMPNAME */ + +# undef __gen_tempname +extern int __gen_tempname (char *, int); +int +gen_tempname (char *tmpl, int kind) +{ + return __gen_tempname (tmpl, kind); +} + +#endif /* !_LIBC && HAVE___GEN_TEMPNAME */ diff --git a/lib/tempname.h b/lib/tempname.h new file mode 100644 index 0000000000..c51fa69424 --- /dev/null +++ b/lib/tempname.h @@ -0,0 +1,40 @@ +/* Create a temporary file or directory. + + Copyright (C) 2006 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* header written by Eric Blake */ + +/* In gnulib, always prefer large files. GT_FILE maps to + __GT_BIGFILE, not __GT_FILE, for a reason. */ +#define GT_FILE 1 +#define GT_DIR 2 +#define GT_NOCREATE 3 + +/* Generate a temporary file name based on TMPL. TMPL must match the + rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed + does not exist at the time of the call to gen_tempname. TMPL is + overwritten with the result. + + KIND may be one of: + GT_NOCREATE: simply verify that the name does not exist + at the time of the call. + GT_FILE: create a large file using open(O_CREAT|O_EXCL) + and return a read-write fd. The file is mode 0600. + GT_DIR: create a directory, which will be mode 0700. + + We use a clever algorithm to get hard-to-predict names. */ +extern int gen_tempname (char *tmpl, int kind); diff --git a/m4/mkstemp.m4 b/m4/mkstemp.m4 index e58fdf82ad..27367cb706 100644 --- a/m4/mkstemp.m4 +++ b/m4/mkstemp.m4 @@ -1,4 +1,4 @@ -#serial 14 +#serial 15 # Copyright (C) 2001, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -45,10 +45,8 @@ AC_DEFUN([gl_FUNC_MKSTEMP], if test $gl_cv_func_working_mkstemp != yes; then AC_DEFINE([__MKSTEMP_PREFIX], [[rpl_]], [Define to rpl_ if the mkstemp replacement function should be used.]) - AC_LIBOBJ(mkstemp) - AC_LIBOBJ(tempname) + AC_LIBOBJ([mkstemp]) gl_PREREQ_MKSTEMP - gl_PREREQ_TEMPNAME fi ]) @@ -56,10 +54,3 @@ AC_DEFUN([gl_FUNC_MKSTEMP], AC_DEFUN([gl_PREREQ_MKSTEMP], [ ]) - -# Prerequisites of lib/tempname.c. -AC_DEFUN([gl_PREREQ_TEMPNAME], -[ - AC_CHECK_HEADERS_ONCE(sys/time.h) - AC_CHECK_FUNCS(__secure_getenv gettimeofday) -]) diff --git a/m4/sys_stat_h.m4 b/m4/sys_stat_h.m4 index c432ac2544..bf9bb9544e 100644 --- a/m4/sys_stat_h.m4 +++ b/m4/sys_stat_h.m4 @@ -17,8 +17,12 @@ AC_DEFUN([gl_HEADER_SYS_STAT_H], dnl instead. AC_CHECK_DECLS([mkdir], [], [], [#include <sys/stat.h>]) + dnl Check for broken stat macros. + AC_REQUIRE([AC_HEADER_STAT]) + SYS_STAT_H= - if test $ac_cv_func_lstat:$ac_cv_have_decl_mkdir != yes:yes ; then + if test $ac_cv_func_lstat:$ac_cv_have_decl_mkdir:$ac_cv_header_stat_broken \ + != yes:yes:no ; then gl_ABSOLUTE_HEADER([sys/stat.h]) ABSOLUTE_SYS_STAT_H=\"$gl_cv_absolute_sys_stat_h\" AC_CHECK_HEADERS([io.h]) diff --git a/m4/tempname.m4 b/m4/tempname.m4 new file mode 100644 index 0000000000..cd0e442a4f --- /dev/null +++ b/m4/tempname.m4 @@ -0,0 +1,24 @@ +#serial 1 + +# Copyright (C) 2006 Free Software Foundation, Inc. +# This file is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# glibc provides __gen_tempname as a wrapper for mk[ds]temp. Expose +# it as a public API, and provide it on systems that are lacking. +AC_DEFUN([gl_FUNC_GEN_TEMPNAME], +[ + AC_REQUIRE([AC_SYS_LARGEFILE]) + AC_CHECK_FUNCS_ONCE([__gen_tempname]) + + AC_LIBOBJ([tempname]) + gl_PREREQ_TEMPNAME +]) + +# Prerequisites of lib/tempname.c. +AC_DEFUN([gl_PREREQ_TEMPNAME], +[ + AC_CHECK_HEADERS_ONCE([sys/time.h]) + AC_CHECK_FUNCS_ONCE([gettimeofday]) +]) diff --git a/modules/mkstemp b/modules/mkstemp index 7d0173521d..dc77562e73 100644 --- a/modules/mkstemp +++ b/modules/mkstemp @@ -4,14 +4,11 @@ mkstemp() function: create a private temporary file. Files: lib/mkstemp.h lib/mkstemp.c -lib/tempname.c m4/mkstemp.m4 Depends-on: extensions -stat-macros -stdint -sys_stat +tempname configure.ac: gl_FUNC_MKSTEMP diff --git a/modules/sys_stat b/modules/sys_stat index 3b8839f91f..9dbb900932 100644 --- a/modules/sys_stat +++ b/modules/sys_stat @@ -7,6 +7,7 @@ m4/absolute-header.m4 m4/sys_stat_h.m4 Depends-on: +stat-macros configure.ac: gl_HEADER_SYS_STAT_H diff --git a/modules/tempname b/modules/tempname new file mode 100644 index 0000000000..a94f568480 --- /dev/null +++ b/modules/tempname @@ -0,0 +1,26 @@ +Description: +gen_tempname() function: create a private temporary file or directory. + +Files: +lib/tempname.c +lib/tempname.h +m4/tempname.m4 + +Depends-on: +extensions +stdint +sys_stat + +configure.ac: +gl_FUNC_GEN_TEMPNAME + +Makefile.am: + +Include: +"tempname.h" + +License: +GPL + +Maintainer: +Eric Blake and Jim Meyering |