/src/common/fd.h
C++ Header | 129 lines | 21 code | 20 blank | 88 comment | 0 complexity | 62bf0ec28e2709be223f3d8041d012f8 MD5 | raw file
1/***************************************************************************** 2 * $Id$ 3 ***************************************************************************** 4 * This file is part of the Munge Uid 'N' Gid Emporium (MUNGE). 5 * For details, see <http://www.llnl.gov/linux/munge/>. 6 * UCRL-CODE-2003-???. 7 * 8 * Copyright (C) 2001-2003 The Regents of the University of California. 9 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER). 10 * Written by Chris Dunlap <cdunlap@llnl.gov>. 11 * 12 * This is free software; you can redistribute it and/or modify it 13 * under the terms of the GNU General Public License as published by 14 * the Free Software Foundation; either version 2 of the License, or 15 * (at your option) any later version. 16 * 17 * This is distributed in the hope that it will be useful, but WITHOUT 18 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 19 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 20 * for more details. 21 * 22 * You should have received a copy of the GNU General Public License; 23 * if not, write to the Free Software Foundation, Inc., 59 Temple Place, 24 * Suite 330, Boston, MA 02111-1307 USA. 25 *****************************************************************************/ 26 27 28#ifndef FD_H 29#define FD_H 30 31 32#if HAVE_CONFIG_H 33# include "config.h" 34#endif /* HAVE_CONFIG_H */ 35 36#include <sys/types.h> 37#include <unistd.h> 38 39 40int fd_set_close_on_exec (int fd); 41/* 42 * Sets the file descriptor [fd] to be closed on exec(). 43 * Returns 0 on success, or -1 on error. 44 */ 45 46int fd_set_nonblocking (int fd); 47/* 48 * Sets the file descriptor [fd] for non-blocking I/O. 49 * Returns 0 on success, or -1 on error. 50 */ 51 52int fd_get_read_lock (int fd); 53/* 54 * Obtain a read lock on the file specified by [fd]. 55 * Returns 0 on success, or -1 if prevented from obtaining the lock. 56 */ 57 58int fd_get_readw_lock (int fd); 59/* 60 * Obtain a read lock on the file specified by [fd], 61 * blocking until one becomes available. 62 * Returns 0 on success, or -1 on error. 63 */ 64 65int fd_get_write_lock (int fd); 66/* 67 * Obtain a write lock on the file specified by [fd]. 68 * Returns 0 on success, or -1 if prevented from obtaining the lock. 69 */ 70 71int fd_get_writew_lock (int fd); 72/* 73 * Obtain a write lock on the file specified by [fd], 74 * blocking until one becomes available. 75 * Returns 0 on success, or -1 on error. 76 */ 77 78int fd_release_lock (int fd); 79/* 80 * Release a lock held on the file specified by [fd]. 81 * Returns 0 on success, or -1 on error. 82 */ 83 84pid_t fd_is_read_lock_blocked (int fd); 85/* 86 * Checks to see if a lock exists on [fd] that would block a request for a 87 * read-lock (ie, if a write-lock is already being held on the file). 88 * Returns the pid of the process holding the lock, 0 if no lock exists, 89 * or -1 on error. 90 */ 91 92pid_t fd_is_write_lock_blocked (int fd); 93/* 94 * Checks to see if a lock exists on [fd] that would block a request for a 95 * write-lock (ie, if any lock is already being held on the file). 96 * Returns the pid of the process holding the lock, 0 if no lock exists, 97 * or -1 on error. 98 */ 99 100ssize_t fd_read_n (int fd, void *buf, size_t n); 101/* 102 * Reads up to [n] bytes from [fd] into [buf]. 103 * Returns the number of bytes read, 0 on EOF, or -1 on error. 104 */ 105 106ssize_t fd_write_n (int fd, void *buf, size_t n); 107/* 108 * Writes [n] bytes from [buf] to [fd]. 109 * Returns the number of bytes written, or -1 on error. 110 */ 111 112ssize_t fd_read_line (int fd, void *buf, size_t maxlen); 113/* 114 * Reads at most [maxlen-1] bytes up to a newline from [fd] into [buf]. 115 * The [buf] is guaranteed to be NUL-terminated and will contain the 116 * newline if it is encountered within [maxlen-1] bytes. 117 * Returns the number of bytes read, 0 on EOF, or -1 on error. 118 */ 119 120ssize_t fd_null_read_n (int fd, void *buf, size_t maxlen); 121/* 122 * Reads up to [n] bytes from [fd] into [buf]. 123 * Returns the number of bytes read, 0 on EOF, or -1 on error. 124 * Differs from fd_read_n() in that it checks for the presence 125 * a null along the partial read and breaks out if it does. 126 * Added by Mike Haskell <mhaskell@llnl.gov> 127 */ 128 129#endif /* !FD_H */