mescc: Mes C Library: Use mes_open to avoid open trickery.
* include/mes/lib.h (mes_open): Declare. * lib/libmes.c[WITH_GLIBC]: Remove open undefine. (mes_open)[!WITH_GLIBC]: New function. * src/mes.c (open_boot): Use mes_open. * src/posix.c (open_input_file): Likewise. (open_output_file): Likewise.
This commit is contained in:
parent
a5ae6569fb
commit
8bda737ee4
|
@ -23,11 +23,6 @@
|
|||
|
||||
#include <mes/lib-mini.h>
|
||||
|
||||
#if WITH_GLIBC
|
||||
int mes_open (char const *file_name, int flags, ...);
|
||||
#define open mes_open
|
||||
#endif
|
||||
|
||||
int __mes_debug ();
|
||||
void __ungetc_init ();
|
||||
void __ungetc_clear (int filedes);
|
||||
|
@ -50,8 +45,9 @@ int _fdungetc_p (int fd);
|
|||
int isdigit (int c);
|
||||
int isspace (int c);
|
||||
int isxdigit (int c);
|
||||
int _open3 (char const *file_name, int flags, int mask);
|
||||
int mes_open (char const *file_name, int flags, int mask);
|
||||
int _open2 (char const *file_name, int flags);
|
||||
int _open3 (char const *file_name, int flags, int mask);
|
||||
int oputc (int c);
|
||||
int oputs (char const* s);
|
||||
char *search_path (char const *file_name);
|
||||
|
|
18
lib/libmes.c
18
lib/libmes.c
|
@ -42,7 +42,6 @@
|
|||
#include <mes/fdungetc.c>
|
||||
|
||||
#if WITH_GLIBC
|
||||
#undef open
|
||||
#include <fcntl.h>
|
||||
#include <stdarg.h>
|
||||
// The Mes C Library defines and initializes these in crt1
|
||||
|
@ -51,22 +50,27 @@ int __stdout = STDOUT;
|
|||
int __stderr = STDERR;
|
||||
|
||||
int
|
||||
mes_open (char const *file_name, int flags, ...)
|
||||
mes_open (char const *file_name, int flags, int mask)
|
||||
{
|
||||
va_list ap;
|
||||
va_start (ap, flags);
|
||||
int mask = va_arg (ap, int);
|
||||
__ungetc_init ();
|
||||
int r = open (file_name, flags, mask);
|
||||
if (r > 2)
|
||||
__ungetc_buf[r] = -1;
|
||||
va_end (ap);
|
||||
return r;
|
||||
}
|
||||
|
||||
#include <mes/eputs.c>
|
||||
#include <mes/oputs.c>
|
||||
#endif // WITH_GLIBC
|
||||
|
||||
#else // !WITH_GLIBC
|
||||
|
||||
int
|
||||
mes_open (char const *file_name, int flags, int mask)
|
||||
{
|
||||
return _open3 (file_name, flags, mask);
|
||||
}
|
||||
|
||||
#endif // !WITH_GLIBC
|
||||
|
||||
#include <mes/eputc.c>
|
||||
#include <mes/oputc.c>
|
||||
|
|
|
@ -2192,7 +2192,7 @@ open_boot (char *prefix, char const *boot, char const *location)
|
|||
eputs (prefix);
|
||||
eputs ("\n");
|
||||
}
|
||||
int fd = open (prefix, O_RDONLY);
|
||||
int fd = mes_open (prefix, O_RDONLY, 0);
|
||||
if (g_debug && fd > 0)
|
||||
{
|
||||
eputs ("mes: read boot-0: ");
|
||||
|
|
|
@ -186,7 +186,7 @@ current_input_port ()
|
|||
SCM
|
||||
open_input_file (SCM file_name)
|
||||
{
|
||||
return MAKE_NUMBER (open (CSTRING (file_name), O_RDONLY));
|
||||
return MAKE_NUMBER (mes_open (CSTRING (file_name), O_RDONLY, 0));
|
||||
}
|
||||
|
||||
SCM
|
||||
|
@ -228,7 +228,7 @@ open_output_file (SCM x) ///((arity . n))
|
|||
int mode = S_IRUSR|S_IWUSR;
|
||||
if (TYPE (x) == TPAIR && TYPE (car (x)) == TNUMBER)
|
||||
mode = VALUE (car (x));
|
||||
return MAKE_NUMBER (open (CSTRING (file_name), O_WRONLY|O_CREAT|O_TRUNC,mode));
|
||||
return MAKE_NUMBER (mes_open (CSTRING (file_name), O_WRONLY|O_CREAT|O_TRUNC, mode));
|
||||
}
|
||||
|
||||
SCM
|
||||
|
|
Loading…
Reference in a new issue