git: 67d21468bfaf - stable/14 - loader: For the mini-stdio we have for lua, #define them to something else

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 16 Apr 2024 20:13:03 UTC
The branch stable/14 has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=67d21468bfafc489194ee2b88180baefd2b83a2a

commit 67d21468bfafc489194ee2b88180baefd2b83a2a
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-02-21 03:31:50 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2024-04-16 19:54:25 +0000

    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 05a8b8843d9c..ce3aef4bc5fc 100644
--- a/stand/liblua/lstd.h
+++ b/stand/liblua/lstd.h
@@ -34,6 +34,15 @@
 #include <string.h>
 #include <machine/stdarg.h>
 
+/*
+ * 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);