[RFA] Implement mkdtemp (patch ping)
Jeff Johnston
jjohnstn@redhat.com
Tue May 24 22:56:00 GMT 2005
Sorry about the delay.
Yes, a _mkdtemp_r function is required (we are setting errno based on the ptr
passed).
I would prefer an additional flag parameter for _gettemp as opposed to
overloading the dopen parameter.
Finally, the comments should be updated at the top with the new functions.
-- Jeff J.
Christopher Faylor wrote:
> 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) */
More information about the Newlib
mailing list