Read an entire file into a list of (unsigned) bytes.
Signature: (read-file-bytes filename state) returns
On success,
On failure, e.g., perhaps
Function:
(defun read-file-bytes (filename state) "Returns (MV ERRMSG/BYTES STATE)" (declare (xargs :guard (and (state-p state) (stringp filename)))) (b* ((filename (mbe :logic (if (stringp filename) filename "") :exec filename)) ((mv channel state) (open-input-channel filename :byte state)) ((unless channel) (mv (concatenate 'string "Error opening file " filename) state)) ((mv data state) (read-byte$-all channel state)) (state (close-input-channel channel state))) (mv data state)))
Theorem:
(defthm state-p1-of-read-file-bytes (implies (force (state-p1 state)) (state-p1 (mv-nth 1 (read-file-bytes filename state)))))
Theorem:
(defthm integer-listp-of-read-file-bytes (equal (integer-listp (mv-nth 0 (read-file-bytes filename state))) (not (stringp (mv-nth 0 (read-file-bytes filename state))))))
Theorem:
(defthm nat-listp-of-read-file-bytes (equal (nat-listp (mv-nth 0 (read-file-bytes filename state))) (not (stringp (mv-nth 0 (read-file-bytes filename state))))))
Theorem:
(defthm unsigned-byte-listp-of-read-file-bytes (equal (unsigned-byte-listp 8 (mv-nth 0 (read-file-bytes filename state))) (not (stringp (mv-nth 0 (read-file-bytes filename state))))))
Theorem:
(defthm type-of-read-file-bytes (or (true-listp (mv-nth 0 (read-file-bytes filename state))) (stringp (mv-nth 0 (read-file-bytes filename state)))) :rule-classes :type-prescription)