delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/09/01/09:11:57

From: kunst AT prl DOT philips DOT nl
Subject: libsrc\c\gen\mktemp.c patch (solves tmpnam bug)
To: djgpp AT sun DOT soe DOT clarkson DOT edu (DJGPP users list)
Date: Thu, 1 Sep 1994 14:30:08 +0100 (METDST)

Hello DJ,

I've found the 'tmpnam' bug in dj112m1.
My earlier report that this was located in stat() was wrong.
The test program below (+output) shows that findfirst() when
invoked with a non-existent filename sets errno to 18 (ENMFILE),
(No more files) and not to 2 (ENOENT) (No such file or directory).
(Tested on a MS-DOS 6.2 system.)

Adding the patch below (to libsrc\c\gen\mktemp.c) solves the problem.

Regards,

Pieter Kunst (kunst AT prl DOT philips DOT nl)

===============================================================================
*** mktemp.old	Sun Aug 28 02:12:58 1994
--- mktemp.c	Thu Sep  1 18:17:18 1994
***************
*** 84,90 ****
  				return(0);
  		}
  		else if (stat(path, &sbuf))
! 			return(errno == ENOENT ? 1 : 0);
  
  		/* tricky little algorithm for backward compatibility */
  		for (trv = start;;) {
--- 84,90 ----
  				return(0);
  		}
  		else if (stat(path, &sbuf))
! 			return((errno == ENOENT) || (errno == ENMFILE) ? 1 : 0);
  
  		/* tricky little algorithm for backward compatibility */
  		for (trv = start;;) {
===============================================================================
#include <dir.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>

int main()
{
  char path[100];
  struct ffblk ffblk;
  int attrib = FA_DIREC | FA_HIDDEN | FA_SYSTEM;
  int rv;

  strcpy (path, "/nonexist");
  printf ("errno (before findfirst()) = %d\n", errno);
  rv = findfirst(path, &ffblk, attrib);
  printf ("errno (after findfirst())  = %d\n", errno);
  printf ("path = %s, rv = %d\n", path, rv);
  return 0;
}
===============================================================================
errno (before findfirst()) = 0
errno (after findfirst())  = 18
path = /nonexist, rv = -1
===============================================================================

- Raw text -


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