Skip to content

Commit

Permalink
* Lib/bbLinLibW & bbLinLibc
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg-N-Cher committed Nov 21, 2023
1 parent eb57cc7 commit 60abf86
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 98 deletions.
64 changes: 24 additions & 40 deletions Mod/Lib/bbLinLibW.cp
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,40 @@ MODULE [foreign] bbLinLibW;

PtrWSTR* = POINTER [untagged] TO ARRAY [untagged] OF wchar_t;

PROCEDURE- includelocale "#include <locale.h>";
(*PROCEDURE- includelocale "#include <locale.h>";
PROCEDURE- includestdio "#include <stdio.h>";
PROCEDURE- includestdlib "#include <stdlib.h>";
PROCEDURE- includewchar "#include <wchar.h>";
PROCEDURE- includewctype "#include <wctype.h>";
PROCEDURE- includewctype "#include <wctype.h>";*)

PROCEDURE- setlocale* (category: int; locale: Libc.PtrSTR): Libc.PtrSTR
"(CHAR*)setlocale(category, (const char *)locale)";
PROCEDURE setlocale* (category: int; locale: Libc.PtrSTR): Libc.PtrSTR;

PROCEDURE- mbsinit* (VAR [nil] ps: mbstate_t): int
"mbsinit((const mbstate_t *)ps)";
PROCEDURE mbsinit* (VAR [nil] ps: mbstate_t): int;

PROCEDURE- wctomb* (s: Libc.PtrSTR; wchar: wchar_t): int
"wctomb((char *)s, (const wchar_t *)wchar)";
PROCEDURE- wcstombs* (s: Libc.PtrSTR; pwcs: PtrWSTR; n: size_t): size_t
"(SYSTEM_ADRINT)wcstombs((char *)s, (const wchar_t *)pwcs, (size_t) n)";
PROCEDURE wctomb* (s: Libc.PtrSTR; wchar: wchar_t): int;
PROCEDURE wcstombs* (s: Libc.PtrSTR; pwcs: PtrWSTR; n: size_t): size_t;

PROCEDURE- wcrtomb* (s: Libc.PtrSTR; wc: wchar_t; VAR [nil] ps: mbstate_t): size_t
"(SYSTEM_ADRINT)wcrtomb((char *)s, (wchar_t)wc, (mbstate_t *)ps)";
PROCEDURE- wcsrtombs* (dst: Libc.PtrSTR; VAR src: PtrWSTR; len: size_t; VAR [nil] ps: mbstate_t): size_t
"(SYSTEM_ADRINT)wcsrtombs((char *)dst, (const wchar_t **)wc, (size_t)len, (mbstate_t *)ps)";
PROCEDURE- wcsnrtombs* (dst: Libc.PtrSTR; VAR src: PtrWSTR; nwc: size_t; len: size_t; VAR [nil] ps: mbstate_t): size_t
"(SYSTEM_ADRINT)wcsnrtombs((char *)dst, (const wchar_t **)src, (size_t)nwc, (size_t)len, (mbstate_t *)ps)";
PROCEDURE wcrtomb* (s: Libc.PtrSTR; wc: wchar_t; VAR [nil] ps: mbstate_t): size_t;
PROCEDURE wcsrtombs* (dst: Libc.PtrSTR; VAR src: PtrWSTR; len: size_t; VAR [nil] ps: mbstate_t): size_t;
PROCEDURE wcsnrtombs* (dst: Libc.PtrSTR; VAR src: PtrWSTR; nwc: size_t; len: size_t; VAR [nil] ps: mbstate_t): size_t;

