[hackers] [scc] [libc] Make stdio.h portable between architectures || Roberto E. Vargas Caballero

From: <git_AT_suckless.org>
Date: Thu, 16 Feb 2017 16:48:47 +0100 (CET)

commit 6b24fc832cf3aa5ff29c06951326bbc140ab0c45
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Feb 16 16:41:03 2017 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Feb 16 16:48:31 2017 +0100

    [libc] Make stdio.h portable between architectures
    
    Almost all the code of stdio.h is portable between the
    different architectures, and only a few bits are
    architecture dependant. A good solution is to put
    every dependant bit in a arch/stdio.h file, and
    share the rest between the different architectures.

diff --git a/inc/sysincludes.def.h b/inc/sysincludes.def.h
index 92e14de..4c338b8 100644
--- a/inc/sysincludes.def.h
+++ b/inc/sysincludes.def.h
_AT_@ -1,6 +1,7 @@
 char *sysincludes[] = {
         PREFIX "/include/scc/" ,
         PREFIX "/include/scc/" ARCH "/",
+ PREFIX "/include/scc/" ARCH "/arch/",
         /* configure below your standard sys include paths */
         PREFIX "/include/",
         PREFIX "/local/include/",
diff --git a/libc/include/amd64-sysv/arch/stdio.h b/libc/include/amd64-sysv/arch/stdio.h
new file mode 100644
index 0000000..d35960e
--- /dev/null
+++ b/libc/include/amd64-sysv/arch/stdio.h
_AT_@ -0,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ 512
+#define FILENAME_MAX 256
+#define FOPEN_MAX 16
+
+#define TMP_MAX 25
+#define L_tmpnam 256
+
+typedef struct _FILE FILE;
diff --git a/libc/include/amd64-sysv/stdio.h b/libc/include/amd64-sysv/stdio.h
deleted file mode 100644
index ea5fc78..0000000
--- a/libc/include/amd64-sysv/stdio.h
+++ /dev/null
_AT_@ -1,79 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDIO_H
-#define _STDIO_H
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define EOF -1
-#define BUFSIZ 512
-#define FILENAME_MAX 256
-#define FOPEN_MAX 16
-#define _IOFBF 0
-#define _IOLBF 1
-#define _IONBF 2
-#define L_tmpnam 256
-#define SEEK_CUR 0
-#define SEEK_END 1
-#define SEEK_SET 2
-#define TMP_MAX 25
-
-typedef struct _FILE FILE;
-
-extern FILE *fopen(const char *, const char *mode);
-extern FILE *freopen(const char *path, const char *mode, FILE *fp);
-extern int fclose(FILE *fp);
-
-extern int fflush(FILE *fp);
-extern void setbuf(FILE *fp, char *buf);
-extern int setvbuf(FILE *fp, char *buf, size_t size);
-
-extern size_t fread(void *ptr, size_t size, size_t n, FILE *fp);
-extern size_t fwrite(const void *ptr, size_t size, size_t n, FILE *fp);
-
-extern int fgetc(FILE *fp);
-extern int getc(FILE *fp);
-extern int getchar(void);
-
-extern int fputc(int c, FILE *fp);
-extern int putc(int c, FILE *fp);
-extern int putchar(int c);
-
-extern char *fgets(char *s, int size, FILE *fp);
-extern char *gets(char *s);
-
-extern int fputs(char *s, FILE *fp);
-extern int puts(char *s);
-
-extern int scanf(const char *fmt, ...);
-extern int fscanf(FILE *fp, const char *fmt, ...);
-extern int sscanf(char *s, const char *fmt, ...);
-
-extern int printf(const char *fmt, ...);
-extern int fprintf(FILE *fp, const char *fmt, ...);
-extern int sprintf(char *s, const char *fmt, ...);
-extern int snprintf(char *s, size_t size, const char *fmt, ...);
-
-extern void perror(const char *s);
-
-extern long ftell(FILE *fp);
-extern long fseek(FILE *fp);
-extern void rewind(FILE *fp);
-
-extern void clearerr(FILE *fp);
-extern int feof(FILE *fp);
-extern int ferror(FILE *fp);
-
-extern int remove(const char *name);
-extern int rename(const char *old, const char *new);
-extern FILE *tmpfile(void);
-extern FILE *tmpnam(char *s);
-
-extern FILE *stdin, *stdout, *stderr;
-#endif
diff --git a/libc/include/i386-sysv/arch/stdio.h b/libc/include/i386-sysv/arch/stdio.h
new file mode 100644
index 0000000..d35960e
--- /dev/null
+++ b/libc/include/i386-sysv/arch/stdio.h
_AT_@ -0,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ 512
+#define FILENAME_MAX 256
+#define FOPEN_MAX 16
+
+#define TMP_MAX 25
+#define L_tmpnam 256
+
+typedef struct _FILE FILE;
diff --git a/libc/include/i386-sysv/stdio.h b/libc/include/i386-sysv/stdio.h
deleted file mode 100644
index ea5fc78..0000000
--- a/libc/include/i386-sysv/stdio.h
+++ /dev/null
_AT_@ -1,79 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDIO_H
-#define _STDIO_H
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define EOF -1
-#define BUFSIZ 512
-#define FILENAME_MAX 256
-#define FOPEN_MAX 16
-#define _IOFBF 0
-#define _IOLBF 1
-#define _IONBF 2
-#define L_tmpnam 256
-#define SEEK_CUR 0
-#define SEEK_END 1
-#define SEEK_SET 2
-#define TMP_MAX 25
-
-typedef struct _FILE FILE;
-
-extern FILE *fopen(const char *, const char *mode);
-extern FILE *freopen(const char *path, const char *mode, FILE *fp);
-extern int fclose(FILE *fp);
-
-extern int fflush(FILE *fp);
-extern void setbuf(FILE *fp, char *buf);
-extern int setvbuf(FILE *fp, char *buf, size_t size);
-
-extern size_t fread(void *ptr, size_t size, size_t n, FILE *fp);
-extern size_t fwrite(const void *ptr, size_t size, size_t n, FILE *fp);
-
-extern int fgetc(FILE *fp);
-extern int getc(FILE *fp);
-extern int getchar(void);
-
-extern int fputc(int c, FILE *fp);
-extern int putc(int c, FILE *fp);
-extern int putchar(int c);
-
-extern char *fgets(char *s, int size, FILE *fp);
-extern char *gets(char *s);
-
-extern int fputs(char *s, FILE *fp);
-extern int puts(char *s);
-
-extern int scanf(const char *fmt, ...);
-extern int fscanf(FILE *fp, const char *fmt, ...);
-extern int sscanf(char *s, const char *fmt, ...);
-
-extern int printf(const char *fmt, ...);
-extern int fprintf(FILE *fp, const char *fmt, ...);
-extern int sprintf(char *s, const char *fmt, ...);
-extern int snprintf(char *s, size_t size, const char *fmt, ...);
-
-extern void perror(const char *s);
-
-extern long ftell(FILE *fp);
-extern long fseek(FILE *fp);
-extern void rewind(FILE *fp);
-
-extern void clearerr(FILE *fp);
-extern int feof(FILE *fp);
-extern int ferror(FILE *fp);
-
-extern int remove(const char *name);
-extern int rename(const char *old, const char *new);
-extern FILE *tmpfile(void);
-extern FILE *tmpnam(char *s);
-
-extern FILE *stdin, *stdout, *stderr;
-#endif
diff --git a/libc/include/qbe/arch/stdio.h b/libc/include/qbe/arch/stdio.h
new file mode 100644
index 0000000..d35960e
--- /dev/null
+++ b/libc/include/qbe/arch/stdio.h
_AT_@ -0,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+#ifndef _SIZET
+typedef unsigned long size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ 512
+#define FILENAME_MAX 256
+#define FOPEN_MAX 16
+
+#define TMP_MAX 25
+#define L_tmpnam 256
+
+typedef struct _FILE FILE;
diff --git a/libc/include/qbe/stdio.h b/libc/include/qbe/stdio.h
deleted file mode 100644
index ea5fc78..0000000
--- a/libc/include/qbe/stdio.h
+++ /dev/null
_AT_@ -1,79 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDIO_H
-#define _STDIO_H
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-#ifndef _SIZET
-typedef unsigned long size_t;
-#define _SIZET
-#endif
-
-#define EOF -1
-#define BUFSIZ 512
-#define FILENAME_MAX 256
-#define FOPEN_MAX 16
-#define _IOFBF 0
-#define _IOLBF 1
-#define _IONBF 2
-#define L_tmpnam 256
-#define SEEK_CUR 0
-#define SEEK_END 1
-#define SEEK_SET 2
-#define TMP_MAX 25
-
-typedef struct _FILE FILE;
-
-extern FILE *fopen(const char *, const char *mode);
-extern FILE *freopen(const char *path, const char *mode, FILE *fp);
-extern int fclose(FILE *fp);
-
-extern int fflush(FILE *fp);
-extern void setbuf(FILE *fp, char *buf);
-extern int setvbuf(FILE *fp, char *buf, size_t size);
-
-extern size_t fread(void *ptr, size_t size, size_t n, FILE *fp);
-extern size_t fwrite(const void *ptr, size_t size, size_t n, FILE *fp);
-
-extern int fgetc(FILE *fp);
-extern int getc(FILE *fp);
-extern int getchar(void);
-
-extern int fputc(int c, FILE *fp);
-extern int putc(int c, FILE *fp);
-extern int putchar(int c);
-
-extern char *fgets(char *s, int size, FILE *fp);
-extern char *gets(char *s);
-
-extern int fputs(char *s, FILE *fp);
-extern int puts(char *s);
-
-extern int scanf(const char *fmt, ...);
-extern int fscanf(FILE *fp, const char *fmt, ...);
-extern int sscanf(char *s, const char *fmt, ...);
-
-extern int printf(const char *fmt, ...);
-extern int fprintf(FILE *fp, const char *fmt, ...);
-extern int sprintf(char *s, const char *fmt, ...);
-extern int snprintf(char *s, size_t size, const char *fmt, ...);
-
-extern void perror(const char *s);
-
-extern long ftell(FILE *fp);
-extern long fseek(FILE *fp);
-extern void rewind(FILE *fp);
-
-extern void clearerr(FILE *fp);
-extern int feof(FILE *fp);
-extern int ferror(FILE *fp);
-
-extern int remove(const char *name);
-extern int rename(const char *old, const char *new);
-extern FILE *tmpfile(void);
-extern FILE *tmpnam(char *s);
-
-extern FILE *stdin, *stdout, *stderr;
-#endif
diff --git a/libc/include/stdio.h b/libc/include/stdio.h
new file mode 100644
index 0000000..4df2e55
--- /dev/null
+++ b/libc/include/stdio.h
_AT_@ -0,0 +1,66 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef _STDIO_H
+#define _STDIO_H
+
+#include <arch/stdio.h>
+
+#define EOF -1
+#define _IOFBF 0
+#define _IOLBF 1
+#define _IONBF 2
+#define SEEK_CUR 0
+#define SEEK_END 1
+#define SEEK_SET 2
+
+
+extern FILE *fopen(const char *, const char *mode);
+extern FILE *freopen(const char *path, const char *mode, FILE *fp);
+extern int fclose(FILE *fp);
+
+extern int fflush(FILE *fp);
+extern void setbuf(FILE *fp, char *buf);
+extern int setvbuf(FILE *fp, char *buf, size_t size);
+
+extern size_t fread(void *ptr, size_t size, size_t n, FILE *fp);
+extern size_t fwrite(const void *ptr, size_t size, size_t n, FILE *fp);
+
+extern int fgetc(FILE *fp);
+extern int getc(FILE *fp);
+extern int getchar(void);
+
+extern int fputc(int c, FILE *fp);
+extern int putc(int c, FILE *fp);
+extern int putchar(int c);
+
+extern char *fgets(char *s, int size, FILE *fp);
+extern char *gets(char *s);
+
+extern int fputs(char *s, FILE *fp);
+extern int puts(char *s);
+
+extern int scanf(const char *fmt, ...);
+extern int fscanf(FILE *fp, const char *fmt, ...);
+extern int sscanf(char *s, const char *fmt, ...);
+
+extern int printf(const char *fmt, ...);
+extern int fprintf(FILE *fp, const char *fmt, ...);
+extern int sprintf(char *s, const char *fmt, ...);
+extern int snprintf(char *s, size_t size, const char *fmt, ...);
+
+extern void perror(const char *s);
+
+extern long ftell(FILE *fp);
+extern long fseek(FILE *fp);
+extern void rewind(FILE *fp);
+
+extern void clearerr(FILE *fp);
+extern int feof(FILE *fp);
+extern int ferror(FILE *fp);
+
+extern int remove(const char *name);
+extern int rename(const char *old, const char *new);
+extern FILE *tmpfile(void);
+extern FILE *tmpnam(char *s);
+
+extern FILE *stdin, *stdout, *stderr;
+#endif
diff --git a/libc/include/z80/arch/stdio.h b/libc/include/z80/arch/stdio.h
new file mode 100644
index 0000000..cfd0d3d
--- /dev/null
+++ b/libc/include/z80/arch/stdio.h
_AT_@ -0,0 +1,18 @@
+/* See LICENSE file for copyright and license details. */
+#ifndef NULL
+#define NULL ((void *) 0)
+#endif
+
+#ifndef _SIZET
+typedef unsigned size_t;
+#define _SIZET
+#endif
+
+#define BUFSIZ 512
+#define FILENAME_MAX 256
+#define FOPEN_MAX 16
+
+#define TMP_MAX 25
+#define L_tmpnam 256
+
+typedef struct _FILE FILE;
diff --git a/libc/include/z80/stdio.h b/libc/include/z80/stdio.h
deleted file mode 100644
index 1122eb6..0000000
--- a/libc/include/z80/stdio.h
+++ /dev/null
_AT_@ -1,79 +0,0 @@
-/* See LICENSE file for copyright and license details. */
-#ifndef _STDIO_H
-#define _STDIO_H
-
-#ifndef NULL
-#define NULL ((void *) 0)
-#endif
-
-#ifndef _SIZET
-typedef unsigned size_t;
-#define _SIZET
-#endif
-
-#define EOF -1
-#define BUFSIZ 512
-#define FILENAME_MAX 256
-#define FOPEN_MAX 16
-#define _IOFBF 0
-#define _IOLBF 1
-#define _IONBF 2
-#define L_tmpnam 256
-#define SEEK_CUR 0
-#define SEEK_END 1
-#define SEEK_SET 2
-#define TMP_MAX 25
-
-typedef struct _FILE FILE;
-
-extern FILE *fopen(const char *, const char *mode);
-extern FILE *freopen(const char *path, const char *mode, FILE *fp);
-extern int fclose(FILE *fp);
-
-extern int fflush(FILE *fp);
-extern void setbuf(FILE *fp, char *buf);
-extern int setvbuf(FILE *fp, char *buf, size_t size);
-
-extern size_t fread(void *ptr, size_t size, size_t n, FILE *fp);
-extern size_t fwrite(const void *ptr, size_t size, size_t n, FILE *fp);
-
-extern int fgetc(FILE *fp);
-extern int getc(FILE *fp);
-extern int getchar(void);
-
-extern int fputc(int c, FILE *fp);
-extern int putc(int c, FILE *fp);
-extern int putchar(int c);
-
-extern char *fgets(char *s, int size, FILE *fp);
-extern char *gets(char *s);
-
-extern int fputs(char *s, FILE *fp);
-extern int puts(char *s);
-
-extern int scanf(const char *fmt, ...);
-extern int fscanf(FILE *fp, const char *fmt, ...);
-extern int sscanf(char *s, const char *fmt, ...);
-
-extern int printf(const char *fmt, ...);
-extern int fprintf(FILE *fp, const char *fmt, ...);
-extern int sprintf(char *s, const char *fmt, ...);
-extern int snprintf(char *s, size_t size, const char *fmt, ...);
-
-extern void perror(const char *s);
-
-extern long ftell(FILE *fp);
-extern long fseek(FILE *fp);
-extern void rewind(FILE *fp);
-
-extern void clearerr(FILE *fp);
-extern int feof(FILE *fp);
-extern int ferror(FILE *fp);
-
-extern int remove(const char *name);
-extern int rename(const char *old, const char *new);
-extern FILE *tmpfile(void);
-extern FILE *tmpnam(char *s);
-
-extern FILE *stdin, *stdout, *stderr;
-#endif
diff --git a/libc/src/Makefile b/libc/src/Makefile
index d4e9684..d837948 100644
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
_AT_@ -1,3 +1,5 @@
+# See LICENSE file for copyright and license details.
+.POSIX:
 
 LIBCOBJ = assert.o
 
Received on Thu Feb 16 2017 - 16:48:47 CET

This archive was generated by hypermail 2.3.0 : Thu Feb 16 2017 - 17:00:23 CET