* Added the primitive (environ):
returns an alist of (string x string) as obtained from the
system environ.
* Added the primitive env:
(env "key") retrieves the env value associated with key
(env "key" "val") sets the env value assocuated with key to val
(env "key" "val" overwrite?) same as above but it does not
overwrite an existing value of overwrite? is #f.
This commit is contained in:
Binary file not shown.
+1
-1
@@ -31,7 +31,7 @@
|
||||
(define binary-logand
|
||||
(lambda (x y)
|
||||
(cond
|
||||
[(fixnum? x)
|
||||
[(fixnum? x)
|
||||
(cond
|
||||
[(fixnum? y) (#%$fxlogand x y)]
|
||||
[(bignum? y)
|
||||
|
||||
+31
-2
@@ -69,6 +69,35 @@
|
||||
[else "Unknown error while deleting ~s"])
|
||||
x)]))))
|
||||
|
||||
(primitive-set! 'env
|
||||
(let ()
|
||||
(define env
|
||||
(case-lambda
|
||||
[(key)
|
||||
(if (string? key)
|
||||
(foreign-call "ikrt_getenv" key)
|
||||
(error 'env "the key: ~s is not a string" key))]
|
||||
[(key val) (env key val #t)]
|
||||
[(key val overwrite?)
|
||||
(if (string? key)
|
||||
(if (string? val)
|
||||
(unless (foreign-call "ikrt_setenv" key val overwrite?)
|
||||
(error 'env "failed to set ~s to ~s" key val))
|
||||
(error 'env "the value: ~s is not a string" val))
|
||||
(error 'env "the key: ~s is not a string" key))]))
|
||||
env))
|
||||
|
||||
|
||||
|
||||
(primitive-set! '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)
|
||||
(substring s (fxadd1 i) n)))))
|
||||
(foreign-call "ikrt_environ"))))
|
||||
|
||||
+2
-2
@@ -86,7 +86,7 @@
|
||||
make-guardian weak-cons collect
|
||||
interrupt-handler
|
||||
time-it
|
||||
posix-fork fork waitpid
|
||||
posix-fork fork waitpid env environ
|
||||
))
|
||||
|
||||
(define system-primitives
|
||||
@@ -266,7 +266,7 @@
|
||||
(when (eq? who (caddr x))
|
||||
(compile-library (car x) (cadr x))))
|
||||
scheme-library-files))
|
||||
; (define (time x) x)
|
||||
(define (time x) x)
|
||||
(fork
|
||||
(lambda (pid)
|
||||
(time (compile-all 'p1))
|
||||
|
||||
Reference in New Issue
Block a user