diff --git a/scheme/ikarus.boot.orig b/scheme/ikarus.boot.orig index 117b013..a8b4f6a 100644 Binary files a/scheme/ikarus.boot.orig and b/scheme/ikarus.boot.orig differ diff --git a/scheme/ikarus.main.ss b/scheme/ikarus.main.ss index 5c79cea..7de8da9 100644 --- a/scheme/ikarus.main.ss +++ b/scheme/ikarus.main.ss @@ -51,14 +51,14 @@ (let ([d (cdr args)]) (cond [(null? d) - (error #f "--script requires a script name")] + (error 'ikarus "--script requires a script name")] [else (values '() (car d) 'script (cdr d))]))] [(string=? (car args) "--r6rs-script") (let ([d (cdr args)]) (cond [(null? d) - (error #f "--r6rs-script requires a script name")] + (error 'ikarus "--r6rs-script requires a script name")] [else (values '() (car d) 'r6rs-script (cdr d))]))] [else diff --git a/scheme/ikarus.posix.ss b/scheme/ikarus.posix.ss index c2a748a..88cc6bb 100644 --- a/scheme/ikarus.posix.ss +++ b/scheme/ikarus.posix.ss @@ -16,12 +16,12 @@ (library (ikarus posix) (export posix-fork fork waitpid system file-exists? delete-file - env environ) + getenv env environ) (import (rnrs bytevectors) (except (ikarus) posix-fork fork waitpid system file-exists? delete-file - env environ)) + getenv env environ)) (define posix-fork (lambda () @@ -96,6 +96,16 @@ [else "Unknown error while deleting"]) x)])))) + (define ($getenv-bv key) + (foreign-call "ikrt_getenv" key)) + (define ($getenv-str key) + (utf8->string ($getenv-bv (string->utf8 key)))) + + (define (getenv key) + (if (string? key) + ($getenv-str key) + (error 'getenv "the key is not a string" key))) + (define env (let () (define env diff --git a/scheme/makefile.ss b/scheme/makefile.ss index c072d4e..27d6595 100755 --- a/scheme/makefile.ss +++ b/scheme/makefile.ss @@ -1266,6 +1266,7 @@ [string-normalize-nfkd r uc] [string-titlecase r uc] [string-upcase r uc] + [getenv i] [char-ready? ] [interaction-environment ] [load i] diff --git a/src/ikarus-runtime.c b/src/ikarus-runtime.c index 1ab4400..2c64da5 100644 --- a/src/ikarus-runtime.c +++ b/src/ikarus-runtime.c @@ -1036,21 +1036,21 @@ ikrt_waitpid(ikp pid){ } ikp -ikrt_getenv(ikp str, ikpcb* pcb){ - fprintf(stderr, "getenv busted!\n"); - exit(-1); - char* v = getenv((char*)str + off_bytevector_data); +ikrt_getenv(ikp bv, ikpcb* pcb){ + char* v = getenv((char*)bv + off_bytevector_data); if(v){ int n = strlen(v); - ikp s = ik_unsafe_alloc(pcb, align(n+disp_string_data+1)) + string_tag; - ref(s, -string_tag) = fix(n); - memcpy(s+off_string_data, v, n+1); + ikp s = ik_safe_alloc(pcb, align(n+disp_bytevector_data+1)) + + bytevector_tag; + ref(s, -bytevector_tag) = fix(n); + memcpy(s+off_bytevector_data, v, n+1); return s; } else { - ikp s = ik_unsafe_alloc(pcb, align(disp_string_data+1)) + string_tag; - ref(s, -string_tag) = fix(0); - ref(s, off_string_data) = 0; + ikp s = ik_safe_alloc(pcb, align(disp_bytevector_data+1)) + + bytevector_tag; + ref(s, -bytevector_tag) = fix(0); + ref(s, off_bytevector_data) = 0; return s; } }