Skip to content

Commit

Permalink
Add light version of the Lua I/O library
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Bourdeauducq committed Jun 3, 2012
1 parent a8b967b commit 07ab4d2
Show file tree
Hide file tree
Showing 7 changed files with 571 additions and 6 deletions.
39 changes: 36 additions & 3 deletions libglue/file.c
Expand Up @@ -226,7 +226,7 @@ int fflush(FILE *stream)

char *fgets(char *s, int size, FILE *stream)
{
return NULL;
return NULL; /* TODO */
}

size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
Expand Down Expand Up @@ -300,12 +300,23 @@ int fputc(int c, FILE *stream)

int ferror(FILE *stream)
{
return 0; /* TODO */
return 0;
}

int feof(FILE *stream)
{
return 0; /* TODO */
int fd;
loff_t position;
loff_t end;

if(is_std_stream(stream))
return 1;

fd = *(int *)stream;
position = yaffs_lseek(fd, 0, SEEK_CUR);
end = yaffs_lseek(fd, 0, SEEK_END);
yaffs_lseek(fd, position, SEEK_SET);
return position == end;
}

FILE *freopen(const char *path, const char *mode, FILE *stream)
Expand All @@ -325,3 +336,25 @@ FILE *freopen(const char *path, const char *mode, FILE *stream)
free(newfd);
return stream;
}

int fseek(FILE *stream, long offset, int whence)
{
int fd;

if(is_std_stream(stream))
return -1;
fd = *(int *)stream;
if(yaffs_lseek(fd, offset, whence) < 0)
return -1;
return 0;
}

long ftell(FILE *stream)
{
int fd;

if(is_std_stream(stream))
return -1;
fd = *(int *)stream;
return yaffs_lseek(fd, 0, SEEK_CUR);
}
2 changes: 1 addition & 1 deletion liblfs/Makefile
Expand Up @@ -2,7 +2,7 @@ MISPDIR=..
include $(MISPDIR)/common.mak

CFLAGS+=-I$(MISPDIR)/liblfs/include -I$(YAFFSDIR)/direct -I$(YAFFSDIR) -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_DEFINES_TYPES -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES -I$(LUADIR)/src
OBJECTS=lfs.o
OBJECTS=lfs.o liolightlib.o

all: liblfs.a

Expand Down
1 change: 1 addition & 0 deletions liblfs/include/lfs.h
Expand Up @@ -9,6 +9,7 @@
#ifndef __LFS_H
#define __LFS_H

int luaopen_iolight(lua_State *L);
int luaopen_lfs(lua_State *L);

#endif /* __LFS_H */

0 comments on commit 07ab4d2

Please sign in to comment.