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 #include #include #include 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 ===============================================================================