root / tags / 1.0.8 / xapian-core / backends / flint / flint_io.cc

Revision 8160, 1.7 kB (checked in by olly, 21 months ago)

* ./: svn:eol-style not svn:eolstyle.

  • Property svn:eol-style set to native
Line 
1/** @file flint_io.cc
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#include <config.h>
22
23#include "safeerrno.h"
24#include "safeunistd.h"
25
26#include <xapian/error.h>
27
28#include "flint_io.h"
29
30size_t flint_io_read(int fd, char * p, size_t n, size_t min)
31{
32    size_t total = 0;
33    while (n) {
34        ssize_t c = read(fd, p, n);
35        if (c <= 0) {
36            if (c == 0) {
37                if (total >= min) break;
38                throw Xapian::DatabaseError("Couldn't read enough (EOF)");
39            }
40            if (errno == EINTR) continue;
41            throw Xapian::DatabaseError("Error reading from file", errno);
42        }
43        p += c;
44        total += c;
45        n -= c;
46    }
47    return total;
48}
49
50/** Write n bytes from block pointed to by p to file descriptor fd. */
51void flint_io_write(int fd, const char * p, size_t n)
52{
53    while (n) {
54        int c = write(fd, p, n);
55        if (c < 0) {
56            if (errno == EINTR) continue;
57            throw Xapian::DatabaseError("Error writing to file", errno);
58        }
59        p += c;
60        n -= c;
61    }
62}
Note: See TracBrowser for help on using the browser.