Added getenv, which takes a string and returns a string from the "unix"
environment. Example: (getenv "HOME") => "/Users/aghuloum" (getenv "FOO") => ""
This commit is contained in:
parent
f417c7505b
commit
25555d7ff6
Binary file not shown.
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue