[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How do I determine the length of resource forks from MCL?



>Date: Mon, 28 Sep 92 18:33:28 EDT
>From: dmg@goldilocks.LCS.MIT.EDU (David Goodine)
>To: info-mcl@cambridge.apple.com
>Cc: dmg@goldilocks.LCS.MIT.EDU
>Subject: How do I determine the length of resource forks from MCL?
>
>I'm trying to find a means of determining the resource fork size of
>files in the Mac filesystem.  I've spent some time looking through
>Inside Mac VI, and can't find out where the info is stored.  I expect
>that it is somehow accessible through a trap or function call but FInfo,
>DXInfo, et al, fall short.
>
>Any suggestions would be greatly appreciated, as I'm on a very tight
>deadline.  Please respond to me, as I'm not currently on the INFO-MCL
>mailing list.
>
>David Goodine
>MIT Spoken Language System Group
>
>

I had this code laying around - I can't promise that it'll work
in future releases of MCL, but it seems OK for now..

----------------------
(in-package ccl)

(defun open-block-readonly (namestring resource-fork-p)
  (%fopen namestring 0 $fsRdPerm resource-fork-p))

; Warning, may not work in future releases of MCL!
;
(defun file-fork-lengths (file)
  "Returns two values: the lengths of the data fork
   and the resource fork in bytes."
  (let ((filename (mac-namestring file))
        fblock dsize rsize)
    (unwind-protect
      (progn 
        (setf fblock (open-block-readonly filename nil))
        (setf dsize (%fsize fblock)))
      (when fblock 
        (%fclose fblock)
        (setf fblock nil)))
    (unwind-protect
      (progn 
        (setf fblock (open-block-readonly filename t))
        (setf rsize (%fsize fblock)))
      (when fblock 
        (%fclose fblock)))
    (values dsize rsize)))