From 67d21468bfafc489194ee2b88180baefd2b83a2a Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Tue, 20 Feb 2024 20:31:50 -0700 Subject: [PATCH] loader: For the mini-stdio we have for lua, #define them to something else To make it easier to port lua and some of the lua modules, we have a series of routines to implement the stdio routines, even though we don't normally implement them in the boot loader. Add a comment to this effect. Also, some tools, like sanitizers and static analysis tools, make unwarranted assumptions about these, so #define them to a different name so they stop. Sponsored by: Netflix (cherry picked from commit 9a5aaa97cbae024f90bb626f78c3dbde28653c58) --- stand/liblua/lstd.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/stand/liblua/lstd.h b/stand/liblua/lstd.h index 05a8b8843d9..ce3aef4bc5f 100644 --- a/stand/liblua/lstd.h +++ b/stand/liblua/lstd.h @@ -34,6 +34,15 @@ #include #include +/* + * Mini stdio FILE and DIR routines. These are the minimal routines needed by + * the lfs module and lua's base code. We define them minimally here so we don't + * have to modify lua on every import. Further, since they aren't completely + * standard, we #define them to other names so they don't conflict with other + * tooling that makes assumptions about these routines that might not be, in + * fact, correct. + */ + typedef struct FILE { int fd; @@ -46,6 +55,18 @@ typedef struct DIR int fd; } DIR; +#define fopen lua_loader_fopen +#define freopen lua_loader_freopen +#define fread lua_loader_fread +#define fwrite lua_loader_fwrite +#define fclose lua_loader_fclose +#define ferror lua_loader_ferror +#define feof lua_loader_feof +#define getc lua_loader_getc +#define opendir lua_loader_opendir +#define fdopendir lua_loader_fdopendir +#define closedir lua_loader_closedir + FILE *fopen(const char *filename, const char *mode); FILE *freopen( const char *filename, const char *mode, FILE *stream); size_t fread(void *ptr, size_t size, size_t count, FILE *stream);