threadederrno.c revision 8eb8bab992e3998c33770b0cdb16059a8b918a06
1/* Make sure we use the POSIX version of strerror_r() on Linux. */ 2#define _XOPEN_SOURCE 600 3 4#include <pthread.h> 5#include <stdio.h> 6#include <errno.h> 7#include <string.h> 8 9 10void* thr2 ( void* v ) 11{ 12 char errstr[128]; 13 FILE* f = fopen("bogus2", "r"); 14 strerror_r(errno, errstr, sizeof(errstr)); 15 printf("f = %ld, errno = %d (%s)\n", (long)f, errno, errstr); 16 return NULL; 17} 18 19void* thr3 ( void* v ) 20{ 21 char errstr[128]; 22 FILE* f = fopen("bogus3", "r"); 23 strerror_r(errno, errstr, sizeof(errstr)); 24 printf("f = %ld, errno = %d (%s)\n", (long)f, errno, errstr); 25 return NULL; 26} 27 28 29int main ( void ) 30{ 31 char errstr[128]; 32 FILE* f; 33 pthread_t tid2, tid3; 34 pthread_create(&tid2, NULL, &thr2, NULL); 35 pthread_create(&tid3, NULL, &thr3, NULL); 36 f = fopen("bogus", "r"); 37 strerror_r(errno, errstr, sizeof(errstr)); 38 printf("f = %ld, errno = %d (%s)\n", (long)f, errno, errstr); 39 pthread_join(tid2, NULL); 40 pthread_join(tid3, NULL); 41 return 0; 42} 43 44