This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
Re: [RFA] Implement mkdtemp (patch ping)
- From: Christopher Faylor <me at cgf dot cx>
- To: newlib at sourceware dot org
- Date: Tue, 24 May 2005 16:43:35 -0400
- Subject: Re: [RFA] Implement mkdtemp (patch ping)
- References: <20050520030635.GA19887@trixie.casa.cgf.cx>
Ping?
cgf
On Thu, May 19, 2005 at 11:06:35PM -0400, Christopher Faylor wrote:
>This patch implements mkdtemp. I wasn't sure if a mkdtemp_r function was
>required or not but implementing one would be trivial.
>
>Ok to apply?
>
>cgf
>
>2005-05-19 Christopher Faylor <cgf@timesys.com>
>
> * libc/stdio/mktemp.c (_gettemp): Make a directory when doopen is zero,
> else make a file.
> (mkdtemp): New function.
>
>Index: libc/stdio/mktemp.c
>===================================================================
>RCS file: /cvs/uberbaum/newlib/libc/stdio/mktemp.c,v
>retrieving revision 1.8
>diff -u -p -r1.8 mktemp.c
>--- libc/stdio/mktemp.c 23 Apr 2004 20:01:55 -0000 1.8
>+++ libc/stdio/mktemp.c 20 May 2005 03:03:50 -0000
>@@ -152,8 +152,11 @@ _DEFUN(_gettemp, (ptr, path, doopen),
> {
> if (doopen)
> {
>- if ((*doopen = _open_r (ptr, path, O_CREAT | O_EXCL | O_RDWR, 0600))
>- >= 0)
>+ if (*doopen)
>+ *doopen = _open_r (ptr, path, O_CREAT | O_EXCL | O_RDWR, 0600);
>+ else
>+ *doopen = mkdir (path, 0700);
>+ if (*doopen >= 0)
> return 1;
> #if defined(__CYGWIN__)
> if (ptr->_errno != EEXIST && ptr->_errno != EACCES)
>@@ -194,7 +197,7 @@ _DEFUN(_mkstemp_r, (ptr, path),
> struct _reent *ptr _AND
> char *path)
> {
>- int fd;
>+ int fd = 1;
>
> return (_gettemp (ptr, path, &fd) ? fd : -1);
> }
>@@ -213,7 +216,7 @@ int
> _DEFUN(mkstemp, (path),
> char *path)
> {
>- int fd;
>+ int fd = 1;
>
> return (_gettemp (_REENT, path, &fd) ? fd : -1);
> }
>@@ -225,4 +228,12 @@ _DEFUN(mktemp, (path),
> return (_gettemp (_REENT, path, (int *) NULL) ? path : (char *) NULL);
> }
>
>+char *
>+_DEFUN(mkdtemp, (path),
>+ char *path)
>+{
>+ int fd = 0;
>+
>+ return (_gettemp (_REENT, path, &fd) ? path : NULL);
>+}
> #endif /* ! defined (_REENT_ONLY) */