version 2.8
gfile_stdio.c
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.org/license.html
6  */
7 
8 /********************************************************
9  * Stdio Emulation Routines
10  ********************************************************/
11 
12 #include "../../gfx.h"
13 
14 #if GFX_USE_GFILE && GFILE_NEED_STDIO && !defined(GFILE_NEED_STDIO_MUST_BE_OFF)
15 
16 #include "gfile_fs.h"
17 
18 size_t gstdioRead(void * ptr, size_t size, size_t count, GFILE *f) {
19  return gfileRead(f, ptr, size*count)/size;
20 }
21 
22 size_t gstdioWrite(const void * ptr, size_t size, size_t count, GFILE *f) {
23  return gfileWrite(f, ptr, size*count)/size;
24 }
25 
26 int gstdioSeek(GFILE *f, size_t offset, int origin) {
27  switch(origin) {
28  case SEEK_SET:
29  break;
30  case SEEK_CUR:
31  offset += f->pos;
32  break;
33  case SEEK_END:
34  offset += gfileGetSize(f);
35  break;
36  default:
37  return -1;
38  }
39  return gfileSetPos(f, offset) ? 0 : -1;
40 }
41 
42 int gstdioGetpos(GFILE *f, long int *pos) {
43  if (!(f->flags & GFILEFLG_OPEN))
44  return -1;
45  *pos = f->pos;
46  return 0;
47 }
48 
49 #endif //GFX_USE_GFILE && GFILE_NEED_STDIO
size_t gfileWrite(GFILE *f, const void *buf, size_t len)
Write to file.
struct GFILE GFILE
A file pointer.
Definition: gfile.h:34
long int gfileGetSize(GFILE *f)
Get the size of file.
size_t gfileRead(GFILE *f, void *buf, size_t len)
Read from file.
bool_t gfileSetPos(GFILE *f, long int pos)
Set the position of the read/write cursor.
GFILE file system header.