1 /* CC0 (Public domain) - see LICENSE file for details */ 2 #include "noerr.h" 3 #include <unistd.h> 4 #include <errno.h> 5 #include <stdlib.h> 6 close_noerr(int fd)7int close_noerr(int fd) 8 { 9 int saved_errno = errno, ret; 10 11 if (close(fd) != 0) 12 ret = errno; 13 else 14 ret = 0; 15 16 errno = saved_errno; 17 return ret; 18 } 19 fclose_noerr(FILE * fp)20int fclose_noerr(FILE *fp) 21 { 22 int saved_errno = errno, ret; 23 24 if (fclose(fp) != 0) 25 ret = errno; 26 else 27 ret = 0; 28 29 errno = saved_errno; 30 return ret; 31 } 32 unlink_noerr(const char * pathname)33int unlink_noerr(const char *pathname) 34 { 35 int saved_errno = errno, ret; 36 37 if (unlink(pathname) != 0) 38 ret = errno; 39 else 40 ret = 0; 41 42 errno = saved_errno; 43 return ret; 44 } 45 free_noerr(void * p)46void free_noerr(void *p) 47 { 48 int saved_errno = errno; 49 free(p); 50 errno = saved_errno; 51 } 52