Skip to content

Commit 07ab4d2

Browse files
author
Sebastien Bourdeauducq
committedJun 3, 2012
Add light version of the Lua I/O library
1 parent a8b967b commit 07ab4d2

File tree

7 files changed

+571
-6
lines changed

7 files changed

+571
-6
lines changed
 

‎libglue/file.c

+36-3
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ int fflush(FILE *stream)
226226

227227
char *fgets(char *s, int size, FILE *stream)
228228
{
229-
return NULL;
229+
return NULL; /* TODO */
230230
}
231231

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

301301
int ferror(FILE *stream)
302302
{
303-
return 0; /* TODO */
303+
return 0;
304304
}
305305

306306
int feof(FILE *stream)
307307
{
308-
return 0; /* TODO */
308+
int fd;
309+
loff_t position;
310+
loff_t end;
311+
312+
if(is_std_stream(stream))
313+
return 1;
314+
315+
fd = *(int *)stream;
316+
position = yaffs_lseek(fd, 0, SEEK_CUR);
317+
end = yaffs_lseek(fd, 0, SEEK_END);
318+
yaffs_lseek(fd, position, SEEK_SET);
319+
return position == end;
309320
}
310321

311322
FILE *freopen(const char *path, const char *mode, FILE *stream)
@@ -325,3 +336,25 @@ FILE *freopen(const char *path, const char *mode, FILE *stream)
325336
free(newfd);
326337
return stream;
327338
}
339+
340+
int fseek(FILE *stream, long offset, int whence)
341+
{
342+
int fd;
343+
344+
if(is_std_stream(stream))
345+
return -1;
346+
fd = *(int *)stream;
347+
if(yaffs_lseek(fd, offset, whence) < 0)
348+
return -1;
349+
return 0;
350+
}
351+
352+
long ftell(FILE *stream)
353+
{
354+
int fd;
355+
356+
if(is_std_stream(stream))
357+
return -1;
358+
fd = *(int *)stream;
359+
return yaffs_lseek(fd, 0, SEEK_CUR);
360+
}

‎liblfs/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ MISPDIR=..
22
include $(MISPDIR)/common.mak
33

44
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
5-
OBJECTS=lfs.o
5+
OBJECTS=lfs.o liolightlib.o
66

77
all: liblfs.a
88

‎liblfs/include/lfs.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef __LFS_H
1010
#define __LFS_H
1111

12+
int luaopen_iolight(lua_State *L);
1213
int luaopen_lfs(lua_State *L);
1314

1415
#endif /* __LFS_H */

‎liblfs/liolightlib.c

+528
Large diffs are not rendered by default.

‎libyaffs2/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
MISPDIR=..
22
include $(MISPDIR)/common.mak
33

4-
CFLAGS+=-include $(M2DIR)/software/include/base/errno.h -include $(YAFFSDIR)/direct/yportenv.h -I$(YAFFSDIR)/direct -I$(YAFFSDIR)
4+
CFLAGS+=-include $(M2DIR)/software/include/base/errno.h -include $(M2DIR)/software/include/base/stdio.h
5+
CFLAGS+=-include $(YAFFSDIR)/direct/yportenv.h -I$(YAFFSDIR)/direct -I$(YAFFSDIR)
56
CFLAGS+=-DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_DEFINES_TYPES -DCONFIG_YAFFS_PROVIDE_DEFS -DCONFIG_YAFFSFS_PROVIDE_VALUES
67

78
OBJECTS=yaffs_ecc.o yaffs_guts.o yaffs_packedtags1.o yaffs_tagscompat.o yaffs_packedtags2.o yaffs_nand.o yaffs_checkptrw.o yaffs_nameval.o yaffs_attribs.o yaffs_allocator.o yaffs_bitmap.o yaffs_yaffs1.o yaffs_yaffs2.o yaffs_verify.o yaffs_summary.o

‎luainit.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ static const luaL_Reg loadedlibs[] = {
1515
{LUA_LOADLIBNAME, luaopen_package},
1616
{LUA_COLIBNAME, luaopen_coroutine},
1717
{LUA_TABLIBNAME, luaopen_table},
18-
// TODO {LUA_IOLIBNAME, luaopen_io},
18+
{LUA_IOLIBNAME, luaopen_iolight},
1919
{LUA_STRLIBNAME, luaopen_string},
2020
{LUA_BITLIBNAME, luaopen_bit32},
2121
{LUA_MATHLIBNAME, luaopen_math},

‎main.c

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ static void test_lua(void)
1515
{
1616
lua_State *L;
1717

18+
// /patchpool/nil - Cid and Lucy.fnp
19+
1820
L = luaL_newstate();
1921
luaL_openlibs(L);
2022
luaL_dostring(L, "for i=10,1,-1 do print(i) end\n");

0 commit comments

Comments
 (0)
Please sign in to comment.