delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/04/28/12:05:56

Date: Tue, 28 Apr 1998 19:04:46 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: Andris Pavenis <pavenis AT ieva06 DOT lanet DOT lv>
cc: djgpp-workers AT delorie DOT com, DJ Delorie <dj AT delorie DOT com>
Subject: Re: mkstemp.c
In-Reply-To: <B0000028850@stargate.astr.lu.lv>
Message-ID: <Pine.SUN.3.91.980428190139.28333A-100000@is>
MIME-Version: 1.0

On Tue, 28 Apr 1998, Andris Pavenis wrote:

> When I'm calling 
>    mkstemp ("C:/aaaa/aaXXXXXX")    
> 
> and directory C:/aaaa does not exist then mkstemp will go into almost 
> infinite for normal user loop (2^30 loops) because mktemp() return not NULL and 
> _createnew returns -1 (error) but we are not looking for error code of _createnew.

Does the patch below solves this?  (I also send a similar patch for 
tmpfile, in case you need it.)

> Note: I didn't find _createnew in djlsr202 and also in djgpp-workers mailing list
> so I used
>     open ( name , O_RDWR+O_EXCL+O_CREAT , S_IWUSR+S_IPUSR )
> that should be equivalent to _createnewl

No, _creatnew is different.  I send you in a separate message a patch 
which will create it.

*** src/libc/compat/stdio/mkstemp.c~1	Thu Apr 23 15:24:46 1998
--- src/libc/compat/stdio/mkstemp.c	Tue Apr 28 18:50:18 1998
*************** mkstemp (char *_template)
*** 13,22 ****
  
    /* Make sure we create a non-exisiting file, even
       if race conditions exist with other processes.  */
!   do
      strcpy(tmp_name, _template);
!   while (mktemp (tmp_name) != NULL
! 	 && (fd = _creatnew(tmp_name, 0, SH_DENYRW)) == -1);
  
    if (fd == -1)
      errno = ENOENT;
--- 13,24 ----
  
    /* Make sure we create a non-exisiting file, even
       if race conditions exist with other processes.  */
!   do {
      strcpy(tmp_name, _template);
!     errno = 0;
!   } while (mktemp (tmp_name) != NULL
! 	   && (fd = _creatnew(tmp_name, 0, SH_DENYRW)) == -1
! 	   && errno != ENOENT);
  
    if (fd == -1)
      errno = ENOENT;
*** src/libc/ansi/stdio/tmpfile.c~1	Thu Apr 23 15:21:40 1998
--- src/libc/ansi/stdio/tmpfile.c	Tue Apr 28 18:53:00 1998
***************
*** 4,9 ****
--- 4,10 ----
  #include <stdio.h>
  #include <string.h>
  #include <stdlib.h>
+ #include <errno.h>
  #include <fcntl.h>
  #include <unistd.h>
  #include <io.h>
*************** tmpfile(void)
*** 28,36 ****
       moment when we actually open the file below.  This loop
       retries the call to `tmpnam' until we actually succeed
       to create the file which didn't exist before.  */
!   do
      temp_fd = _creatnew(temp_name, 0, SH_DENYRW);
!   while (temp_fd == -1 && (temp_name = tmpnam(0)) != 0);
  
    if (temp_name == 0)
      return 0;
--- 29,38 ----
       moment when we actually open the file below.  This loop
       retries the call to `tmpnam' until we actually succeed
       to create the file which didn't exist before.  */
!   do {
!     errno = 0;
      temp_fd = _creatnew(temp_name, 0, SH_DENYRW);
!   } while (temp_fd == -1 && errno != ENOENT && (temp_name = tmpnam(0)) != 0);
  
    if (temp_name == 0)
      return 0;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019