PROCEDURE- mbtowc* (pwc: PtrWSTR; s: Libc.PtrSTR; n: size_t): int
"mbtowc((wchar_t *)pwc, (const char *)s, (size_t)n)";
PROCEDURE- mbstowcs* (pwcs: PtrWSTR; s: Libc.PtrSTR; n: size_t): size_t
"(SYSTEM_ADRINT)mbstowcs((wchar_t *)pwcs, (const char *)s, (size_t)n)";
PROCEDURE- mblen* (s: Libc.PtrSTR; n: size_t): int
"mblen((const char *)s, (size_t)n)";
PROCEDURE mbtowc* (pwc: PtrWSTR; s: Libc.PtrSTR; n: size_t): int;
PROCEDURE mbstowcs* (pwcs: PtrWSTR; s: Libc.PtrSTR; n: size_t): size_t;
PROCEDURE mblen* (s: Libc.PtrSTR; n: size_t): int;

PROCEDURE- mbrtowc* (wc: PtrWSTR; s: Libc.PtrSTR; n: size_t; VAR [nil] mbs: mbstate_t): size_t
"(SYSTEM_ADRINT)mbrtowc((wchar_t *)wc, (const char *)s, (size_t)n, (mbstate_t *)mbs)";
PROCEDURE- mbsrtowcs* (dst: PtrWSTR; VAR src: Libc.PtrSTR; len: size_t; VAR [nil] ps: mbstate_t): size_t
"(SYSTEM_ADRINT)mbsrtowcs((wchar_t *)dst, (const char **)src, (size_t)len, (mbstate_t *)ps);";
PROCEDURE- mbsnrtowcs* (dst: PtrWSTR; VAR src: Libc.PtrSTR; nmc: size_t; len: size_t; VAR [nil] ps: mbstate_t): size_t
"(SYSTEM_ADRINT)mbsnrtowcs((wchar_t *)dst, (const char **)src, (size_t)nmc, (size_t)len, (mbstate_t *)ps)";
PROCEDURE- mbrlen* (s: Libc.PtrSTR; n: size_t; VAR [nil] ps: mbstate_t): size_t
"(SYSTEM_ADRINT)mbrlen((const char *)s, (size_t)n, (mbstate_t *)ps)";
PROCEDURE mbrtowc* (wc: PtrWSTR; s: Libc.PtrSTR; n: size_t; VAR [nil] mbs: mbstate_t): size_t;
PROCEDURE mbsrtowcs* (dst: PtrWSTR; VAR src: Libc.PtrSTR; len: size_t; VAR [nil] ps: mbstate_t): size_t;
PROCEDURE mbsnrtowcs* (dst: PtrWSTR; VAR src: Libc.PtrSTR; nmc: size_t; len: size_t; VAR [nil] ps: mbstate_t): size_t;
PROCEDURE mbrlen* (s: Libc.PtrSTR; n: size_t; VAR [nil] ps: mbstate_t): size_t;

PROCEDURE- iswalpha* (wc: wint_t): int "iswalpha(wc)";
PROCEDURE- iswlower* (wc: wint_t): int "iswlower(wc)";
PROCEDURE- iswupper* (wc: wint_t): int "iswupper(wc)";
PROCEDURE- towlower* (wc: wint_t): wint_t "towlower(wc)";
PROCEDURE- towupper* (wc: wint_t): wint_t "towupper(wc)";
PROCEDURE iswalpha* (wc: wint_t): int;
PROCEDURE iswlower* (wc: wint_t): int;
PROCEDURE iswupper* (wc: wint_t): int;
PROCEDURE towlower* (wc: wint_t): wint_t;
PROCEDURE towupper* (wc: wint_t): wint_t;

PROCEDURE- wprintf* (fmt: PtrWSTR): int "wprintf((const wchar_t *)fmt)";
PROCEDURE- fputws* (ws: PtrWSTR; fp: Libc.PtrFILE): int
"fputws((const wchar_t *)ws, (FILE *)fp)";
PROCEDURE- fgetws* (ws: PtrWSTR; n: int; fp: Libc.PtrFILE): PtrWSTR
"(INTEGER *)fgetws((wchar_t *)ws, n, (FILE *)fp)";
PROCEDURE wprintf* (fmt: PtrWSTR): int;
PROCEDURE fputws* (ws: PtrWSTR; fp: Libc.PtrFILE): int;
PROCEDURE fgetws* (ws: PtrWSTR; n: int; fp: Libc.PtrFILE): PtrWSTR;

