fileio.t.c

00001 /*
00002  * Copyright (C) 2005 Hubert Figuiere
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00017  * 02111-1307, USA.
00018  */
00019 
00020 
00021 
00022 #include <stdio.h>
00023 #include <errno.h>
00024 #include "libopenraw/io.h"
00025 
00026 
00027 
00028 
00029 int main (int argc, char **argv)
00030 {
00031     IOFileRef f;
00032     int retval;
00033     char buf[128];
00034 
00035     f = raw_open(get_default_io_methods(), "/etc/hosts", O_RDONLY);
00036 
00037     if (f == NULL) {
00038         fprintf(stderr, "failed to open /etc/hosts\n");
00039         return 1;
00040     }
00041     fprintf(stderr, "error code is %d\n", raw_get_error(f));
00042 
00043     retval = raw_seek(f, 0, SEEK_SET);
00044     if (retval == -1) {
00045         fprintf(stderr, "failed to seek\n");
00046         return 2;
00047     }
00048 
00049     fprintf(stderr, "position is %d\n", retval);
00050 
00051     retval = raw_read(f, buf, 10);
00052     if (retval == -1) {
00053         fprintf(stderr, "failed to read with error %d\n", raw_get_error(f));
00054         return 3;
00055     }
00056 
00057     fprintf(stderr, "read %d bytes\n", retval);
00058 
00059     retval = raw_close(f);
00060     if (retval == -1) {
00061         fprintf(stderr, "failed to close\n");
00062         return 4;
00063     }
00064 
00065     return 0;
00066 }
00067 
00068 
00069 

Generated on Sat Jan 27 11:36:13 2007 for libopenraw by  doxygen 1.4.7