root / tags / 1.0.8 / xapian-core / backends / flint / flint_io.h
| Revision 8160, 1.9 kB (checked in by olly, 21 months ago) |
|---|
| Line | |
|---|---|
| 1 | /** @file flint_io.h |
| 2 | * @brief Wrappers for low-level POSIX I/O routines. |
| 3 | */ |
| 4 | /* Copyright (C) 2006,2007 Olly Betts |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #ifndef XAPIAN_INCLUDED_FLINT_IO_H |
| 22 | #define XAPIAN_INCLUDED_FLINT_IO_H |
| 23 | |
| 24 | #include <sys/types.h> |
| 25 | #include "safefcntl.h" |
| 26 | #include "safeunistd.h" |
| 27 | |
| 28 | /** Ensure all data previously written to file descriptor fd has been written to |
| 29 | * disk. |
| 30 | * |
| 31 | * Returns false if this could not be done. |
| 32 | */ |
| 33 | inline bool flint_io_sync(int fd) |
| 34 | { |
| 35 | // If we have it, prefer fdatasync() as it avoids updating the access time |
| 36 | // so is probably a little more efficient. |
| 37 | #if defined HAVE_FDATASYNC |
| 38 | return fdatasync(fd) == 0; |
| 39 | #elif defined HAVE_FSYNC |
| 40 | return fsync(fd) == 0; |
| 41 | #elif defined __WIN32__ |
| 42 | return _commit(fd) == 0; |
| 43 | #else |
| 44 | # error Cannot implement flint_io_sync() without fdatasync(), fsync(), or _commit() |
| 45 | #endif |
| 46 | } |
| 47 | |
| 48 | /** Read n bytes (or until EOF) into block pointed to by p from file descriptor |
| 49 | * fd. |
| 50 | * |
| 51 | * If less than min bytes are read, throw an exception. |
| 52 | * |
| 53 | * Returns the number of bytes actually read. |
| 54 | */ |
| 55 | size_t flint_io_read(int fd, char * p, size_t n, size_t min); |
| 56 | |
| 57 | /** Write n bytes from block pointed to by p to file descriptor fd. */ |
| 58 | void flint_io_write(int fd, const char * p, size_t n); |
| 59 | |
| 60 | #endif |
Note: See TracBrowser
for help on using the browser.
