File: byte-order.lisp

package info (click to toggle)
ruby-unf-ext 0.0.7.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 5,472 kB
  • sloc: cpp: 14,118; lisp: 1,180; ruby: 94; makefile: 4
file content (16 lines) | stat: -rw-r--r-- 626 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
;# <- バイトオーダー判定用文字列
;; ファイル名: byte-order.lisp
(in-package :dawg.global)

(eval-when (:compile-toplevel :load-toplevel)
  (defun guess-byte-order (sample-file)
    (with-open-file (1byte sample-file :element-type '(unsigned-byte 8))
      (with-open-file (2byte sample-file :element-type '(unsigned-byte 16))
        (if (= (read-byte 2byte)
               (+ (ash (read-byte 1byte) 8) (read-byte 1byte)))
            :big
          :little)))))

(defconstant +NATIVE_ORDER+ (guess-byte-order (or *COMPILE-FILE-PATHNAME*
                                                  *LOAD-PATHNAME*)))