Changeset 6634


Ignore:
Timestamp:
May 31, 2007, 5:09:33 PM (17 years ago)
Author:
Gary Byers
Message:

Define UID-FROM-NAME, TILDE-EXPAND. Use TILDE-EXPAND in %REALPATH, but
any leading tildes should probably have been caught earlier.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/level-1/linux-files.lisp

    r6496 r6634  
    344344      (fd-set-flags fd (logandc2 old mask)))))
    345345
     346
     347;;; Assume that any quoting's been removed already.
     348(defun tilde-expand (namestring)
     349  (let* ((len (length namestring)))
     350    (if (or (zerop len)
     351            (not (eql (schar namestring 0) #\~)))
     352      namestring
     353      (if (or (= len 1)
     354              (eql (schar namestring 1) #\/))
     355        (concatenate 'string (get-user-home-dir (getuid)) (if (= len 1) "/" (subseq namestring 1)))
     356        (let* ((slash-pos (position #\/ namestring))
     357               (user-name (subseq namestring 1 slash-pos))
     358               (uid (or (get-uid-from-name user-name)
     359                        (error "Unknown user ~s in namestring ~s" user-name namestring))))
     360          (concatenate 'string (get-user-home-dir uid) (if slash-pos (subseq namestring slash-pos) "/")))))))
     361
     362                     
     363   
    346364;;; This doesn't seem to exist on VxWorks.  It's a POSIX
    347365;;; function AFAIK, so the source should be somewhere ...
     
    351369    (setq namestring (current-directory-name)))
    352370  (%stack-block ((resultbuf #$PATH_MAX))
    353     (with-cstrs ((name namestring))
     371    (with-cstrs ((name (tilde-expand namestring)))
    354372      (let* ((result (#_realpath name resultbuf)))
    355373        (declare (dynamic-extent result))
     
    417435         
    418436
     437(defun get-uid-from-name (name)
     438  (with-cstrs ((name name))
     439    (let* ((pwent (#_getpwnam name)))
     440      (unless (%null-ptr-p pwent)
     441        (pref pwent :passwd.pw_uid)))))
     442
     443   
    419444(defun isatty (fd)
    420445  (= 1 (#_isatty fd)))
Note: See TracChangeset for help on using the changeset viewer.