END bbLinLibW.
115 changes: 57 additions & 58 deletions Mod/Lib/bbLinLibc.cp
Original file line number Diff line number Diff line change
Expand Up @@ -575,125 +575,124 @@ MODULE [foreign] bbLinLibc;
stdin*, stdout*, stderr* : PtrFILE;
*)

PROCEDURE- includestdio "#include <stdio.h>";
PROCEDURE- includestdlib "#include <stdlib.h>";
(*PROCEDURE- includestdio "#include <stdio.h>";
PROCEDURE- includestdlib "#include <stdlib.h>";*)

PROCEDURE- __errno_location*(): PtrVoid;
PROCEDURE __errno_location*(): PtrVoid;

PROCEDURE- __xstat* (version: int; filename: PtrSTR; VAR buf: stat_t): int;
PROCEDURE- __xstat64* (version: int; filename: PtrSTR; VAR buf: stat64_t): int;
PROCEDURE- fopen64* (path, mode: PtrSTR): PtrFILE;
PROCEDURE- lseek64* (fd: int; offset: off64_t; whence: int): off64_t;
PROCEDURE- fseeko64* (stream: PtrFILE; off: off64_t; whence: int): int;
PROCEDURE __xstat* (version: int; filename: PtrSTR; VAR buf: stat_t): int;
PROCEDURE __xstat64* (version: int; filename: PtrSTR; VAR buf: stat64_t): int;
PROCEDURE fopen64* (path, mode: PtrSTR): PtrFILE;
PROCEDURE lseek64* (fd: int; offset: off64_t; whence: int): off64_t;
PROCEDURE fseeko64* (stream: PtrFILE; off: off64_t; whence: int): int;

(*PROCEDURE- sigsetjmp* ["__sigsetjmp"] (VAR env: sigjmp_buf; savemask: int): int;*)


(* ANSI C 89 *)
PROCEDURE- clock* (): clock_t;
PROCEDURE clock* (): clock_t;

(* POSIX.1 *)
PROCEDURE- clock_gettime* (clock_id: clockid_t; VAR tp: timespec_t): int;
PROCEDURE clock_gettime* (clock_id: clockid_t; VAR tp: timespec_t): int;

PROCEDURE- mmap* (adr: PtrVoid; len: size_t; prot: intFlags; flags: intFlags; fd: int; offset: off_t): PtrVoid;
PROCEDURE mmap* (adr: PtrVoid; len: size_t; prot: intFlags; flags: intFlags; fd: int; offset: off_t): PtrVoid;
(* BSD *)
PROCEDURE- munmap* (adr: PtrVoid; len: size_t): int;
PROCEDURE- mprotect* (adr: PtrVoid; len: size_t; prot: intFlags): int;
PROCEDURE munmap* (adr: PtrVoid; len: size_t): int;
PROCEDURE mprotect* (adr: PtrVoid; len: size_t; prot: intFlags): int;

(*
PROCEDURE- calloc* (nmemb: size_t; size: size_t): PtrVoid;
(* ANSI C 89 *)
PROCEDURE- malloc* (size: size_t): PtrVoid;
*)
PROCEDURE- free* (ptr: PtrVoid) "free(ptr)";
PROCEDURE free* (ptr: PtrVoid);

(* AT&T *)
PROCEDURE- time* (VAR [nil] t: time_t): time_t;
PROCEDURE- gmtime* (VAR [nil] t: time_t): tm;
PROCEDURE- localtime* (VAR [nil] t: time_t): tm;
PROCEDURE time* (VAR [nil] t: time_t): time_t;
PROCEDURE gmtime* (VAR [nil] t: time_t): tm;
PROCEDURE localtime* (VAR [nil] t: time_t): tm;

