libopenraw
|
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00017 */ 00018 00019 00020 00021 #include <stdio.h> 00022 #include <errno.h> 00023 #include "libopenraw/io.h" 00024 00025 00026 00027 00028 int main (int argc, char **argv) 00029 { 00030 IOFileRef f; 00031 int retval; 00032 char buf[128]; 00033 (void)argc; 00034 (void)argv; 00035 00036 f = raw_open(get_default_io_methods(), "/etc/hosts", O_RDONLY); 00037 00038 if (f == NULL) { 00039 fprintf(stderr, "failed to open /etc/hosts\n"); 00040 return 1; 00041 } 00042 fprintf(stderr, "error code is %d\n", raw_get_error(f)); 00043 00044 retval = raw_seek(f, 0, SEEK_SET); 00045 if (retval == -1) { 00046 fprintf(stderr, "failed to seek\n"); 00047 return 2; 00048 } 00049 00050 fprintf(stderr, "position is %d\n", retval); 00051 00052 retval = raw_read(f, buf, 10); 00053 if (retval == -1) { 00054 fprintf(stderr, "failed to read with error %d\n", raw_get_error(f)); 00055 return 3; 00056 } 00057 00058 fprintf(stderr, "read %d bytes\n", retval); 00059 00060 retval = raw_close(f); 00061 if (retval == -1) { 00062 fprintf(stderr, "failed to close\n"); 00063 return 4; 00064 } 00065 00066 return 0; 00067 } 00068 00069 00070