Module: system-internals Author: Gary Palter Copyright: Original Code is Copyright (c) 1995-2004 Functional Objects, Inc. All rights reserved. License: Functional Objects Library Public License Version 1.0 Dual-license: GNU Lesser General Public License Warranty: Distributed WITHOUT WARRANTY OF ANY KIND define constant $os-variant = $os-name; define constant $os-version = "Unknown"; define constant $command-line-option-prefix = '-'; define function command-line-option-prefix () => (prefix :: ) $command-line-option-prefix end function command-line-option-prefix; define function login-name () => (name :: false-or()) let value = primitive-wrap-machine-word (primitive-cast-pointer-as-raw (%call-c-function ("getlogin") () => (name :: ) () end)); if (primitive-machine-word-not-equal?(primitive-unwrap-machine-word(value), integer-as-raw(0))) primitive-raw-as-string (primitive-cast-raw-as-pointer(primitive-unwrap-machine-word(value))) else #f end end function login-name; define function login-group () => (group :: false-or()) let group = primitive-wrap-machine-word (%call-c-function ("getgid") () => (gid :: ) () end); let value = primitive-wrap-machine-word (primitive-cast-pointer-as-raw (%call-c-function ("getgrgid") (gid :: ) => (group :: ) (primitive-unwrap-machine-word(group)) end)); if (primitive-machine-word-not-equal?(primitive-unwrap-machine-word(value), integer-as-raw(0))) group-name(value) else #f end end function login-group; ///---*** NOTE: Provide a non-null implementation when time permits... define function owner-name () => (name :: false-or()) #f end function owner-name; ///---*** NOTE: Provide a non-null implementation when time permits... define function owner-organization () => (organization :: false-or()) #f end function owner-organization; define constant $environment-variable-delimiter = ':'; define function environment-variable (name :: ) => (value :: false-or()) let value = primitive-wrap-machine-word (primitive-cast-pointer-as-raw (%call-c-function ("getenv") (name :: ) => (value :: ) (primitive-string-as-raw(name)) end)); if (primitive-machine-word-not-equal?(primitive-unwrap-machine-word(value), integer-as-raw(0))) let value :: = primitive-raw-as-string (primitive-cast-raw-as-pointer(primitive-unwrap-machine-word(value))); value.size > 0 & value else #f end end function environment-variable; define function environment-variable-setter (new-value :: false-or(), name :: ) => (new-value :: false-or()) let thing = concatenate-as(, name, "=", new-value | ""); //--- NOTE: The string passed to putenv must be statically allocated //--- as it will remain in use after this function returns to its caller. let static-thing = primitive-wrap-machine-word (primitive-cast-pointer-as-raw (%call-c-function ("GC_malloc") (nbytes :: ) => (p :: ) (integer-as-raw(size(thing) + 1)) end)); if (primitive-machine-word-not-equal?(primitive-unwrap-machine-word(static-thing), integer-as-raw(0))) //--- NOTE: We can't use primitive-replace-bytes! as our //--- first argument isn't a Dylan object. (Sigh) %call-c-function ("memcpy") (dst :: , src :: , n-bytes :: ) => (dst :: ) (primitive-cast-raw-as-pointer(primitive-unwrap-machine-word(static-thing)), primitive-string-as-raw(thing), integer-as-raw(size(thing))) end; //---*** Should we signal something if this call fails? %call-c-function ("putenv") (new-value :: ) => (result :: ) (primitive-cast-raw-as-pointer(primitive-unwrap-machine-word(static-thing))) end end; new-value end function environment-variable-setter; ///---*** NOTE: Should change this to use exec so we can capture I/O, etc ... define function run-application (command :: , #key, #all-keys) => (status :: ) raw-as-integer(primitive-run-application(primitive-string-as-raw(command))) end function run-application; ///---*** NOTE: The following functions need real implementations! define function create-application-event (event :: ) => (event-object :: ) as(, 0) end function create-application-event; define constant $INFINITE_TIMEOUT = -1; define function wait-for-application-event (event-object :: , #key timeout :: = $INFINITE_TIMEOUT) => (success? :: ) #t end function wait-for-application-event; define function signal-application-event (event :: ) => (success? :: ) #t end function signal-application-event; define function load-library (name :: ) => (module) #f end function load-library;