This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA:] add _mkdir_r, fixing fallout from "add mkstemps, mkdtemp"


I noticed my autotester hadn't been able to update newlib for
quite a while, due to testsuite regressions introduced by the
attempted update.  Looks like it was due to this patch, to be
specific, the _mkdir_r call in the quoted code below:

> 2009-06-29  Eric Blake  <ebb9@byu.net>
> 
> 	Add mkdtemp, mkstemps.
> 	* libc/stdio/mktemp.c: Fix documentation.
> 	(_gettemp): Add domkdir and length parameters.  Check for
> 	insufficient 'X' suffix.  Drop cygwin-specific code.
> 	(_mkstemp_r, _mktemp_r, mkstemp, mktemp): Adjust clients.
> 	(_mkdtemp_r, _mkstemps_r, mkdtemp, mkstemps): New functions.
> 	* libc/include/stdlib.h (_mkdtemp_r, _mkstemps_r, mkdtemp)
> 	(mkstemps): Declare them.

> diff -u -p -r1.10 mktemp.c
> --- libc/stdio/mktemp.c	14 Mar 2009 12:14:08 -0000	1.10
> +++ libc/stdio/mktemp.c	29 Jun 2009 12:44:24 -0000

> @@ -161,16 +193,22 @@ _DEFUN(_gettemp, (ptr, path, doopen),
>  
>    for (;;)
>      {
> +#if !defined _ELIX_LEVEL || _ELIX_LEVEL >= 2
> +      if (domkdir)
> +	{
> +	  if (_mkdir_r (ptr, path, 0700) == 0)
> +	    return 1;
> +	  if (ptr->_errno != EEXIST)
> +	    return 0;
> +	}
> +      else
> +#endif /* _ELIX_LEVEL */

So, where did you find that _mkdir_r you're calling?  Were there
missing parts to the above patches?  Would those parts look like
the patches below, adding necessary framework and stub for the
mkdir syscall?  They should, because without this, I get 1168
gcc gfortran testsuite regressions for cris-elf (not an ELIX
target) when trying to update newlib.  The failures look like
the following:

Executing on host: /tmp/updbad2/gccobj/gcc/testsuite/gfortran/../../gfortran -B/tmp/updbad2/gccobj/gcc/testsuite/gfortran/../../ /tmp/updbad2/gcc/gcc/testsuite/gfortran.dg/PR19754_2.f90   -O0   -pedantic-errors   -isystem /tmp/updbad2/gccobj/cris-elf/./newlib/targ-include -isystem /tmp/updbad2/gcc/newlib/libc/include -B/tmp/updbad2/gccobj/cris-elf/./libgloss/cris/ -L/tmp/updbad2/gccobj/cris-elf/./libgloss/cris -L/tmp/updbad2/gcc/libgloss/cris  -B/tmp/updbad2/gccobj/cris-elf/./newlib/ -L/tmp/updbad2/gccobj/cris-elf/./newlib -sim3  -L/tmp/updbad2/gccobj/cris-elf/./libgfortran/.libs -L/tmp/updbad2/gccobj/cris-elf/./libiberty  -lm   -o ./PR19754_2.exe    (timeout = 300)
/tmp/updbad2/gccobj/cris-elf/./newlib/libc.a(lib_a-mktemp.o): In function `_gettemp':
/tmp/updbad2/gcc/newlib/libc/stdio/mktemp.c:204: undefined reference to `__mkdir_r'
collect2: ld returned 1 exit status
compiler exited with status 1
output is:
/tmp/updbad2/gccobj/cris-elf/./newlib/libc.a(lib_a-mktemp.o): In function `_gettemp':
/tmp/updbad2/gcc/newlib/libc/stdio/mktemp.c:204: undefined reference to `__mkdir_r'
collect2: ld returned 1 exit status
FAIL: gfortran.dg/PR19754_2.f90  -O0  (test for excess errors)

I very much think all non-ELIXy newlib targets would get the
same results.  Except for cygwin perhaps...  Grep finds no
_mkdir_r in today's newlib tree, not even a declaration.
There's appears to be no matching mkdir stuff at all.

I included the diff for the regenerated reent/Makefile.in for
usability of this patch.  There are two seemingly-spurious
HAVE_LONG_DOUBLE_FALSE/TRUE lines, but they're there because of
a previous missing regen.  An alternative to this patch is
presumably to remove the code quoted above.

With this patch, I can use today's newlib with test-suite
results fixed (the same as before the above patch) for cris-elf.
Nope, didn't test it anywhere else.  Not trying to raise the bar.

Ok to commit?
(PS. can we start using ISO C89 non-K&R function headers soon?)

libgloss:
2009-08-11  Hans-Peter Nilsson  <hp@axis.com>

	* libnosys/Makefile.in (OBJS): Add mkdir.
	* libnosys/mkdir.c: New file.

newlib:
2009-08-11  Hans-Peter Nilsson  <hp@axis.com>

	* libc/include/reent.h: Add prototype and definition of _mkdir_r.
	* libc/reent/Makefile.am (GENERAL_SOURCES): Add mkdirr.c.
	(CHEWOUT_FILES): Add mkdirr.def.
	* libc/reent/Makefile.in: Regenerate.
	* libc/reent/mkdirr.c: New file.

Index: libgloss/libnosys/Makefile.in
===================================================================
RCS file: /cvs/src/src/libgloss/libnosys/Makefile.in,v
retrieving revision 1.6
diff -u -p -r1.6 Makefile.in
--- libgloss/libnosys/Makefile.in	30 Nov 2005 23:43:57 -0000	1.6
+++ libgloss/libnosys/Makefile.in	11 Aug 2009 20:18:22 -0000
@@ -66,9 +66,9 @@ OBJCOPY = `if [ -f ${objroot}/../binutil
 
 # object files needed
 OBJS = chown.o close.o environ.o errno.o execve.o fork.o fstat.o \
-	getpid.o gettod.o isatty.o kill.o link.o lseek.o open.o \
-	read.o readlink.o sbrk.o stat.o symlink.o times.o unlink.o \
-	wait.o write.o _exit.o
+	getpid.o gettod.o isatty.o kill.o link.o lseek.o mkdir.o \
+	open.o read.o readlink.o sbrk.o stat.o symlink.o times.o \
+	unlink.o wait.o write.o _exit.o
 
 # Object files specific to particular targets.
 EVALOBJS = ${OBJS}

--- /dev/null	Tue Oct 29 15:57:07 2002
+++ libgloss/libnosys/mkdir.c	Tue Aug 11 21:33:50 2009
@@ -0,0 +1,22 @@
+/*
+ * Stub version of mkdir.
+ */
+
+#include "config.h"
+#include <_ansi.h>
+#include <_syslist.h>
+#include <errno.h>
+#undef errno
+extern int errno;
+#include "warning.h"
+
+int
+_DEFUN (_mkdir, (path, mode),
+        char *path  _AND
+        int   mode)
+{
+  errno = ENOSYS;
+  return -1;
+}
+
+stub_warning(_mkdir)

Index: newlib/libc/include/reent.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/reent.h,v
retrieving revision 1.10
diff -u -p -r1.10 reent.h
--- newlib/libc/include/reent.h	11 Dec 2008 17:27:55 -0000	1.10
+++ newlib/libc/include/reent.h	11 Aug 2009 20:18:22 -0000
@@ -116,6 +116,7 @@ struct timezone;
 #define _kill_r(__reent, __pid, __signal)         kill(__pid, __signal)
 #define _link_r(__reent, __oldpath, __newpath)    link(__oldpath, __newpath)
 #define _lseek_r(__reent, __fdes, __off, __w)     lseek(__fdes, __off, __w)
+#define _mkdir_r(__reent, __path, __m)		  mkdir(__path, __m)
 #define _open_r(__reent, __path, __flag, __m)     open(__path, __flag, __m)
 #define _read_r(__reent, __fd, __buff, __cnt)     read(__fd, __buff, __cnt)
 #define _rename_r(__reent, __old, __new)	  rename(__old, __new)
@@ -146,6 +147,7 @@ extern int _isatty_r _PARAMS ((struct _r
 extern int _kill_r _PARAMS ((struct _reent *, int, int));
 extern int _link_r _PARAMS ((struct _reent *, const char *, const char *));
 extern _off_t _lseek_r _PARAMS ((struct _reent *, int, _off_t, int));
+extern int _mkdir_r _PARAMS ((struct _reent *, const char *, int));
 extern int _open_r _PARAMS ((struct _reent *, const char *, int, int));
 extern _ssize_t _read_r _PARAMS ((struct _reent *, int, void *, size_t));
 extern int _rename_r _PARAMS ((struct _reent *, const char *, const char *));
Index: newlib/libc/reent/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/reent/Makefile.am,v
retrieving revision 1.14
diff -u -p -r1.14 Makefile.am
--- newlib/libc/reent/Makefile.am	24 Nov 2008 21:16:06 -0000	1.14
+++ newlib/libc/reent/Makefile.am	11 Aug 2009 20:18:22 -0000
@@ -42,6 +42,7 @@ GENERAL_SOURCES = \
 	isattyr.c \
 	linkr.c \
 	lseekr.c \
+	mkdirr.c \
 	openr.c \
 	readr.c \
 	renamer.c \
@@ -77,6 +78,7 @@ CHEWOUT_FILES = \
 	gettimeofdayr.def \
 	linkr.def \
 	lseekr.def \
+	mkdirr.def \
 	openr.def \
 	readr.def \
 	renamer.def \
--- /dev/null	Tue Oct 29 15:57:07 2002
+++ newlib/libc/reent/mkdirr.c	Tue Aug 11 21:30:21 2009
@@ -0,0 +1,62 @@
+/* Reentrant versions of mkdir system call. */
+
+#include <reent.h>
+#include <unistd.h>
+#include <_syslist.h>
+
+/* Some targets provides their own versions of this functions.  Those
+   targets should define REENTRANT_SYSCALLS_PROVIDED in TARGET_CFLAGS.  */
+
+#ifdef _REENT_ONLY
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+#define REENTRANT_SYSCALLS_PROVIDED
+#endif
+#endif
+
+#ifndef REENTRANT_SYSCALLS_PROVIDED
+
+/* We use the errno variable used by the system dependent layer.  */
+#undef errno
+extern int errno;
+
+/*
+FUNCTION
+	<<_mkdir_r>>---Reentrant version of mkdir
+	
+INDEX
+	_mkdir_r
+
+ANSI_SYNOPSIS
+	#include <reent.h>
+	int _mkdir_r(struct _reent *<[ptr]>,
+		     const char *<[path]>, int <[mode]>);
+
+TRAD_SYNOPSIS
+	#include <reent.h>
+	int _mkdir_r(<[ptr]>, <[path]>, <[mode]>)
+	struct _reent *<[ptr]>;
+	char *<[path]>;
+	int <[mode]>;
+
+DESCRIPTION
+	This is a reentrant version of <<mkdir>>.  It
+	takes a pointer to the global data block, which holds
+	<<errno>>.
+*/
+
+int
+_DEFUN (_mkdir_r, (ptr, path, mode),
+     struct _reent *ptr _AND
+     _CONST char *path _AND
+     int mode)
+{
+  int ret;
+
+  errno = 0;
+  if ((ret = _mkdir (path, mode)) == -1 && errno != 0)
+    ptr->_errno = errno;
+  return ret;
+}
+
+
+#endif /* ! defined (REENTRANT_SYSCALLS_PROVIDED) */
Index: newlib/libc/reent/Makefile.in
===================================================================
RCS file: /cvs/src/src/newlib/libc/reent/Makefile.in,v
retrieving revision 1.27
diff -u -p -r1.27 Makefile.in
--- newlib/libc/reent/Makefile.in	24 Nov 2008 21:16:06 -0000	1.27
+++ newlib/libc/reent/Makefile.in	11 Aug 2009 20:18:22 -0000
@@ -62,11 +62,12 @@ am__objects_1 = lib_a-closer.$(OBJEXT) l
 	lib_a-fstatr.$(OBJEXT) lib_a-getreent.$(OBJEXT) \
 	lib_a-gettimeofdayr.$(OBJEXT) lib_a-isattyr.$(OBJEXT) \
 	lib_a-linkr.$(OBJEXT) lib_a-lseekr.$(OBJEXT) \
-	lib_a-openr.$(OBJEXT) lib_a-readr.$(OBJEXT) \
-	lib_a-renamer.$(OBJEXT) lib_a-signalr.$(OBJEXT) \
-	lib_a-signgam.$(OBJEXT) lib_a-sbrkr.$(OBJEXT) \
-	lib_a-statr.$(OBJEXT) lib_a-timesr.$(OBJEXT) \
-	lib_a-unlinkr.$(OBJEXT) lib_a-writer.$(OBJEXT)
+	lib_a-mkdirr.$(OBJEXT) lib_a-openr.$(OBJEXT) \
+	lib_a-readr.$(OBJEXT) lib_a-renamer.$(OBJEXT) \
+	lib_a-signalr.$(OBJEXT) lib_a-signgam.$(OBJEXT) \
+	lib_a-sbrkr.$(OBJEXT) lib_a-statr.$(OBJEXT) \
+	lib_a-timesr.$(OBJEXT) lib_a-unlinkr.$(OBJEXT) \
+	lib_a-writer.$(OBJEXT)
 @HAVE_STDIO64_DIR_TRUE@am__objects_2 = lib_a-fstat64r.$(OBJEXT) \
 @HAVE_STDIO64_DIR_TRUE@	lib_a-lseek64r.$(OBJEXT) \
 @HAVE_STDIO64_DIR_TRUE@	lib_a-stat64r.$(OBJEXT) \
@@ -85,8 +86,8 @@ LTLIBRARIES = $(noinst_LTLIBRARIES)
 libreent_la_LIBADD =
 am__objects_6 = closer.lo reent.lo impure.lo fcntlr.lo fstatr.lo \
 	getreent.lo gettimeofdayr.lo isattyr.lo linkr.lo lseekr.lo \
-	openr.lo readr.lo renamer.lo signalr.lo signgam.lo sbrkr.lo \
-	statr.lo timesr.lo unlinkr.lo writer.lo
+	mkdirr.lo openr.lo readr.lo renamer.lo signalr.lo signgam.lo \
+	sbrkr.lo statr.lo timesr.lo unlinkr.lo writer.lo
 @HAVE_STDIO64_DIR_TRUE@am__objects_7 = fstat64r.lo lseek64r.lo \
 @HAVE_STDIO64_DIR_TRUE@	stat64r.lo open64r.lo
 am__objects_8 = $(am__objects_7)
@@ -158,6 +159,8 @@ ENABLE_NEWLIB_ICONV_TRUE = @ENABLE_NEWLI
 EXEEXT = @EXEEXT@
 FGREP = @FGREP@
 GREP = @GREP@
+HAVE_LONG_DOUBLE_FALSE = @HAVE_LONG_DOUBLE_FALSE@
+HAVE_LONG_DOUBLE_TRUE = @HAVE_LONG_DOUBLE_TRUE@
 HAVE_POSIX_DIR_FALSE = @HAVE_POSIX_DIR_FALSE@
 HAVE_POSIX_DIR_TRUE = @HAVE_POSIX_DIR_TRUE@
 HAVE_SIGNAL_DIR_FALSE = @HAVE_SIGNAL_DIR_FALSE@
@@ -313,6 +316,7 @@ GENERAL_SOURCES = \
 	isattyr.c \
 	linkr.c \
 	lseekr.c \
+	mkdirr.c \
 	openr.c \
 	readr.c \
 	renamer.c \
@@ -341,6 +345,7 @@ CHEWOUT_FILES = \
 	gettimeofdayr.def \
 	linkr.def \
 	lseekr.def \
+	mkdirr.def \
 	openr.def \
 	readr.def \
 	renamer.def \
@@ -483,6 +488,12 @@ lib_a-lseekr.o: lseekr.c
 lib_a-lseekr.obj: lseekr.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-lseekr.obj `if test -f 'lseekr.c'; then $(CYGPATH_W) 'lseekr.c'; else $(CYGPATH_W) '$(srcdir)/lseekr.c'; fi`
 
+lib_a-mkdirr.o: mkdirr.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mkdirr.o `test -f 'mkdirr.c' || echo '$(srcdir)/'`mkdirr.c
+
+lib_a-mkdirr.obj: mkdirr.c
+	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mkdirr.obj `if test -f 'mkdirr.c'; then $(CYGPATH_W) 'mkdirr.c'; else $(CYGPATH_W) '$(srcdir)/mkdirr.c'; fi`
+
 lib_a-openr.o: openr.c
 	$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-openr.o `test -f 'openr.c' || echo '$(srcdir)/'`openr.c
 
brgds, H-P


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]