@@ -263,6 +263,9 @@ main(int argc, char *argv[])
263263}
264264}
265265
266+ /*
267+ * func_call_1
268+ */
266269static void
267270func_call_1 (void )
268271{
@@ -272,23 +275,38 @@ func_call_1(void)
272275void * p ;
273276#endif
274277#ifdef WIN32
275- HANDLE h1 ,h2 ;
278+ HANDLE h1 ;
279+ #else
280+ int fd ;
276281#endif
277282
278283unlink (TEMP_FILENAME_1 );
279284
285+ /* Set errno = EEXIST */
286+
280287/* create, then try to fail on exclusive create open */
281288#ifdef WIN32
282- h1 = CreateFile (TEMP_FILENAME_1 ,GENERIC_WRITE ,0 ,NULL ,OPEN_ALWAYS ,0 ,NULL );
283- h2 = CreateFile (TEMP_FILENAME_1 ,GENERIC_WRITE ,0 ,NULL ,CREATE_NEW ,0 ,NULL );
284- if (h1 == INVALID_HANDLE_VALUE || GetLastError ()!= ERROR_FILE_EXISTS )
289+ if ((h1 = CreateFile (TEMP_FILENAME_1 ,GENERIC_WRITE ,0 ,NULL ,OPEN_ALWAYS ,0 ,NULL ))==
290+ INVALID_HANDLE_VALUE )
291+ #else
292+ if ((fd = open (TEMP_FILENAME_1 ,O_RDWR |O_CREAT ,0600 ))< 0 )
293+ #endif
294+ {
295+ fprintf (stderr ,"Could not create file %s in current directory\n" ,
296+ TEMP_FILENAME_1 );
297+ exit (1 );
298+ }
299+
300+ #ifdef WIN32
301+ if (CreateFile (TEMP_FILENAME_1 ,GENERIC_WRITE ,0 ,NULL ,CREATE_NEW ,0 ,NULL )
302+ != INVALID_HANDLE_VALUE || GetLastError ()!= ERROR_FILE_EXISTS )
285303#else
286- if (open (TEMP_FILENAME_1 ,O_RDWR |O_CREAT ,0600 )< 0 ||
287- open (TEMP_FILENAME_1 ,O_RDWR |O_CREAT |O_EXCL ,0600 ) >=0 )
304+ if (open (TEMP_FILENAME_1 ,O_RDWR |O_CREAT |O_EXCL ,0600 ) >=0 )
288305#endif
289306{
290- fprintf (stderr ,"Could not create file in current directory or\n" );
291- fprintf (stderr ,"could not generate failure for create file in current directory **\nexiting\n" );
307+ fprintf (stderr ,
308+ "Could not generate failure for exclusive file create of %s in current directory **\nexiting\n" ,
309+ TEMP_FILENAME_1 );
292310exit (1 );
293311}
294312
@@ -315,6 +333,11 @@ func_call_1(void)
315333exit (1 );
316334}
317335
336+ #ifdef WIN32
337+ CloseHandle (h1 );
338+ #else
339+ close (fd );
340+ #endif
318341unlink (TEMP_FILENAME_1 );
319342
320343#ifndef HAVE_STRERROR_R
@@ -352,6 +375,9 @@ func_call_1(void)
352375}
353376
354377
378+ /*
379+ * func_call_2
380+ */
355381static void
356382func_call_2 (void )
357383{
@@ -363,15 +389,14 @@ func_call_2(void)
363389
364390unlink (TEMP_FILENAME_2 );
365391
366- /* open non-existant file */
367- #ifdef WIN32
368- CreateFile (TEMP_FILENAME_2 ,GENERIC_WRITE ,0 ,NULL ,OPEN_EXISTING ,0 ,NULL );
369- if (GetLastError ()!= ERROR_FILE_NOT_FOUND )
370- #else
371- if (open (TEMP_FILENAME_2 ,O_RDONLY ,0600 ) >=0 )
372- #endif
392+ /* Set errno = ENOENT */
393+
394+ /* This will fail, but we can't check errno yet */
395+ if (unlink (TEMP_FILENAME_2 )!= -1 )
373396{
374- fprintf (stderr ,"Read-only open succeeded without create **\nexiting\n" );
397+ fprintf (stderr ,
398+ "Could not generate failure for unlink of %s in current directory **\nexiting\n" ,
399+ TEMP_FILENAME_2 );
375400exit (1 );
376401}
377402
@@ -394,12 +419,9 @@ func_call_2(void)
394419#else
395420fprintf (stderr ,"errno not thread-safe **\nexiting\n" );
396421#endif
397- unlink (TEMP_FILENAME_2 );
398422exit (1 );
399423}
400424
401- unlink (TEMP_FILENAME_2 );
402-
403425#ifndef HAVE_STRERROR_R
404426/*
405427 * If strerror() uses sys_errlist, the pointer might change for different