µGFX  2.9
version 2.9
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.io/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, gFileSize *pos) {
43  if (!(f->flags & GFILEFLG_OPEN))
44  return (gFileSize)-1;
45  *pos = f->pos;
46  return 0;
47 }
48 
49 #endif //GFX_USE_GFILE && GFILE_NEED_STDIO
GFILE file system header.
gBool gfileSetPos(GFILE *f, gFileSize pos)
Set the position of the read/write cursor.
gMemSize gfileRead(GFILE *f, void *buf, gMemSize len)
Read from file.
struct GFILE GFILE
A file pointer.
Definition: gfile.h:34
gMemSize gfileWrite(GFILE *f, const void *buf, gMemSize len)
Write to file.
gFileSize gfileGetSize(GFILE *f)
Get the size of file.