]> pd.if.org Git - pdclib/blob - platform/gandr/functions/stdio/_PDCLIB_fileops.c
PDCLib includes with quotes, not <>.
[pdclib] / platform / gandr / functions / stdio / _PDCLIB_fileops.c
1 /* _PDCLIB_fileops
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #ifndef REGTEST
8 #include <stdio.h>
9 #include <stdint.h>
10 #include "_PDCLIB_glue.h"
11 #include <errno.h>
12 #include <gd_bal.h>
13
14 static bool readf( _PDCLIB_fd_t fd, void * buf, size_t length,
15                    size_t * numBytesRead )
16 {
17     int rv = gd_read(fd.pointer, buf, length, numBytesRead );
18
19     return rv >= 0;
20 }
21
22 static bool writef( _PDCLIB_fd_t fd, const void * buf, size_t length,
23                    size_t * numBytesWritten )
24 {
25     int rv = gd_write(fd.pointer, buf, length, numBytesWritten );
26
27     return rv >= 0;
28 }
29
30 static bool seekf( _PDCLIB_fd_t fd, int_fast64_t offset, int whence,
31     int_fast64_t* newPos )
32 {
33     int rv = gd_seek( fd.pointer, offset, whence, newPos );
34
35     return rv >= 0;
36 }
37
38 static void closef( _PDCLIB_fd_t self )
39 {
40     gd_close( self.pointer );
41 }
42
43 const _PDCLIB_fileops_t _PDCLIB_fileops = {
44     .read  = readf,
45     .write = writef,
46     .seek  = seekf,
47     .close = closef,
48 };
49
50 #endif
51
52 #ifdef TEST
53 #include "_PDCLIB_test.h"
54
55 int main( void )
56 {
57     // Tested by stdio test cases
58     return TEST_RESULTS;
59 }
60
61 #endif