1 /*
2 * $Id: pstdio.c,v 1.1 2009-06-18 05:19:12 dhmunro Exp $
3 *
4 * implement virtual pstdio.h interface
5 */
6 /* Copyright (c) 2009, David H. Munro
7 * All rights reserved.
8 * This file is part of yorick (http://yorick.sourceforge.net).
9 * Read the accompanying LICENSE file for details.
10 */
11
12 #include "config.h"
13 #include "pstdio.h"
14
15 struct pv_file {
16 p_file_ops *ops;
17 };
18
19 unsigned long
p_fsize(p_file * file)20 p_fsize(p_file *file)
21 {
22 p_file_ops *ops = ((struct pv_file *)file)->ops;
23 return ops->v_fsize(file);
24 }
25
26 unsigned long
p_ftell(p_file * file)27 p_ftell(p_file *file)
28 {
29 p_file_ops *ops = ((struct pv_file *)file)->ops;
30 return ops->v_ftell(file);
31 }
32
33 int
p_fseek(p_file * file,unsigned long addr)34 p_fseek(p_file *file, unsigned long addr)
35 {
36 p_file_ops *ops = ((struct pv_file *)file)->ops;
37 return ops->v_fseek(file, addr);
38 }
39
40 char *
p_fgets(p_file * file,char * buf,int buflen)41 p_fgets(p_file *file, char *buf, int buflen)
42 {
43 p_file_ops *ops = ((struct pv_file *)file)->ops;
44 return ops->v_fgets(file, buf, buflen);
45 }
46
47 int
p_fputs(p_file * file,const char * buf)48 p_fputs(p_file *file, const char *buf)
49 {
50 p_file_ops *ops = ((struct pv_file *)file)->ops;
51 return ops->v_fputs(file, buf);
52 }
53
54 unsigned long
p_fread(p_file * file,void * buf,unsigned long nbytes)55 p_fread(p_file *file, void *buf, unsigned long nbytes)
56 {
57 p_file_ops *ops = ((struct pv_file *)file)->ops;
58 return ops->v_fread(file, buf, nbytes);
59 }
60
61 unsigned long
p_fwrite(p_file * file,const void * buf,unsigned long nbytes)62 p_fwrite(p_file *file, const void *buf, unsigned long nbytes)
63 {
64 p_file_ops *ops = ((struct pv_file *)file)->ops;
65 return ops->v_fwrite(file, buf, nbytes);
66 }
67
68 int
p_feof(p_file * file)69 p_feof(p_file *file)
70 {
71 if (file) {
72 p_file_ops *ops = ((struct pv_file *)file)->ops;
73 return ops->v_feof(file);
74 } else {
75 return 1;
76 }
77 }
78
79 int
p_ferror(p_file * file)80 p_ferror(p_file *file)
81 {
82 if (file) {
83 p_file_ops *ops = ((struct pv_file *)file)->ops;
84 return ops->v_ferror(file);
85 } else {
86 return 1;
87 }
88 }
89
90 int
p_fflush(p_file * file)91 p_fflush(p_file *file)
92 {
93 p_file_ops *ops = ((struct pv_file *)file)->ops;
94 return ops->v_fflush(file);
95 }
96
97 int
p_fclose(p_file * file)98 p_fclose(p_file *file)
99 {
100 if (file) {
101 p_file_ops *ops = ((struct pv_file *)file)->ops;
102 return ops->v_fclose(file);
103 } else {
104 return 0;
105 }
106 }
107