+
+(defun string-to-octets (str &key foreign-encoding)
+ "Converts a Lisp string to a vector of octets."
+ #-(or allegro lispworks openmcl sbcl)
+ (declare (ignore foreign-encoding))
+ #-(or allegro lispworks openmcl sbcl)
+ (map-into (make-array len :element-type '(unsigned-byte 8))
+ #'char-code str)
+
+ #+allegro
+ (excl:string-to-native str :external-format foreign-encoding :null-terminate nil)
+
+ #+(or lispworks openmcl)
+ ;; simply reading each char-code from the LENGTH of string handles multibyte characters
+ ;; just fine in testing LW 6.0 and CCL 1.4
+ (map-into (make-array len :element-type '(unsigned-byte 8))
+ #'char-code str)
+
+ #+sbcl
+ (sb-ext:string-to-native str :external-format foreign-encoding)
+
+)
+