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:
Jan Nieuwenhuizen 2019-05-13 00:40:33 +02:00
parent a5ae6569fb
commit 8bda737ee4
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273
4 changed files with 16 additions and 16 deletions

View file

@ -23,11 +23,6 @@
#include <mes/lib-mini.h> #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 (); int __mes_debug ();
void __ungetc_init (); void __ungetc_init ();
void __ungetc_clear (int filedes); void __ungetc_clear (int filedes);
@ -50,8 +45,9 @@ int _fdungetc_p (int fd);
int isdigit (int c); int isdigit (int c);
int isspace (int c); int isspace (int c);
int isxdigit (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 _open2 (char const *file_name, int flags);
int _open3 (char const *file_name, int flags, int mask);
int oputc (int c); int oputc (int c);
int oputs (char const* s); int oputs (char const* s);
char *search_path (char const *file_name); char *search_path (char const *file_name);

View file

@ -42,7 +42,6 @@
#include <mes/fdungetc.c> #include <mes/fdungetc.c>
#if WITH_GLIBC #if WITH_GLIBC
#undef open
#include <fcntl.h> #include <fcntl.h>
#include <stdarg.h> #include <stdarg.h>
// The Mes C Library defines and initializes these in crt1 // The Mes C Library defines and initializes these in crt1
@ -51,22 +50,27 @@ int __stdout = STDOUT;
int __stderr = STDERR; int __stderr = STDERR;
int 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 (); __ungetc_init ();
int r = open (file_name, flags, mask); int r = open (file_name, flags, mask);
if (r > 2) if (r > 2)
__ungetc_buf[r] = -1; __ungetc_buf[r] = -1;
va_end (ap);
return r; return r;
} }
#include <mes/eputs.c> #include <mes/eputs.c>
#include <mes/oputs.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/eputc.c>
#include <mes/oputc.c> #include <mes/oputc.c>

View file

@ -2192,7 +2192,7 @@ open_boot (char *prefix, char const *boot, char const *location)
eputs (prefix); eputs (prefix);
eputs ("\n"); eputs ("\n");
} }
int fd = open (prefix, O_RDONLY); int fd = mes_open (prefix, O_RDONLY, 0);
if (g_debug && fd > 0) if (g_debug && fd > 0)
{ {
eputs ("mes: read boot-0: "); eputs ("mes: read boot-0: ");

View file

@ -186,7 +186,7 @@ current_input_port ()
SCM SCM
open_input_file (SCM file_name) 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 SCM
@ -228,7 +228,7 @@ open_output_file (SCM x) ///((arity . n))
int mode = S_IRUSR|S_IWUSR; int mode = S_IRUSR|S_IWUSR;
if (TYPE (x) == TPAIR && TYPE (car (x)) == TNUMBER) if (TYPE (x) == TPAIR && TYPE (car (x)) == TNUMBER)
mode = VALUE (car (x)); 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 SCM