Skip to content

Commit

Permalink
(getpid) in (liii os)
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii committed Aug 9, 2024
1 parent 3749b6e commit 0259741
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion goldfish/liii/os.scm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
(define-library (liii os)
(export
os-call os-arch os-type os-windows? os-linux? os-macos? os-temp-dir
isdir mkdir rmdir getenv getcwd listdir access getlogin)
isdir mkdir rmdir getenv getcwd listdir access getlogin getpid)
(import (scheme process-context)
(liii error))
(begin
Expand Down Expand Up @@ -87,5 +87,8 @@
(getenv "USERNAME")
(g_getlogin)))

(define (getpid)
(g_getpid))

) ; end of begin
) ; end of define-library
15 changes: 15 additions & 0 deletions src/goldfish.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#ifdef TB_CONFIG_OS_WINDOWS
#include <io.h>
#include <windows.h>
#else
#include <pwd.h>
#include <unistd.h>
Expand Down Expand Up @@ -293,6 +294,15 @@ f_getlogin (s7_scheme* sc, s7_pointer args) {
#endif
}

static s7_pointer
f_getpid (s7_scheme* sc, s7_pointer args) {
#ifdef TB_CONFIG_OS_WINDOWS
return GetCurrentProcessId ();
#else
return s7_make_integer (sc, getpid ());
#endif
}

inline void
glue_liii_os (s7_scheme* sc) {
s7_pointer cur_env= s7_curlet (sc);
Expand All @@ -317,6 +327,8 @@ glue_liii_os (s7_scheme* sc) {
const char* d_access = "(g_access string integer) => boolean";
const char* s_getlogin = "g_getlogin";
const char* d_getlogin = "(g_getlogin) => string";
const char* s_getpid = "g_getpid";
const char* d_getpid = "(g_getpid) => integer";

s7_define (sc, cur_env, s7_make_symbol (sc, s_os_type),
s7_make_typed_function (sc, s_os_type, f_os_type, 0, 0, false,
Expand Down Expand Up @@ -348,6 +360,9 @@ glue_liii_os (s7_scheme* sc) {
s7_define (sc, cur_env, s7_make_symbol (sc, s_getlogin),
s7_make_typed_function (sc, s_getlogin, f_getlogin, 0, 0, false,
d_access, NULL));
s7_define (sc, cur_env, s7_make_symbol (sc, s_getpid),
s7_make_typed_function (sc, s_getpid, f_getpid, 0, 0, false,
d_getpid, NULL));
}

static s7_pointer
Expand Down

0 comments on commit 0259741

Please sign in to comment.