Skip to content

Commit

Permalink
inc/darwin: (WIP) Use linux versions of various crt headers; can incl…
Browse files Browse the repository at this point in the history
…ude crt.bi now

Only stdio.bi has been translated from the real thing.
  • Loading branch information
rversteegen authored and jayrm committed Jan 1, 2024
1 parent c707eef commit 83852e9
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 40 deletions.
39 changes: 39 additions & 0 deletions 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
88 changes: 48 additions & 40 deletions inc/crt/errno.bi
Expand Up @@ -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"

Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions inc/crt/stdio.bi
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions inc/crt/sys/types.bi
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions inc/crt/time.bi
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions inc/crt/wchar.bi
Expand Up @@ -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"
Expand Down

0 comments on commit 83852e9

Please sign in to comment.