X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=33891d2e6c9f1c3568428b1df93b4b92e295ef61;hp=49736448a7fe3013a69596525ea4d815358bd226;hb=9d232e636d79a2321e280fe3eee6839c8f45c36f;hpb=177ea8ea46918a925c0d2d8a07e7fbe9f478a40c diff --git a/fd.c b/fd.c index 49736448..33891d2e 100644 --- a/fd.c +++ b/fd.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2006 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2006 Andre Noll , see file COPYING. */ /** \file fd.c Helper functions for file descriptor handling. */ @@ -183,15 +179,15 @@ __printf_2_3 int write_va_buffer(int fd, const char *fmt, ...) * \param rfds An optional fd set pointer. * \param num_bytes Result pointer. Contains the number of bytes read from \a fd. * - * If \a rfds is not \p NULL and the (non-blocking) file descriptor \a fd is - * not set in \a rfds, this function returns early without doing anything. - * Otherwise The function tries to read up to \a sz bytes from \a fd, where \a - * sz is the sum of the lengths of all vectors in \a iov. As for xwrite(), - * \p EAGAIN is not considered an error condition. However, \p EOF is. + * If rfds is not NULL and the (non-blocking) file descriptor fd is not set in + * rfds, this function returns early without doing anything. Otherwise it tries + * to read up to sz bytes from fd, where sz is the sum of the lengths of all + * vectors in iov. Like \ref xwrite(), EAGAIN and EINTR are not considered + * error conditions. However, EOF is. * * \return Zero or a negative error code. If the underlying call to readv(2) * returned zero (indicating an end of file condition) or failed for some - * reason other than \p EAGAIN, a negative error code is returned. + * reason other than EAGAIN or EINTR, a negative error code is returned. * * In any case, \a num_bytes contains the number of bytes that have been * successfully read from \a fd (zero if the first readv() call failed with @@ -230,7 +226,7 @@ int readv_nonblock(int fd, struct iovec *iov, int iovcnt, fd_set *rfds, if (ret == 0) return -E_EOF; if (ret < 0) { - if (errno == EAGAIN) + if (errno == EAGAIN || errno == EINTR) return 0; return -ERRNO_TO_PARA_ERROR(errno); } @@ -320,9 +316,9 @@ out: * * \param fn The file name. * - * \return Non-zero iff file exists. + * \return True iff file exists. */ -int file_exists(const char *fn) +bool file_exists(const char *fn) { struct stat statbuf; @@ -423,34 +419,6 @@ void para_fd_set(int fd, fd_set *fds, int *max_fileno) *max_fileno = PARA_MAX(*max_fileno, fd); } -/** - * Paraslash's wrapper for fgets(3). - * - * \param line Pointer to the buffer to store the line. - * \param size The size of the buffer given by \a line. - * \param f The stream to read from. - * - * \return Unlike the standard fgets() function, an integer value - * is returned. On success, this function returns 1. On errors, -E_FGETS - * is returned. A zero return value indicates an end of file condition. - */ -__must_check int para_fgets(char *line, int size, FILE *f) -{ -again: - if (fgets(line, size, f)) - return 1; - if (feof(f)) - return 0; - if (!ferror(f)) - return -E_FGETS; - if (errno != EINTR) { - PARA_ERROR_LOG("%s\n", strerror(errno)); - return -E_FGETS; - } - clearerr(f); - goto again; -} - /** * Paraslash's wrapper for mmap. * @@ -459,22 +427,20 @@ again: * PROT_EXEC PROT_READ PROT_WRITE. * \param flags Exactly one of MAP_SHARED and MAP_PRIVATE. * \param fd The file to mmap from. - * \param offset Mmap start. * \param map Result pointer. * * \return Standard. * * \sa mmap(2). */ -int para_mmap(size_t length, int prot, int flags, int fd, off_t offset, - void *map) +int para_mmap(size_t length, int prot, int flags, int fd, void *map) { void **m = map; errno = EINVAL; if (!length) goto err; - *m = mmap(NULL, length, prot, flags, fd, offset); + *m = mmap(NULL, length, prot, flags, fd, (off_t)0); if (*m != MAP_FAILED) return 1; err: @@ -643,7 +609,7 @@ int mmap_full_file(const char *path, int open_mode, void **map, if (S_ISDIR(file_status.st_mode)) goto out; - ret = para_mmap(*size, mmap_prot, mmap_flags, fd, 0, map); + ret = para_mmap(*size, mmap_prot, mmap_flags, fd, map); out: if (ret < 0 || !fd_ptr) close(fd);