Changeset 11058


Ignore:
Timestamp:
Oct 12, 2008, 8:03:48 AM (11 years ago)
Author:
gb
Message:

Now that it's a little easier to call fstat early, use it to determine
the size of an open file in FD-SIZE (rather than 3 calls to lseek.)
Note that this can give different results in some cases: fstat will
claim that /proc/cpuinfo has a size of 0, while lseeking to the end
of it yielded an error.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/level-0/l0-io.lisp

    r10990 r11058  
    238238;;; that handles 64-bit file offsets.
    239239(defun fd-size (fd)
    240   (without-interrupts
    241    (let* ((curpos (fd-lseek fd 0 #$SEEK_CUR)))
    242      (unwind-protect
    243           (fd-lseek fd 0 #$SEEK_END)
    244        (fd-lseek fd curpos #$SEEK_SET)))))
     240  (rlet ((stat #+win64-target #>_stat64 #+win32-target #>__stat64 #-windows-target :stat))
     241    (if (eql 0 (ff-call (%kernel-import target::kernel-import-lisp-fstat)
     242                        :int fd
     243                        :address stat
     244                        :int))
     245      (pref stat
     246            #-windows-target :stat.st_size
     247            #+win64-target #>_stat64.st_size
     248            #+win32-target #>__stat64.st_size)
     249      -1)))
     250
    245251
    246252(defun fd-ftruncate (fd new)
Note: See TracChangeset for help on using the changeset viewer.