Last active
April 5, 2018 04:49
Revisions
-
m-renaud revised this gist
Jul 29, 2013 . 1 changed file with 6 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,8 +1,3 @@ // Examples of EINTR handling for reentrant functions. #include <errno.h> @@ -21,7 +16,8 @@ int myopen(char const* pathname, int flags) { errno = 0; ret_val = open(pathname, flags); } while(ret_val == -1 && errno == EINTR); return ret_val; } @@ -39,6 +35,7 @@ ssize_t myread(int fildes, void* buf, size_t nbyte) numbytes = read(fildes, buf, nbyte); } while (numbytes == -1 && errno == EINTR); return numbytes; } @@ -56,6 +53,7 @@ ssize_t mywrite(int fildes, void const* buf, size_t nbyte) numbytes = write(fildes, buf, nbyte); } while (numbytes == -1 && errno == EINTR); return numbytes; } @@ -69,7 +67,8 @@ int myclose(int fd) { errno = 0; ret_val = close(fd); } while(ret_val == -1 && errno == EINTR); return ret_val; } -
m-renaud created this gist
Jul 27, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,75 @@ //=========================================================================== // Copyright (c) 2012 Matt Renaud. All Rights Reserved. // //=========================================================================== // Examples of EINTR handling for reentrant functions. #include <errno.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> //m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // Open can be interupted when blocked, waiting for a slow device such as a // FIFO to open. int myopen(char const* pathname, int flags) { int ret_val; do { errno = 0; ret_val = open(pathname, flags); } while(ret_val == -1 && errno == EINTR); return ret_val; } //m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ssize_t myread(int fildes, void* buf, size_t nbyte) { ssize_t numbytes = 0; // Loop while the read function is interupted. Set errno in the loop // to make sure that another system call has not set it. do { errno = 0; numbytes = read(fildes, buf, nbyte); } while (numbytes == -1 && errno == EINTR); return numbytes; } //m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ssize_t mywrite(int fildes, void const* buf, size_t nbyte) { // Loop while the write function is interupted. Set errno in the loop // to make sure that another system call has not set it. ssize_t numbytes = 0; do { errno = 0; numbytes = write(fildes, buf, nbyte); } while (numbytes == -1 && errno == EINTR); return numbytes; } //m=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- int myclose(int fd) { int ret_val; do { errno = 0; ret_val = close(fd); } while(ret_val == -1 && errno == EINTR); return ret_val; }