aboutsummaryrefslogtreecommitdiffstats
path: root/src/gfile/gfile_stdio.c
blob: 0528547dafa0010fc5d9e8d14beec9fe6811259d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
 * This file is subject to the terms of the GFX License. If a copy of
 * the license was not distributed with this file, you can obtain one at:
 *
 *              http://ugfx.org/license.html
 */

/********************************************************
 * Stdio Emulation Routines
 ********************************************************/

#include "gfx.h"

#if GFX_USE_GFILE && GFILE_NEED_STDIO && !defined(GFILE_NEED_STDIO_MUST_BE_OFF)

#include "gfile_fs.h"

size_t gstdioRead(void * ptr, size_t size, size_t count, GFILE *f) {
	return gfileRead(f, ptr, size*count)/size;
}

size_t gstdioWrite(const void * ptr, size_t size, size_t count, GFILE *f) {
	return gfileWrite(f, ptr, size*count)/size;
}

int gstdioSeek(GFILE *f, size_t offset, int origin) {
	switch(origin) {
	case SEEK_SET:
		break;
	case SEEK_CUR:
		offset += f->pos;
		break;
	case SEEK_END:
		offset += gfileGetSize(f);
		break;
	default:
		return -1;
	}
	return gfileSetPos(f, offset) ? 0 : -1;
}

int gstdioGetpos(GFILE *f, long int *pos) {
	if (!(f->flags & GFILEFLG_OPEN))
		return -1;
	*pos = f->pos;
	return 0;
}

#endif //GFX_USE_GFILE && GFILE_NEED_STDIO