[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mingw conflict between mkdtemp and sys_stat
From: |
Eric Blake |
Subject: |
Re: mingw conflict between mkdtemp and sys_stat |
Date: |
Fri, 27 Oct 2006 07:50:47 -0600 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Thunderbird/1.5.0.7 Mnenhy/0.7.4.666 |
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Paul Eggert on 10/17/2006 10:03 PM:
> Eric Blake <address@hidden> writes:
>
>> It just looks nicer if we provide gnulib
>> modules with exported APIs that do not lie in the reserved namespace.
>
> Sure, but can't you do something like the following (taken from
> mktime.c)? This minimizes the changes from libc and packages it
> inside "#ifndef _LIBC" blocks that the libc maintainers can safely
> ignore. Admittedly it relies on undefined behavior since it defines
> __something, but if that's a real problem we can fix it later.
I broke my original proposal into two parts. Here's the first half, where
I add the tempname module, and expose gen_tempname in a new header, and
fix mkstemp to use it (so far, touching only modules that Paul and Jim
maintain). I'm going ahead and checking it in. The changes to tempname.c
are not as drastic as in the original, so that it should now be easier to
compare it to glibc.
The second half, fixing mkdtemp to use the new tempname module and the
existing sys_stat module, so that mkdtemp and mkstemp can coexist on
mingw, still needs Bruno's approval; I'll post that patch later in light
of this commit. And I need mkdtemp fixed before I can release M4 1.4.8;
I'm hoping I don't need to use a gnulib-tool --local-dir workaround if I
can avoid it. (Hmm, gnulib-tool --help doesn't document --local-dir).
Also, is it worth changing other modules that depend on stat-macros to
instead depend on sys_stat, and delete the #include "stat-macros.h" line
from their implementation?
2006-10-27 Eric Blake <address@hidden>
* 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.
- --
Life is short - so eat dessert first!
Eric Blake address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFQg6284KuGfSFAYARAgueAKCjkOhvhQRZVsW9s2wDZCFQz28mGACfQlLD
37bBhmc3TEsgYPL/Hh8dEQs=
=RVxb
-----END PGP SIGNATURE-----
Index: MODULES.html.sh
===================================================================
RCS file: /sources/gnulib/gnulib/MODULES.html.sh,v
retrieving revision 1.155
diff -u -p -r1.155 MODULES.html.sh
--- MODULES.html.sh 24 Oct 2006 22:32:25 -0000 1.155
+++ MODULES.html.sh 27 Oct 2006 13:46:27 -0000
@@ -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
Index: modules/mkstemp
===================================================================
RCS file: /sources/gnulib/gnulib/modules/mkstemp,v
retrieving revision 1.13
diff -u -p -r1.13 mkstemp
--- modules/mkstemp 13 Oct 2006 12:40:23 -0000 1.13
+++ modules/mkstemp 27 Oct 2006 13:46:27 -0000
@@ -4,14 +4,11 @@ mkstemp() function: create a private tem
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
Index: modules/sys_stat
===================================================================
RCS file: /sources/gnulib/gnulib/modules/sys_stat,v
retrieving revision 1.7
diff -u -p -r1.7 sys_stat
--- modules/sys_stat 13 Oct 2006 12:40:23 -0000 1.7
+++ modules/sys_stat 27 Oct 2006 13:46:27 -0000
@@ -7,6 +7,7 @@ m4/absolute-header.m4
m4/sys_stat_h.m4
Depends-on:
+stat-macros
configure.ac:
gl_HEADER_SYS_STAT_H
Index: modules/tempname
===================================================================
RCS file: modules/tempname
diff -N modules/tempname
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/tempname 27 Oct 2006 13:46:27 -0000
@@ -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
Index: lib/mkstemp.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/mkstemp.c,v
retrieving revision 1.8
diff -u -p -r1.8 mkstemp.c
--- lib/mkstemp.c 20 Sep 2006 18:44:04 -0000 1.8
+++ lib/mkstemp.c 27 Oct 2006 13:46:27 -0000
@@ -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>
Index: lib/stat_.h
===================================================================
RCS file: /sources/gnulib/gnulib/lib/stat_.h,v
retrieving revision 1.4
diff -u -p -r1.4 stat_.h
--- lib/stat_.h 21 Aug 2006 06:11:26 -0000 1.4
+++ lib/stat_.h 27 Oct 2006 13:46:27 -0000
@@ -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
Index: lib/tempname.c
===================================================================
RCS file: /sources/gnulib/gnulib/lib/tempname.c,v
retrieving revision 1.21
diff -u -p -r1.21 tempname.c
--- lib/tempname.c 20 Sep 2006 18:38:14 -0000 1.21
+++ lib/tempname.c 27 Oct 2006 13:46:27 -0000
@@ -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_l
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 */
Index: lib/tempname.h
===================================================================
RCS file: lib/tempname.h
diff -N lib/tempname.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/tempname.h 27 Oct 2006 13:46:27 -0000
@@ -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);
Index: m4/mkstemp.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/mkstemp.m4,v
retrieving revision 1.19
diff -u -p -r1.19 mkstemp.m4
--- m4/mkstemp.m4 20 Sep 2006 18:44:04 -0000 1.19
+++ m4/mkstemp.m4 27 Oct 2006 13:46:27 -0000
@@ -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)
-])
Index: m4/sys_stat_h.m4
===================================================================
RCS file: /sources/gnulib/gnulib/m4/sys_stat_h.m4,v
retrieving revision 1.4
diff -u -p -r1.4 sys_stat_h.m4
--- m4/sys_stat_h.m4 11 Jul 2006 06:13:28 -0000 1.4
+++ m4/sys_stat_h.m4 27 Oct 2006 13:46:27 -0000
@@ -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])
Index: m4/tempname.m4
===================================================================
RCS file: m4/tempname.m4
diff -N m4/tempname.m4
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ m4/tempname.m4 27 Oct 2006 13:46:27 -0000
@@ -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])
+])
- mingw conflict between mkdtemp and sys_stat, Eric Blake, 2006/10/13
- Re: mingw conflict between mkdtemp and sys_stat, Eric Blake, 2006/10/13
- Re: mingw conflict between mkdtemp and sys_stat, Eric Blake, 2006/10/13
- Re: mingw conflict between mkdtemp and sys_stat, Paul Eggert, 2006/10/15
- Re: mingw conflict between mkdtemp and sys_stat, Eric Blake, 2006/10/17
- Re: mingw conflict between mkdtemp and sys_stat, Paul Eggert, 2006/10/18
- Re: mingw conflict between mkdtemp and sys_stat,
Eric Blake <=
- Re: mingw conflict between mkdtemp and sys_stat, Eric Blake, 2006/10/27
- Re: mingw conflict between mkdtemp and sys_stat, Eric Blake, 2006/10/31
- Re: mingw conflict between mkdtemp and sys_stat, Paul Eggert, 2006/10/27