1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #include <stdio.h> 7 #include <string.h> 8 9 #include "posix_error_mapper.h" 10 11 12 static int* 13 real_errnop() 14 { 15 GET_REAL_FUNCTION(int*, _errnop, (void)); 16 return sReal__errnop(); 17 } 18 19 20 int* 21 _errnop(void) 22 { 23 HIDDEN_FUNCTION(_errnop); 24 25 // convert errno to positive error code 26 int* error = real_errnop(); 27 if (*error < 0) 28 *error = B_TO_POSITIVE_ERROR(*error); 29 return error; 30 } 31 32 33 34 WRAPPER_FUNCTION(char*, strerror, (int errorCode), 35 return sReal_strerror(B_TO_NEGATIVE_ERROR(errorCode)); 36 ) 37 38 39 WRAPPER_FUNCTION(int, strerror_r, 40 (int errorCode, char* buffer, size_t bufferSize), 41 return sReal_strerror_r(B_TO_NEGATIVE_ERROR(errorCode), buffer, bufferSize); 42 ) 43 44 45 WRAPPER_FUNCTION(void, perror, (const char* errorPrefix), 46 // convert errno to negative error code 47 int* error = real_errnop(); 48 int oldError = *error; 49 if (*error > 0) 50 *error = B_TO_NEGATIVE_ERROR(*error); 51 52 // call the real perror() 53 sReal_perror(errorPrefix); 54 55 // reset errno 56 *error = oldError; 57 ) 58