X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=fd.c;h=ae5ef41379d94ea009e6647e62989c74e84cf2b8;hp=dc4fd59c93320929bd7e7f781a37f3e903a13c8f;hb=8f69a1302a52163c61142531c4a6944510c3ec12;hpb=8eb77a20423c3dcc44c4584a082e981391272cb2 diff --git a/fd.c b/fd.c index dc4fd59c..ae5ef413 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. */ @@ -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: @@ -573,20 +539,6 @@ close_cwd: return ret; } -/** - * A wrapper for fchdir(). - * - * \param fd An open file descriptor. - * - * \return Standard. - */ -static int para_fchdir(int fd) -{ - if (fchdir(fd) < 0) - return -ERRNO_TO_PARA_ERROR(errno); - return 1; -} - /** * A wrapper for mkdir(2). * @@ -657,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); @@ -749,7 +701,7 @@ int for_each_file_in_dir(const char *dirname, { DIR *dir; struct dirent *entry; - int cwd_fd, ret2, ret = para_opendir(dirname, &dir, &cwd_fd); + int cwd_fd, ret = para_opendir(dirname, &dir, &cwd_fd); if (ret < 0) return ret == -ERRNO_TO_PARA_ERROR(EACCES)? 1 : ret; @@ -785,9 +737,8 @@ int for_each_file_in_dir(const char *dirname, ret = 1; out: closedir(dir); - ret2 = para_fchdir(cwd_fd); - if (ret2 < 0 && ret >= 0) - ret = ret2; + if (fchdir(cwd_fd) < 0 && ret >= 0) + ret = -ERRNO_TO_PARA_ERROR(errno); close(cwd_fd); return ret; }