backends/flint/flint_io.cc

Go to the documentation of this file.
00001 
00004 /* Copyright (C) 2006,2007 Olly Betts
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include "safeerrno.h"
00024 #include "safeunistd.h"
00025 
00026 #include <xapian/error.h>
00027 
00028 #include "flint_io.h"
00029 
00030 size_t flint_io_read(int fd, char * p, size_t n, size_t min)
00031 {
00032     size_t total = 0;
00033     while (n) {
00034         ssize_t c = read(fd, p, n);
00035         if (c <= 0) {
00036             if (c == 0) {
00037                 if (total >= min) break;
00038                 throw Xapian::DatabaseError("Couldn't read enough (EOF)");
00039             }
00040             if (errno == EINTR) continue;
00041             throw Xapian::DatabaseError("Error reading from file", errno);
00042         }
00043         p += c;
00044         total += c;
00045         n -= c;
00046     }
00047     return total;
00048 }
00049 
00051 void flint_io_write(int fd, const char * p, size_t n)
00052 {
00053     while (n) {
00054         int c = write(fd, p, n);
00055         if (c < 0) {
00056             if (errno == EINTR) continue;
00057             throw Xapian::DatabaseError("Error writing to file", errno);
00058         }
00059         p += c;
00060         n -= c;
00061     }
00062 }

Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.