r4701: *** empty log message ***
[uffi.git] / tests / atoifl.lisp
1 ;;;; -*- Mode: Lisp; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          atoifl.cl
6 ;;;; Purpose:       UFFI Example file to atoi/atof/atol
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Mar 2002
9 ;;;;
10 ;;;; $Id: atoifl.lisp,v 1.2 2003/04/29 12:57:10 kevin Exp $
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package :uffi-tests)
20
21 (uffi:def-function ("atoi" c-atoi) 
22     ((str :cstring))
23   :returning :int)
24
25 (uffi:def-function ("atol" c-atol) 
26     ((str :cstring))
27   :returning :long)
28
29 (uffi:def-function ("atof" c-atof) 
30     ((str :cstring))
31   :returning :double)
32
33 (defun atoi (str)
34   "Returns a int from a string."
35   (uffi:with-cstring (str-cstring str)
36     (c-atoi str-cstring)))
37
38 (defun atof (str)
39   "Returns a double float from a string."
40   (uffi:with-cstring (str-cstring str)
41     (c-atof str-cstring)))
42   
43 (deftest atoi.1 (atoi "123") 123)
44 (deftest atoi.2 (atoi "") 0)
45 (deftest atof.3 (atof "2.23") 2.23d0)