Fixed environ. The procedure environ takes no arguments and returns

an association list where both keys and values and strings found in
the posix environment.
This commit is contained in:
Abdulaziz Ghuloum 2009-04-06 09:59:07 +03:00
parent 7b60ec46a9
commit b97cbf1688
4 changed files with 25 additions and 21 deletions

View File

@ -371,22 +371,22 @@
busted))
(define environ (lambda args (die 'environ "busted!")))
(define environ^
(define environ
(lambda ()
(map
(lambda (s)
(define (loc= s i n)
(cond
[(fx= i n) i]
[(char=? (string-ref s i) #\=) i]
[else (loc= s (fx+ i 1) n)]))
(let ([n (string-length s)])
(let ([i (loc= s 0 n)])
(cons (substring s 0 i)
(if (fx< (fxadd1 i) n)
(substring s (fxadd1 i) n)
"")))))
(lambda (bv)
(let ([s (utf8->string bv)])
(define (loc= s i n)
(cond
[(fx= i n) i]
[(char=? (string-ref s i) #\=) i]
[else (loc= s (fx+ i 1) n)]))
(let ([n (string-length s)])
(let ([i (loc= s 0 n)])
(cons (substring s 0 i)
(if (fx< (fxadd1 i) n)
(substring s (fxadd1 i) n)
""))))))
(foreign-call "ikrt_environ"))))
(define (nanosleep secs nsecs)

View File

@ -1 +1 @@
1746
1748

View File

@ -1357,6 +1357,7 @@
[getenv i]
[setenv i]
[unsetenv i]
[environ i]
[nanosleep i]
[char-ready? ]
[load i]

View File

@ -972,21 +972,24 @@ ikrt_unsetenv(ikptr key){
ikptr
ikrt_environ(ikpcb* pcb){
fprintf(stderr, "environ busted!\n");
exit(-1);
char** es = environ;
int i; char* e;
ikptr ac = null_object;
pcb->root0 = &ac;
for(i=0; (e=es[i]); i++){
long int n = strlen(e);
ikptr s = ik_unsafe_alloc(pcb, align(n+disp_string_data+1)) + string_tag;
ref(s, -string_tag) = fix(n);
memcpy((char*)(long)(s+off_string_data), e, n+1);
ikptr p = ik_unsafe_alloc(pcb, pair_size) + pair_tag;
ikptr s = ik_safe_alloc(pcb, align(n+disp_bytevector_data+1))
+ bytevector_tag;
ref(s, -bytevector_tag) = fix(n);
memcpy((char*)(long)(s+off_bytevector_data), e, n+1);
pcb->root1 = &s;
ikptr p = ik_safe_alloc(pcb, pair_size) + pair_tag;
pcb->root1 = 0;
ref(p, off_cdr) = ac;
ref(p, off_car) = s;
ac = p;
}
pcb->root0 = 0;
return ac;
}