Eliminate style-warning about undefined type GLOBAL-VAR
[sbcl.git] / src / code / common-os.lisp
blob74bded4a3c4051475cda2f79b8d14420bf4797bd
1 ;;;; OS interface functions for SBCL common to all target OSes
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; This software is derived from the CMU CL system, which was
7 ;;;; written at Carnegie Mellon University and released into the
8 ;;;; public domain. The software is in the public domain and is
9 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
10 ;;;; files for more information.
12 (in-package "SB!SYS")
14 (defvar *software-version* nil)
16 (sb!alien:define-alien-variable ("posix_argv" *native-posix-argv*) (* (* char)))
17 (sb!alien:define-alien-variable ("core_string" *native-core-string*) (* char))
18 (sb!alien:define-alien-routine
19 os-get-runtime-executable-path sb!alien:c-string (external-path boolean))
20 (sb!alien:define-alien-variable
21 ("saved_runtime_path" *native-saved-runtime-path*) (* char))
23 (defmacro init-var-ignoring-errors (variable
24 form
25 &key default
26 explanation
27 (condition 'error))
28 `(setf ,variable
29 (handler-case ,form
30 (,condition (c)
31 (let ((default ,default))
32 (warn "Error initializing ~a~@[ ~a~]:~@
34 ~% Using ~s instead."
35 ',variable
36 ,explanation
38 default)
39 default)))))
41 ;;; If something ever needs to be done differently for one OS, then
42 ;;; split out the different part into per-os functions.
44 (defun os-deinit ()
45 (setf *default-pathname-defaults* (make-trivial-default-pathname)
46 *core-string* ""
47 *software-version* nil
48 *runtime-pathname* nil
49 *core-pathname* nil
50 *posix-argv* nil)
51 (sb!impl::%makunbound '*machine-version*))
53 (defun os-cold-init-or-reinit ()
54 (/show0 "entering OS-COLD-INIT-OR-REINIT")
55 (/show0 "setting *CORE-STRING*")
56 (init-var-ignoring-errors
57 *core-string*
58 (sb!alien:cast *native-core-string* sb!alien:c-string)
59 :default "")
60 (/show0 "setting *POSIX-ARGV*")
61 (init-var-ignoring-errors
62 *posix-argv*
63 (loop for i from 0
64 for arg = (sb!alien:deref *native-posix-argv* i)
65 until (sb!alien:null-alien arg)
66 collect (sb!alien:cast arg sb!alien:c-string)))
67 (/show0 "setting *DEFAULT-PATHNAME-DEFAULTS*")
68 ;; Temporary value, so that #'PARSE-NATIVE-NAMESTRING won't blow up
69 ;; when we call it below.
70 (setf *default-pathname-defaults* (make-trivial-default-pathname))
71 (init-var-ignoring-errors
72 *default-pathname-defaults*
73 (parse-native-namestring (sb!unix:posix-getcwd/))
74 :default *default-pathname-defaults*
75 :explanation "with the current directory")
76 (/show0 "setting *CORE-PATHNAME*")
77 (setf *core-pathname* (merge-pathnames (native-pathname *core-string*)))
78 (/show0 "setting *RUNTIME-PATHNAME*")
79 (init-var-ignoring-errors
80 *runtime-pathname*
81 (let ((exe (os-get-runtime-executable-path t))
82 (saved (sb!alien:cast *native-saved-runtime-path* sb!alien:c-string)))
83 (when (or exe saved) (native-pathname (or exe saved)))))
84 (/show0 "leaving OS-COLD-INIT-OR-REINIT"))