Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite319ec4

Browse files
committed
Simplify errno generating in thread testing program.
1 parentb33f78d commite319ec4

File tree

1 file changed

+41
-19
lines changed

1 file changed

+41
-19
lines changed

‎src/test/thread/thread_test.c

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ main(int argc, char *argv[])
263263
}
264264
}
265265

266+
/*
267+
* func_call_1
268+
*/
266269
staticvoid
267270
func_call_1(void)
268271
{
@@ -272,23 +275,38 @@ func_call_1(void)
272275
void*p;
273276
#endif
274277
#ifdefWIN32
275-
HANDLEh1,h2;
278+
HANDLEh1;
279+
#else
280+
intfd;
276281
#endif
277282

278283
unlink(TEMP_FILENAME_1);
279284

285+
/* Set errno = EEXIST */
286+
280287
/* create, then try to fail on exclusive create open */
281288
#ifdefWIN32
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+
#ifdefWIN32
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);
292310
exit(1);
293311
}
294312

@@ -315,6 +333,11 @@ func_call_1(void)
315333
exit(1);
316334
}
317335

336+
#ifdefWIN32
337+
CloseHandle(h1);
338+
#else
339+
close(fd);
340+
#endif
318341
unlink(TEMP_FILENAME_1);
319342

320343
#ifndefHAVE_STRERROR_R
@@ -352,6 +375,9 @@ func_call_1(void)
352375
}
353376

354377

378+
/*
379+
* func_call_2
380+
*/
355381
staticvoid
356382
func_call_2(void)
357383
{
@@ -363,15 +389,14 @@ func_call_2(void)
363389

364390
unlink(TEMP_FILENAME_2);
365391

366-
/* open non-existant file */
367-
#ifdefWIN32
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);
375400
exit(1);
376401
}
377402

@@ -394,12 +419,9 @@ func_call_2(void)
394419
#else
395420
fprintf(stderr,"errno not thread-safe **\nexiting\n");
396421
#endif
397-
unlink(TEMP_FILENAME_2);
398422
exit(1);
399423
}
400424

401-
unlink(TEMP_FILENAME_2);
402-
403425
#ifndefHAVE_STRERROR_R
404426
/*
405427
* If strerror() uses sys_errlist, the pointer might change for different

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp