Function: bindat--pack-strz
bindat--pack-strz is a byte-compiled function defined in bindat.el.gz.
Signature
(bindat--pack-strz LEN V)
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/bindat.el.gz
(defun bindat--pack-strz (len v)
(let* ((v (string-to-unibyte v))
(vlen (length v)))
;; Explicitly write a null terminator (if there's room) in case
;; the user provided a pre-allocated string to `bindat-pack' that
;; wasn't already zeroed.
(when (or (null len) (< vlen len))
(aset bindat-raw (+ bindat-idx vlen) 0))
(if len
;; When len is specified, behave the same as the str type
;; (except for the null terminator possibly written above).
(bindat--pack-str len v)
(dotimes (i vlen)
(when (= (aref v i) 0)
;; Alternatively we could pretend that this was the end of
;; the string and stop packing, but then bindat-length would
;; need to scan the input string looking for a null byte.
(error "Null byte encountered in input strz string"))
(aset bindat-raw (+ bindat-idx i) (aref v i)))
(setq bindat-idx (+ bindat-idx vlen 1)))))