libopenraw
fileio.t.c
1/*
2 * Copyright (C) 2005 Hubert Figuiere
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19
20
21#include <stdio.h>
22#include <errno.h>
23#include "libopenraw/io.h"
24
25
26
27
28int main (int argc, char **argv)
29{
30 IOFileRef f;
31 int retval;
32 char buf[128];
33 (void)argc;
34 (void)argv;
35
36 f = raw_open(get_default_io_methods(), "/etc/hosts", O_RDONLY);
37
38 if (f == NULL) {
39 fprintf(stderr, "failed to open /etc/hosts\n");
40 return 1;
41 }
42 fprintf(stderr, "error code is %d\n", raw_get_error(f));
43
44 retval = raw_seek(f, 0, SEEK_SET);
45 if (retval == -1) {
46 fprintf(stderr, "failed to seek\n");
47 return 2;
48 }
49
50 fprintf(stderr, "position is %d\n", retval);
51
52 retval = raw_read(f, buf, 10);
53 if (retval == -1) {
54 fprintf(stderr, "failed to read with error %d\n", raw_get_error(f));
55 return 3;
56 }
57
58 fprintf(stderr, "read %d bytes\n", retval);
59
60 retval = raw_close(f);
61 if (retval == -1) {
62 fprintf(stderr, "failed to close\n");
63 return 4;
64 }
65
66 return 0;
67}
68
69
70