#| -*-Scheme-*-
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/runtime/unxprm.scm,v 1.18 1992/05/26 05:55:47 mhwu Exp $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/runtime/unxprm.scm,v 1.19 1992/07/07 00:44:54 jinx Exp $
-Copyright (c) 1988-91 Massachusetts Institute of Technology
+Copyright (c) 1988-1992 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
(define (call-with-temporary-filename receiver)
(let find-eligible-directory
- ((eligible-directories '("." "/tmp" "/usr/tmp")))
+ ((eligible-directories
+ (let ((tmp (or (get-environment-variable "TEMP")
+ (get-environment-variable "TMP")))
+ (others '("." "/tmp" "/usr/tmp")))
+ (if (not tmp) others (cons tmp others)))))
(if (null? eligible-directories)
(error "Can't locate directory for temporary file")
(let ((dir (->namestring
(lambda () (if (file-exists? name)
(delete-file name))))))))
(find-eligible-directory (cdr eligible-directories)))))))
-
\f
(define (file-attributes-direct filename)
((ucode-primitive file-attributes)
(define file-modification-time
file-modification-time-indirect)
\f
-(define-integrable get-environment-variable
- (ucode-primitive get-environment-variable))
-
+(define get-environment-variable)
+(define set-environment-variable!)
+(define delete-environment-variable!)
+(define reset-environment-variables!)
+
+(let ((environment-variables '()))
+ ;; Kludge: since getenv returns false for unbound,
+ ;; that can also be the marker for a deleted variable
+ (define-integrable *variable-deleted* false)
+
+ (set! get-environment-variable
+ (lambda (variable)
+ (cond ((not (string? variable))
+ (error "GET-ENVIRONMENT-VARIABLE: Variable must be a string"
+ variable))
+ ((assoc variable environment-variables)
+ =>
+ cdr)
+ (else ((ucode-primitive get-environment-variable)
+ variable)))))
+
+ (set! set-environment-variable!
+ (lambda (variable value)
+ (cond ((not (string? variable))
+ (error "SET-ENVIRONMENT-VARIABLE!: Variable must be a string"
+ variable value))
+ ((assoc variable environment-variables)
+ =>
+ (lambda (pair)
+ (set-cdr! pair value)))
+ (else
+ (set! environment-variables
+ (cons (cons variable value)
+ environment-variables))))
+ unspecific))
+
+ (set! delete-environment-variable!
+ (lambda (variable)
+ (set-environment-variable! variable *variable-deleted*)))
+
+ (set! reset-environment-variables!
+ (lambda () (set! environment-variables '())))
+) ; End LET
+\f
(define (unix/user-home-directory user-name)
(let ((directory ((ucode-primitive get-user-home-directory) user-name)))
(if (not directory)
((ucode-primitive file-touch) (->namestring (merge-pathnames filename))))
(define (make-directory name)
- ((ucode-primitive directory-make)
- (->namestring (pathname-as-directory (merge-pathnames name)))))
\ No newline at end of file
+ ((ucode-primitive directory-make 1)
+ (->namestring (pathname-as-directory (merge-pathnames name)))))
+
+(define (delete-directory name)
+ ((ucode-primitive directory-delete 1)
+ (->namestring (pathname-as-directory (merge-pathnames name)))))
+\f
+;;; Queues after-restart daemon to clean up environment space
+
+(define (initialize-system-primitives!)
+ (add-event-receiver! event:after-restart reset-environment-variables!))
\ No newline at end of file