(* POSIX.1 *)
(*
PROCEDURE- sigsetjmp* (VAR env: sigjmp_buf; savemask: int): int;
*)
PROCEDURE- siglongjmp* (VAR env: sigjmp_buf; val: int);
PROCEDURE siglongjmp* (VAR env: sigjmp_buf; val: int);

(* POSIX.1 *)
PROCEDURE- sigemptyset* (set: PtrSigset_t): int;
PROCEDURE- sigfillset* (set: PtrSigset_t): int;
PROCEDURE- sigaddset* (set: PtrSigset_t; signo: int): int;
PROCEDURE- sigprocmask* (how: int; set: PtrSigset_t; oset: PtrSigset_t): int;
PROCEDURE sigemptyset* (set: PtrSigset_t): int;
PROCEDURE sigfillset* (set: PtrSigset_t): int;
PROCEDURE sigaddset* (set: PtrSigset_t; signo: int): int;
PROCEDURE sigprocmask* (how: int; set: PtrSigset_t; oset: PtrSigset_t): int;

(* POSIX.1 *)
(*PROCEDURE- sigaction* (sig: int; VAR [nil] act: sigaction_t; VAR [nil] oact: sigaction_t): int;*)

(* BSD *)
PROCEDURE- sigaltstack* (VAR [nil] ss: stack_t; VAR [nil] oss: stack_t): int;
PROCEDURE sigaltstack* (VAR [nil] ss: stack_t; VAR [nil] oss: stack_t): int;

(* ANSI C 89 *)
PROCEDURE- getenv* (s: PtrSTR): PtrSTR;
PROCEDURE getenv* (s: PtrSTR): PtrSTR;

(* ANSI C 89 *)
PROCEDURE- fopen* (path, mode: PtrSTR): PtrFILE;
PROCEDURE- fdopen* (fildes: int; mode: PtrSTR): PtrFILE;
PROCEDURE- fclose* (stream: PtrFILE): int;
PROCEDURE- fread* (ptr: PtrVoid; size: size_t; nmemb: size_t; stream: PtrFILE): size_t;
PROCEDURE- fwrite* (ptr: PtrVoid; size: size_t; nmemb: size_t; stream: PtrFILE): size_t
"(SYSTEM_ADRINT)fwrite(ptr, (size_t)size, (size_t)nmemb, (FILE*)stream)";
PROCEDURE- fflush* (s: PtrFILE): int;
PROCEDURE- printf* (s: PtrSTR): int;
PROCEDURE fopen* (path, mode: PtrSTR): PtrFILE;
PROCEDURE fdopen* (fildes: int; mode: PtrSTR): PtrFILE;
PROCEDURE fclose* (stream: PtrFILE): int;
PROCEDURE fread* (ptr: PtrVoid; size: size_t; nmemb: size_t; stream: PtrFILE): size_t;
PROCEDURE fwrite* (ptr: PtrVoid; size: size_t; nmemb: size_t; stream: PtrFILE): size_t;
PROCEDURE fflush* (s: PtrFILE): int;
PROCEDURE printf* (s: PtrSTR): int;
(* ANSI C 89, XPG4 *)
PROCEDURE- fseek* (stream: PtrFILE; offset: long; whence: int): int;
PROCEDURE fseek* (stream: PtrFILE; offset: long; whence: int): int;

(* POSIX.1 *)
PROCEDURE- fileno* (stream: PtrFILE): int;
PROCEDURE fileno* (stream: PtrFILE): int;

(* POSIX.1 *)
PROCEDURE- rename* (from, to: PtrSTR): int;
PROCEDURE- mkdir* (path: PtrSTR; mode: mode_t): int;
PROCEDURE- opendir* (filename: PtrSTR): PtrDIR;
PROCEDURE- readdir* (dirp: PtrDIR): PtrDirent;
PROCEDURE- closedir* (dirp: PtrDIR): int;
PROCEDURE rename* (from, to: PtrSTR): int;
PROCEDURE mkdir* (path: PtrSTR; mode: mode_t): int;
PROCEDURE opendir* (filename: PtrSTR): PtrDIR;
PROCEDURE readdir* (dirp: PtrDIR): PtrDirent;
PROCEDURE closedir* (dirp: PtrDIR): int;
(* ANSI C 89, XPG4.2 *)
PROCEDURE- remove* (path: PtrSTR): int;
PROCEDURE remove* (path: PtrSTR): int;

