Skip to content
Permalink
Browse files
Add light version of the Lua I/O library
  • Loading branch information
Sebastien Bourdeauducq committed Jun 3, 2012
1 parent a8b967b commit 07ab4d2bd092d0dc5fc6f05f740ee33ea6af84d8
Showing with 571 additions and 6 deletions.
  1. +36 −3 libglue/file.c
  2. +1 −1 liblfs/Makefile
  3. +1 −0 liblfs/include/lfs.h
  4. +528 −0 liblfs/liolightlib.c
  5. +2 −1 libyaffs2/Makefile
  6. +1 −1 luainit.c
  7. +2 −0 main.c
@@ -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)
@@ -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)
@@ -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,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

@@ -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 */
Loading

0 comments on commit 07ab4d2

Please sign in to comment.