X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=f9b3d9d003abe88599f437bcc1aa46424bc99dc8;hp=83c6cd5b4d39c77f723aef5f67553b60d6653a31;hb=8978f426314b107c55a652e0151397fdab2f003e;hpb=97f53e18953fc2013c0b14f0261ac385e45b0284 diff --git a/fd.c b/fd.c index 83c6cd5b..f9b3d9d0 100644 --- a/fd.c +++ b/fd.c @@ -332,3 +332,47 @@ out: *fd_ptr = fd; return ret; } + +/** + * A wrapper for munmap(2). + * + * \param start The start address of the memory mapping. + * \param length The size of the mapping. + * + * \return Positive on success, \p -E_MUNMAP on errors. + * + * \sa munmap(2), mmap_full_file(). + */ +int para_munmap(void *start, size_t length) +{ + if (munmap(start, length) >= 0) + return 1; + PARA_ERROR_LOG("munmap (%p/%zu) failed: %s\n", start, length, + strerror(errno)); + return -E_MUNMAP; +} + +/** + * check a file descriptor for writability + * + * \param fd the file descriptor + * + * \return positive if fd is ready for writing, zero if it isn't, negative if + * an error occurred. + */ + +int write_ok(int fd) +{ + struct timeval tv = {0, 0}; + fd_set wfds; + int ret; +again: + FD_ZERO(&wfds); + FD_SET(fd, &wfds); + tv.tv_sec = 0; + tv.tv_usec = 0; + ret = select(fd + 1, NULL, &wfds, NULL, &tv); + if (ret < 0 && errno == EINTR) + goto again; + return ret; +}