From 43a74e382ad972c1de76dd0f8556b5041cc9f929 Mon Sep 17 00:00:00 2001 From: Jeremiah Orians Date: Sat, 26 May 2018 16:33:00 -0400 Subject: [PATCH] mescc: Add fopen. * lib/libc+tcc.c (fopen)[!POSIX]: Remove stub. * lib/libc.c (fopen)[!POSIX]: New function. * AUTHORS: Add Jeremiah. --- AUTHORS | 9 ++++++++- include/stdio.h | 2 +- lib/libc+tcc.c | 9 +-------- lib/libc.c | 21 ++++++++++++++++++++- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/AUTHORS b/AUTHORS index 8fa55095..757e0f40 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,6 +1,13 @@ Jan (janneke) Nieuwenhuizen Main author -All files except the files listed below +All files except the imported files listed below + +Jeremiah Orians +lib/libc.c (fopen) + + + +List of imported files Based on Guile ECMAScript module/language/c/lexer.mes diff --git a/include/stdio.h b/include/stdio.h index 9e880e21..230eb057 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -103,7 +103,7 @@ int eputs (char const* s); int fclose (FILE *stream); FILE *fdopen (int fd, char const *mode); int fflush (FILE *stream); -FILE *fopen (char const *pathname, char const *mode); +FILE *fopen (char const *file_name, char const *mode); int ferror (FILE *stream); int fprintf (FILE *stream, char const *format, ...); int fdputc (int c, int fd); diff --git a/lib/libc+tcc.c b/lib/libc+tcc.c index bf0d0499..3a0b425b 100644 --- a/lib/libc+tcc.c +++ b/lib/libc+tcc.c @@ -1,6 +1,6 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2017,2018 Jan (janneke) Nieuwenhuizen * * This file is part of Mes. * @@ -76,13 +76,6 @@ fflush (FILE *stream) return 0; } -FILE * -fopen (char const *pathname, char const *mode) -{ - eputs ("fopen stub\n"); - return 0; -} - int fprintf (FILE *stream, char const *format, ...) { diff --git a/lib/libc.c b/lib/libc.c index 40be8a44..7f0bf1c1 100644 --- a/lib/libc.c +++ b/lib/libc.c @@ -1,6 +1,7 @@ /* -*-comment-start: "//";comment-end:""-*- * Mes --- Maxwell Equations of Software - * Copyright © 2016,2017 Jan (janneke) Nieuwenhuizen + * Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen + * Copyright © 2018 Jeremiah Orians * * This file is part of Mes. * @@ -174,6 +175,24 @@ eputc (int c) return fdputc (c, STDERR); } +FILE* +fopen (char const* file_name, char const* mode) +{ + FILE* f; + if ('w' == mode[0]) + /* 577 is O_WRONLY|O_CREAT|O_TRUNC, 384 is 600 in octal */ + f = open (file_name, 577 , 384); + else + /* Everything else is a read */ + f = open (file_name, 0, 0); + + /* Negative numbers are error codes */ + if (0 > f) + return 0; + + return f; +} + int putchar (int c) {