Skip to content

Commit 5473f28

Browse files
committed
Properly call strerror() in thread test; add comments.
1 parent e319ec4 commit 5473f28

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/test/thread/thread_test.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ main(int argc, char *argv[])
157157
if (rc != 0)
158158
{
159159
fprintf(stderr, "Failed to create thread 1: %s **\nexiting\n",
160-
strerror(rc));
160+
strerror(errno));
161161
exit(1);
162162
}
163163
rc = pthread_create(&thread2, NULL, (void *(*) (void *)) func_call_2, NULL);
@@ -285,6 +285,11 @@ func_call_1(void)
285285
/* Set errno = EEXIST */
286286

287287
/* create, then try to fail on exclusive create open */
288+
/*
289+
* It would be great to check errno here but if errno is not thread-safe
290+
* we might get a value from the other thread and mis-report the cause
291+
* of the failure.
292+
*/
288293
#ifdef WIN32
289294
if ((h1 = CreateFile(TEMP_FILENAME_1, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, 0, NULL)) ==
290295
INVALID_HANDLE_VALUE)
@@ -299,7 +304,7 @@ func_call_1(void)
299304

300305
#ifdef WIN32
301306
if (CreateFile(TEMP_FILENAME_1, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL)
302-
!= INVALID_HANDLE_VALUE || GetLastError() != ERROR_FILE_EXISTS)
307+
!= INVALID_HANDLE_VALUE)
303308
#else
304309
if (open(TEMP_FILENAME_1, O_RDWR | O_CREAT | O_EXCL, 0600) >= 0)
305310
#endif

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy