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)])
|
(let ([d (cdr args)])
|
||||||
(cond
|
(cond
|
||||||
[(null? d)
|
[(null? d)
|
||||||
(error #f "--script requires a script name")]
|
(error 'ikarus "--script requires a script name")]
|
||||||
[else
|
[else
|
||||||
(values '() (car d) 'script (cdr d))]))]
|
(values '() (car d) 'script (cdr d))]))]
|
||||||
[(string=? (car args) "--r6rs-script")
|
[(string=? (car args) "--r6rs-script")
|
||||||
(let ([d (cdr args)])
|
(let ([d (cdr args)])
|
||||||
(cond
|
(cond
|
||||||
[(null? d)
|
[(null? d)
|
||||||
(error #f "--r6rs-script requires a script name")]
|
(error 'ikarus "--r6rs-script requires a script name")]
|
||||||
[else
|
[else
|
||||||
(values '() (car d) 'r6rs-script (cdr d))]))]
|
(values '() (car d) 'r6rs-script (cdr d))]))]
|
||||||
[else
|
[else
|
||||||
|
|
|
@ -16,12 +16,12 @@
|
||||||
|
|
||||||
(library (ikarus posix)
|
(library (ikarus posix)
|
||||||
(export posix-fork fork waitpid system file-exists? delete-file
|
(export posix-fork fork waitpid system file-exists? delete-file
|
||||||
env environ)
|
getenv env environ)
|
||||||
(import
|
(import
|
||||||
(rnrs bytevectors)
|
(rnrs bytevectors)
|
||||||
(except (ikarus)
|
(except (ikarus)
|
||||||
posix-fork fork waitpid system file-exists? delete-file
|
posix-fork fork waitpid system file-exists? delete-file
|
||||||
env environ))
|
getenv env environ))
|
||||||
|
|
||||||
(define posix-fork
|
(define posix-fork
|
||||||
(lambda ()
|
(lambda ()
|
||||||
|
@ -96,6 +96,16 @@
|
||||||
[else "Unknown error while deleting"])
|
[else "Unknown error while deleting"])
|
||||||
x)]))))
|
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
|
(define env
|
||||||
(let ()
|
(let ()
|
||||||
(define env
|
(define env
|
||||||
|
|
|
@ -1266,6 +1266,7 @@
|
||||||
[string-normalize-nfkd r uc]
|
[string-normalize-nfkd r uc]
|
||||||
[string-titlecase r uc]
|
[string-titlecase r uc]
|
||||||
[string-upcase r uc]
|
[string-upcase r uc]
|
||||||
|
[getenv i]
|
||||||
[char-ready? ]
|
[char-ready? ]
|
||||||
[interaction-environment ]
|
[interaction-environment ]
|
||||||
[load i]
|
[load i]
|
||||||
|
|
|
@ -1036,21 +1036,21 @@ ikrt_waitpid(ikp pid){
|
||||||
}
|
}
|
||||||
|
|
||||||
ikp
|
ikp
|
||||||
ikrt_getenv(ikp str, ikpcb* pcb){
|
ikrt_getenv(ikp bv, ikpcb* pcb){
|
||||||
fprintf(stderr, "getenv busted!\n");
|
char* v = getenv((char*)bv + off_bytevector_data);
|
||||||
exit(-1);
|
|
||||||
char* v = getenv((char*)str + off_bytevector_data);
|
|
||||||
if(v){
|
if(v){
|
||||||
int n = strlen(v);
|
int n = strlen(v);
|
||||||
ikp s = ik_unsafe_alloc(pcb, align(n+disp_string_data+1)) + string_tag;
|
ikp s = ik_safe_alloc(pcb, align(n+disp_bytevector_data+1))
|
||||||
ref(s, -string_tag) = fix(n);
|
+ bytevector_tag;
|
||||||
memcpy(s+off_string_data, v, n+1);
|
ref(s, -bytevector_tag) = fix(n);
|
||||||
|
memcpy(s+off_bytevector_data, v, n+1);
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ikp s = ik_unsafe_alloc(pcb, align(disp_string_data+1)) + string_tag;
|
ikp s = ik_safe_alloc(pcb, align(disp_bytevector_data+1))
|
||||||
ref(s, -string_tag) = fix(0);
|
+ bytevector_tag;
|
||||||
ref(s, off_string_data) = 0;
|
ref(s, -bytevector_tag) = fix(0);
|
||||||
|
ref(s, off_bytevector_data) = 0;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue