Changeset 14581 for trunk/source/level-1


Ignore:
Timestamp:
Jan 18, 2011, 3:14:44 AM (9 years ago)
Author:
gb
Message:

Provide hand-rolled version of %OPEN-DIR, CLOSE-DIR, and %READ-DIR
for Win64. (The versions of the underlying functions defined in
the static mingw C library have changed over time.)

File:
1 edited

Legend:

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

    r14551 r14581  
    795795  (= 1 (#_isatty fd)))
    796796
     797#-win64-target
     798(progn
    797799(defun %open-dir (namestring)
    798800  (with-filename-cstrs ((name namestring))
     
    816818                                    #+windows-target :_wdirent.d_name
    817819                                    #-windows-target :dirent.d_name)))))
     820)
     821
     822#+win64-target
     823(progn
     824  (eval-when (:compile-toplevel :execute)
     825    (def-foreign-type nil
     826        (:struct :win64-dir
     827                 (:data #>WIN32_FIND_DATAW)
     828                 (:handle :address)
     829                 (:state :int))))
     830
     831(defun %open-dir (namestring)
     832  ;;; Namestring should end in /*.  Honest.
     833  (let* ((len (length namestring))
     834         (lastchar (if (> len 0) (schar namestring (1- len))))
     835         (penultimatechar (if (> len 1) (schar namestring (- len 2)))))
     836    (unless (and (eql lastchar #\*)
     837                 (or (eql penultimatechar #\\)
     838                     (eql penultimatechar #\/)))
     839      (if (or (eql lastchar #\\)
     840              (eql lastchar #\/))
     841        (setq namestring (concatenate 'string namestring "*"))
     842        (setq namestring (concatenate 'string namestring "/*")))))
     843  (let* ((dir (make-record :win64-dir :state -1)))
     844    (with-filename-cstrs ((name namestring))
     845      (let* ((handle (#_FindFirstFileW name dir)))
     846        (cond ((eql handle #$INVALID_HANDLE_VALUE)
     847               (free dir)
     848               nil)
     849              (t
     850               (setf (pref dir :win64-dir.state) 0
     851                     (pref dir :win64-dir.handle) handle)
     852               dir))))))
     853         
     854(defun %read-dir (dir)
     855  (when (eql 0 (pref dir :win64-dir.state))
     856    (prog1
     857        (get-foreign-namestring (pref dir  #>WIN32_FIND_DATAW.cFileName))
     858      (if (eql 0 (#_FindNextFileW (pref dir :win64-dir.handle) dir))
     859        (setf (pref dir :win64-dir.state) -1)))))
     860
     861(defun close-dir (dir)
     862  (#_FindClose (pref dir :win64-dir.handle))
     863  (free dir)
     864  nil)
     865)
     866                       
     867 
     868
     869                         
    818870
    819871
Note: See TracChangeset for help on using the changeset viewer.