+
+(defun foreign-encoded-string-octets (str &optional foreign-encoding)
+ "Returns the octets required to represent the string when passed to a ~
+foreign function."
+ ;; AllegroCL, CCL, and Lispworks give correct value without converting
+ ;; to external-format. CLISP, like SBCL, requires conversion with external-
+ ;; format
+ (length #+(and sbcl sb-unicode)
+ (sb-ext:string-to-octets
+ str
+ :external-format (or foreign-encoding
+ *default-foreign-encoding*
+ :utf-8))
+ #-(and sbcl sb-unicode) str))