+(define-alien-type-translator c-string
+ (&key (external-format :default)
+ (element-type 'character)
+ (not-null nil))
+ (make-alien-c-string-type
+ :to (parse-alien-type 'char (sb!kernel:make-null-lexenv))
+ :element-type element-type
+ :external-format external-format
+ :not-null not-null))
+
+(defun c-string-external-format (type)
+ (let ((external-format (alien-c-string-type-external-format type)))
+ (if (eq external-format :default)
+ (default-c-string-external-format)
+ external-format)))
+
+(define-alien-type-method (c-string :unparse) (type)
+ (let* ((external-format (alien-c-string-type-external-format type))
+ (element-type (alien-c-string-type-element-type type))
+ (not-null (alien-c-string-type-not-null type))
+ (tail
+ (append (unless (eq :default external-format)
+ (list :external-format external-format))
+ (unless (eq 'character element-type)
+ (list :element-type element-type))
+ (when not-null
+ (list :not-null t)))))
+ (if tail
+ (cons 'c-string tail)
+ 'c-string)))