(* POSIX.1 *)
PROCEDURE- getcwd* (buf: PtrSTR; size: size_t): PtrSTR;
PROCEDURE getcwd* (buf: PtrSTR; size: size_t): PtrSTR;

(* ANSI C 99 *)
PROCEDURE- exit* (status: int);
PROCEDURE exit* (status: int);

(* ANSI C 89 *)
PROCEDURE- strftime* (buf: PtrSTR; maxsize: size_t; format: PtrSTR; timeptr: tm): size_t;
PROCEDURE strftime* (buf: PtrSTR; maxsize: size_t; format: PtrSTR; timeptr: tm): size_t;

(* XXX: use fread instead *)
PROCEDURE- fgets* (str: PtrSTR; size: int; stream: PtrFILE): PtrSTR;
PROCEDURE fgets* (str: PtrSTR; size: int; stream: PtrFILE): PtrSTR;

(* POSIX.1 *)
PROCEDURE- open* (path: PtrSTR; flags: intFlags; mode: mode_t): int;
PROCEDURE- write* (d: int; buf: PtrVoid; nbytes: size_t): ssize_t;
PROCEDURE- read* (d: int; buf: PtrVoid; nbytes: size_t): ssize_t;
PROCEDURE- close* (d: int): int;
PROCEDURE open* (path: PtrSTR; flags: intFlags; mode: mode_t): int;
PROCEDURE write* (d: int; buf: PtrVoid; nbytes: size_t): ssize_t;
PROCEDURE read* (d: int; buf: PtrVoid; nbytes: size_t): ssize_t;
PROCEDURE close* (d: int): int;

(* POSIX.1 *)
PROCEDURE- chmod* (path: PtrSTR; mode: mode_t): int;
PROCEDURE- fchmod* (fd: int; mode: mode_t): int;
PROCEDURE chmod* (path: PtrSTR; mode: mode_t): int;
PROCEDURE fchmod* (fd: int; mode: mode_t): int;

(* POSIX.1 *)
PROCEDURE- fork* (): pid_t;
PROCEDURE- waitpid* (wpid: pid_t; VAR [nil] status: int; options: intFlags): pid_t;
PROCEDURE fork* (): pid_t;
PROCEDURE waitpid* (wpid: pid_t; VAR [nil] status: int; options: intFlags): pid_t;

(* POSIX.1 *)
PROCEDURE- execv* (path: PtrSTR; argv: POINTER [untagged] TO ARRAY [untagged] OF PtrSTR): int;
PROCEDURE- execvp* (file: PtrSTR; argv: POINTER [untagged] TO ARRAY [untagged] OF PtrSTR): int;
PROCEDURE execv* (path: PtrSTR; argv: POINTER [untagged] TO ARRAY [untagged] OF PtrSTR): int;
PROCEDURE execvp* (file: PtrSTR; argv: POINTER [untagged] TO ARRAY [untagged] OF PtrSTR): int;

(* POSIX.2 *)
PROCEDURE- system* (string: PtrSTR): int;
PROCEDURE system* (string: PtrSTR): int;

(* POSIX.1 *)
PROCEDURE- sysconf* (name: int): long;
PROCEDURE sysconf* (name: int): long;

PROCEDURE- popen* (command, type: PtrSTR): PtrFILE;
PROCEDURE- pclose* (stream: PtrFILE): int;
PROCEDURE popen* (command, type: PtrSTR): PtrFILE;
PROCEDURE pclose* (stream: PtrFILE): int;

END bbLinLibc.

0 comments on commit 60abf86

Please sign in to comment.