Raymond Toy pushed to branch issue-269-unix-get-user-homedir at cmucl / cmucl

Commits:

7 changed files:

Changes:

  • src/code/exports.lisp
    ... ... @@ -1712,9 +1712,7 @@
    1712 1712
     	   "DESCRIBE-EXTERNAL-FORMAT"
    
    1713 1713
     	   "LIST-ALL-EXTERNAL-FORMATS"
    
    1714 1714
     	   "STRING-ENCODE" "STRING-DECODE"
    
    1715
    -	   "SET-SYSTEM-EXTERNAL-FORMAT")
    
    1716
    -  ;; File sys items
    
    1717
    -  (:export "GET-USER-HOMEDIR-PATHNAME"))
    
    1715
    +	   "SET-SYSTEM-EXTERNAL-FORMAT"))
    
    1718 1716
     
    
    1719 1717
     (defpackage "STREAM"
    
    1720 1718
       (:import-from "SYSTEM" "LISP-STREAM")
    
    ... ... @@ -2073,6 +2071,7 @@
    2073 2071
     	   "FD-STREAM-P" "FIND-IF-IN-CLOSURE" "FOREIGN-SYMBOL-ADDRESS"
    
    2074 2072
     	   "FOREIGN-SYMBOL-CODE-ADDRESS" "FOREIGN-SYMBOL-DATA-ADDRESS"
    
    2075 2073
     	   "GET-PAGE-SIZE" "GET-SYSTEM-INFO"
    
    2074
    +           "GET-USER-HOMEDIR-PATHNAME"
    
    2076 2075
     	   "IGNORE-INTERRUPT"
    
    2077 2076
     	   "INT-SAP" "INVALIDATE-DESCRIPTOR" "IO-TIMEOUT"
    
    2078 2077
     	   "LISP-STREAM" "LONG-FLOAT-RADIX" "LONG-WORDS"
    

  • src/code/filesys.lisp
    ... ... @@ -1484,28 +1484,3 @@ optionally keeping some of the most recent old versions."
    1484 1484
     				(go retry))))))
    
    1485 1485
     	 ;; Only the first path in a search-list is considered.
    
    1486 1486
     	 (return (values pathspec created-p))))))
    1487
    -
    
    1488
    -;;; GET-USER-HOMEDIR-PATHNAME  -- Public
    
    1489
    -;;;
    
    1490
    -(defun get-user-homedir-pathname (name)
    
    1491
    -  _N"Get the user home directory for user named NAME.  Two values are
    
    1492
    -  returned: the pathname of the home directory and a status code.  If
    
    1493
    -  the home directory does not exist NIL is returned.  The status is 0
    
    1494
    -  if no errors occurred.  Otherwise a non-zero value is returned.
    
    1495
    -  Examining errno may give information about what failed."
    
    1496
    -  (alien:with-alien ((status c-call:int))
    
    1497
    -    (let ((result
    
    1498
    -            (alien:alien-funcall
    
    1499
    -             (alien:extern-alien "os_get_user_homedir"
    
    1500
    -                                 (function c-call:c-string
    
    1501
    -                                           c-call:c-string
    
    1502
    -                                           (* c-call:int)))
    
    1503
    -             name
    
    1504
    -             (alien:addr status))))
    
    1505
    -      (if (and (zerop status) result)
    
    1506
    -          (values (pathname
    
    1507
    -                   (concatenate 'string
    
    1508
    -                                result
    
    1509
    -                                "/"))
    
    1510
    -                  status)
    
    1511
    -          (values result status)))))

  • src/code/os.lisp
    ... ... @@ -57,3 +57,28 @@
    57 57
     	(error (intl:gettext "Unix system call getrusage failed: ~A.")
    
    58 58
     	       (unix:get-unix-error-msg utime)))
    
    59 59
           (values utime stime major-fault))))
    
    60
    +
    
    61
    +;;; GET-USER-HOMEDIR-PATHNAME  -- Public
    
    62
    +;;;
    
    63
    +(defun get-user-homedir-pathname (name)
    
    64
    +  _N"Get the user home directory for user named NAME.  Two values are
    
    65
    +  returned: the pathname of the home directory and a status code.  If
    
    66
    +  the home directory does not exist NIL is returned.  The status is 0
    
    67
    +  if no errors occurred.  Otherwise a non-zero value is returned.
    
    68
    +  Examining errno may give information about what failed."
    
    69
    +  (alien:with-alien ((status c-call:int))
    
    70
    +    (let ((result
    
    71
    +            (alien:alien-funcall
    
    72
    +             (alien:extern-alien "os_get_user_homedir"
    
    73
    +                                 (function c-call:c-string
    
    74
    +                                           c-call:c-string
    
    75
    +                                           (* c-call:int)))
    
    76
    +             name
    
    77
    +             (alien:addr status))))
    
    78
    +      (if (and (zerop status) result)
    
    79
    +          (values (pathname
    
    80
    +                   (concatenate 'string
    
    81
    +                                result
    
    82
    +                                "/"))
    
    83
    +                  status)
    
    84
    +          (values result status)))))

  • src/i18n/locale/cmucl-os.pot
    ... ... @@ -33,3 +33,12 @@ msgstr ""
    33 33
     msgid "Unix system call getrusage failed: ~A."
    
    34 34
     msgstr ""
    
    35 35
     
    
    36
    +#: src/code/os.lisp
    
    37
    +msgid ""
    
    38
    +"Get the user home directory for user named NAME.  Two values are\n"
    
    39
    +"  returned: the pathname of the home directory and a status code.  If\n"
    
    40
    +"  the home directory does not exist NIL is returned.  The status is 0\n"
    
    41
    +"  if no errors occurred.  Otherwise a non-zero value is returned.\n"
    
    42
    +"  Examining errno may give information about what failed."
    
    43
    +msgstr ""
    
    44
    +

  • src/i18n/locale/cmucl.pot
    ... ... @@ -10207,15 +10207,6 @@ msgstr ""
    10207 10207
     msgid "Can't create directory ~A."
    
    10208 10208
     msgstr ""
    
    10209 10209
     
    
    10210
    -#: src/code/filesys.lisp
    
    10211
    -msgid ""
    
    10212
    -"Get the user home directory for user named NAME.  Two values are\n"
    
    10213
    -"  returned: the pathname of the home directory and a status code.  If\n"
    
    10214
    -"  the home directory does not exist NIL is returned.  The status is 0\n"
    
    10215
    -"  if no errors occurred.  Otherwise a non-zero value is returned.\n"
    
    10216
    -"  Examining errno may give information about what failed."
    
    10217
    -msgstr ""
    
    10218
    -
    
    10219 10210
     #: src/code/load.lisp
    
    10220 10211
     msgid "The default for the :IF-SOURCE-NEWER argument to load."
    
    10221 10212
     msgstr ""
    

  • tests/filesys.lisp
    ... ... @@ -54,37 +54,3 @@
    54 54
     	 (assert-equal "/tmp/foo/bar/symlink"
    
    55 55
     		       (ext:unix-namestring "/tmp/foo/bar/symlink" nil)))
    
    56 56
         (unix:unix-unlink "/tmp/foo/bar/symlink")))
    57
    -
    
    58
    -(define-test user-homedir.1
    
    59
    -  "Test user-homedir"
    
    60
    -  (:tag :issues)
    
    61
    -  ;; Simple test to see if get-user-homedir-pathname returns the
    
    62
    -  ;; expected value.  Use getuid and getpwuid to figure out what the
    
    63
    -  ;; name and home directory should be.
    
    64
    -  (let* ((uid (unix:unix-getuid))
    
    65
    -         (user-info (unix:unix-getpwuid uid)))
    
    66
    -    (assert-true uid)
    
    67
    -    (assert-true user-info)
    
    68
    -    (let* ((info-dir (unix:user-info-dir user-info))
    
    69
    -           (info-name (unix:user-info-name user-info))
    
    70
    -           (expected-home-pathname (pathname
    
    71
    -                                    (concatenate 'string info-dir "/"))))
    
    72
    -      (multiple-value-bind (home-pathname status)
    
    73
    -          (ext:get-user-homedir-pathname info-name)
    
    74
    -        (assert-true info-dir)
    
    75
    -        (assert-true info-name)
    
    76
    -
    
    77
    -        (assert-equal home-pathname expected-home-pathname)
    
    78
    -        (assert-eql status 0)))))
    
    79
    -
    
    80
    -(define-test user-homedir.2
    
    81
    -  "Test user-homedir"
    
    82
    -  (:tag :issues)
    
    83
    -  ;; Simple test to see if get-user-homedir-pathname returns the expected
    
    84
    -  ;; value for a user that does not exist.  Well, we assume such a
    
    85
    -  ;; user doesn't exist.
    
    86
    -      (multiple-value-bind (home-pathname status)
    
    87
    -          (ext:get-user-homedir-pathname "zotuserunknown")
    
    88
    -        (assert-eql home-pathname nil)
    
    89
    -        (assert-eql status 0)))    
    
    90
    -  

  • tests/os.lisp
    1
    +(defpackage :os-tests
    
    2
    +  (:use :cl :lisp-unit))
    
    3
    +
    
    4
    +(in-package "OS-TESTS")
    
    5
    +
    
    6
    +
    
    7
    +(define-test user-homedir.1
    
    8
    +  "Test user-homedir"
    
    9
    +  (:tag :issues)
    
    10
    +  ;; Simple test to see if get-user-homedir-pathname returns the
    
    11
    +  ;; expected value.  Use getuid and getpwuid to figure out what the
    
    12
    +  ;; name and home directory should be.
    
    13
    +  (let* ((uid (unix:unix-getuid))
    
    14
    +         (user-info (unix:unix-getpwuid uid)))
    
    15
    +    (assert-true uid)
    
    16
    +    (assert-true user-info)
    
    17
    +    (let* ((info-dir (unix:user-info-dir user-info))
    
    18
    +           (info-name (unix:user-info-name user-info))
    
    19
    +           (expected-home-pathname (pathname
    
    20
    +                                    (concatenate 'string info-dir "/"))))
    
    21
    +      (multiple-value-bind (home-pathname status)
    
    22
    +          (system:get-user-homedir-pathname info-name)
    
    23
    +        (assert-true info-dir)
    
    24
    +        (assert-true info-name)
    
    25
    +
    
    26
    +        (assert-equal home-pathname expected-home-pathname)
    
    27
    +        (assert-eql status 0)))))
    
    28
    +
    
    29
    +(define-test user-homedir.2
    
    30
    +  "Test user-homedir"
    
    31
    +  (:tag :issues)
    
    32
    +  ;; Simple test to see if get-user-homedir-pathname returns the expected
    
    33
    +  ;; value for a user that does not exist.  Well, we assume such a
    
    34
    +  ;; user doesn't exist.
    
    35
    +      (multiple-value-bind (home-pathname status)
    
    36
    +          (system:get-user-homedir-pathname "zotuserunknown")
    
    37
    +        (assert-eql home-pathname nil)
    
    38
    +        (assert-eql status 0)))