From 83852e99e9fc5cca7520e816de3172559eb77ceb Mon Sep 17 00:00:00 2001 From: Ralph Versteegen Date: Mon, 11 Apr 2016 16:34:53 +1200 Subject: [PATCH] inc/darwin: (WIP) Use linux versions of various crt headers; can include crt.bi now Only stdio.bi has been translated from the real thing. --- inc/crt/darwin/stdio.bi | 39 ++++++++++++++++++ inc/crt/errno.bi | 88 ++++++++++++++++++++++------------------- inc/crt/stdio.bi | 2 + inc/crt/sys/types.bi | 3 ++ inc/crt/time.bi | 5 +++ inc/crt/wchar.bi | 4 ++ 6 files changed, 101 insertions(+), 40 deletions(-) create mode 100644 inc/crt/darwin/stdio.bi diff --git a/inc/crt/darwin/stdio.bi b/inc/crt/darwin/stdio.bi new file mode 100644 index 0000000000..b5cbbee542 --- /dev/null +++ b/inc/crt/darwin/stdio.bi @@ -0,0 +1,39 @@ +'' +'' +'' stdio -- header translated with help of SWIG FB wrapper +'' +'' NOTICE: This file is part of the FreeBASIC Compiler package and can't +'' be included in other distributions without authorization. +'' +'' +#ifndef __crt_linux_stdio_bi__ +#define __crt_linux_stdio_bi__ + +#define _IOFBF 0 +#define _IOLBF 1 +#define _IONBF 2 +#define BUFSIZ 1024 +#define FILENAME_MAX 1024 +#define FOPEN_MAX 20 +#define P_tmpdir "/var/tmp" +#define L_tmpnam 1024 +#define TMP_MAX 308915776 + +type FILE as _sFILE + +extern stdin alias "__stdinp" as FILE ptr +extern stdout alias "__stdoutp" as FILE ptr +extern stderr alias "__stderrp" as FILE ptr + +type fpos_t as longint + +extern "c" +declare function snprintf (byval s as zstring ptr, byval n as size_t, byval format as zstring ptr, ...) as long +declare function vsnprintf (byval s as zstring ptr, byval n as size_t, byval format as zstring ptr, byval arg as va_list) as long +declare function popen (byval as zstring ptr, byval as zstring ptr) as FILE ptr +declare function pclose (byval as FILE ptr) as long +declare function getw (byval as FILE ptr) as long +declare function putw (byval as long, byval as FILE ptr) as long +end extern + +#endif diff --git a/inc/crt/errno.bi b/inc/crt/errno.bi index f76e96dcf6..5f3d3eea40 100644 --- a/inc/crt/errno.bi +++ b/inc/crt/errno.bi @@ -9,46 +9,51 @@ #ifndef __crt_errno_bi__ #define __crt_errno_bi__ -#define EPERM 1 -#define ENOFILE 2 -#define ENOENT 2 -#define ESRCH 3 -#define EINTR 4 -#define EIO 5 -#define ENXIO 6 -#define E2BIG 7 -#define ENOEXEC 8 -#define EBADF 9 -#define ECHILD 10 -#define EAGAIN 11 -#define ENOMEM 12 -#define EACCES 13 -#define EFAULT 14 -#define EBUSY 16 -#define EEXIST 17 -#define EXDEV 18 -#define ENODEV 19 -#define ENOTDIR 20 -#define EISDIR 21 -#define EINVAL 22 -#define ENFILE 23 -#define EMFILE 24 -#define ENOTTY 25 -#define EFBIG 27 -#define ENOSPC 28 -#define ESPIPE 29 -#define EROFS 30 -#define EMLINK 31 -#define EPIPE 32 -#define EDOM 33 -#define ERANGE 34 -#define EDEADLOCK 36 -#define EDEADLK 36 -#define ENAMETOOLONG 38 -#define ENOLCK 39 -#define ENOSYS 40 -#define ENOTEMPTY 41 -#define EILSEQ 42 +#ifdef __FB_DARWIN__ + '' FIXME: Error numbers are completely different on Darwin +#else + + #define EPERM 1 + #define ENOFILE 2 + #define ENOENT 2 + #define ESRCH 3 + #define EINTR 4 + #define EIO 5 + #define ENXIO 6 + #define E2BIG 7 + #define ENOEXEC 8 + #define EBADF 9 + #define ECHILD 10 + #define EAGAIN 11 + #define ENOMEM 12 + #define EACCES 13 + #define EFAULT 14 + #define EBUSY 16 + #define EEXIST 17 + #define EXDEV 18 + #define ENODEV 19 + #define ENOTDIR 20 + #define EISDIR 21 + #define EINVAL 22 + #define ENFILE 23 + #define EMFILE 24 + #define ENOTTY 25 + #define EFBIG 27 + #define ENOSPC 28 + #define ESPIPE 29 + #define EROFS 30 + #define EMLINK 31 + #define EPIPE 32 + #define EDOM 33 + #define ERANGE 34 + #define EDEADLOCK 36 + #define EDEADLK 36 + #define ENAMETOOLONG 38 + #define ENOLCK 39 + #define ENOSYS 40 + #define ENOTEMPTY 41 + #define EILSEQ 42 +#endif extern "C" @@ -58,6 +63,9 @@ extern "C" #elseif defined( __FB_LINUX__ ) declare function __errno_location() as long ptr #define errno (*__errno_location()) +#elseif defined( __FB_DARWIN__ ) + declare function __error() as long ptr + #define errno (*__error()) #else extern errno as long #endif diff --git a/inc/crt/stdio.bi b/inc/crt/stdio.bi index 164cda5118..d334276453 100644 --- a/inc/crt/stdio.bi +++ b/inc/crt/stdio.bi @@ -29,6 +29,8 @@ #include once "crt/linux/stdio.bi" #elseif defined(__FB_FREEBSD__) #include once "crt/freebsd/stdio.bi" +#elseif defined(__FB_DARWIN__) +#include once "crt/darwin/stdio.bi" #elseif defined(__FB_UNIX__) '' Other Unices are likely to be BSD variants. stdio.bi is the most important '' crt header, so try to make FB work on other OSes. diff --git a/inc/crt/sys/types.bi b/inc/crt/sys/types.bi index 5f72c377db..b3d02405e4 100644 --- a/inc/crt/sys/types.bi +++ b/inc/crt/sys/types.bi @@ -19,6 +19,9 @@ #include once "crt/sys/linux/types.bi" #elseif defined(__FB_FREEBSD__) #include once "crt/sys/freebsd/types.bi" +#elseif defined(__FB_DARWIN__) +'' May not be correct +#include once "crt/sys/linux/types.bi" #else #error Platform unsupported #endif diff --git a/inc/crt/time.bi b/inc/crt/time.bi index 2a0b051ecb..e84e345412 100644 --- a/inc/crt/time.bi +++ b/inc/crt/time.bi @@ -20,6 +20,11 @@ #include once "crt/linux/time.bi" #elseif defined(__FB_FREEBSD__) #include once "crt/freebsd/time.bi" +#elseif defined(__FB_DARWIN__) +'' FIXME: may be wrong +#include once "crt/linux/time.bi" +#else +#error Unsupported platform #endif extern "c" diff --git a/inc/crt/wchar.bi b/inc/crt/wchar.bi index 073a849860..22991de751 100644 --- a/inc/crt/wchar.bi +++ b/inc/crt/wchar.bi @@ -24,6 +24,10 @@ #include once "crt/freebsd/wchar.bi" #elseif defined(__FB_DOS__) #include once "crt/dos/wchar.bi" +#elseif defined(__FB_DARWIN__) +#include once "crt/linux/wchar.bi" +#else +#error Unsupported platform #endif extern "c"