-(defun char-ptr-points-to-null (char-ptr)
- "Returns T if foreign character pointer refers to 'NULL' string. Only called for numeric entries"
- ;; Uses short cut and returns T if first character is #\N. It should
- ;; never be non-numeric
- (declare (type char-ptr-def char-ptr))
- (let ((char (uffi:ensure-char-character
- (uffi:deref-pointer char-ptr :char))))
- (eql char #\N)))
-
-(defun convert-raw-field (char-ptr types index)
- (let ((type (if (listp types)
- (nth index types)
- types)))
- (cond
- ((and (or (eq type :double) (eq type :int32) (eq type :int)
- (eq type :int64))
- (char-ptr-points-to-null char-ptr))
- nil)
- (t
- (case type
- (:double
- (atof char-ptr))
- ((or :int32 :int)
- (atoi char-ptr))
- (:int64
- (uffi:with-foreign-object (high32-ptr :int)
- (let ((low32 (atol64 char-ptr high32-ptr))
- (high32 (uffi:deref-pointer high32-ptr :int)))
- (if (zerop high32)
- low32
- (make-64-bit-integer high32 low32)))))
- (t
- ;; Choose optimized routine
- #-(or cmu sbcl)
- (native-to-string char-ptr)
- #+(or cmu sbcl)
- (uffi:convert-from-foreign-string char-ptr)))))))
-
-
-(uffi:def-function "strlen"
- ((str (* :unsigned-char)))
- :returning :unsigned-int)
+(defun strtoul (char-ptr)
+ (declare (optimize (speed 3) (safety 0) (space 0))
+ (type char-ptr-def char-ptr))
+ (c-strtoul char-ptr uffi:+null-cstring-pointer+ 10))