Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/compat/nonblock.c # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / compat / nonblock.c` 50 lines ยท 939 bytes Raw Blame History 1 #include "git-compat-util.h" 2 #include "nonblock.h" 3 4 #ifdef O_NONBLOCK 5 6 int enable_pipe_nonblock(int fd) 7 { 8 int flags = fcntl(fd, F_GETFL); 9 if (flags < 0) 10 return -1; 11 flags |= O_NONBLOCK; 12 return fcntl(fd, F_SETFL, flags); 13 } 14 15 #elif defined(GIT_WINDOWS_NATIVE) 16 17 #include "win32.h" 18 19 int enable_pipe_nonblock(int fd) 20 { 21 HANDLE h = (HANDLE)_get_osfhandle(fd); 22 DWORD mode; 23 DWORD type = GetFileType(h); 24 if (type == FILE_TYPE_UNKNOWN && GetLastError() != NO_ERROR) { 25 errno = EBADF; 26 return -1; 27 } 28 if (type != FILE_TYPE_PIPE) 29 BUG("unsupported file type: %lu", type); 30 if (!GetNamedPipeHandleState(h, &mode, NULL, NULL, NULL, NULL, 0)) { 31 errno = err_win_to_posix(GetLastError()); 32 return -1; 33 } 34 mode |= PIPE_NOWAIT; 35 if (!SetNamedPipeHandleState(h, &mode, NULL, NULL)) { 36 errno = err_win_to_posix(GetLastError()); 37 return -1; 38 } 39 return 0; 40 } 41 42 #else 43 44 int enable_pipe_nonblock(int fd UNUSED) 45 { 46 errno = ENOSYS; 47 return -1; 48 } 49 50 #endif