r1673: *** empty log message ***
[clsql.git] / interfaces / clsql-uffi / clsql-uffi.c
1 /****************************************************************************
2  * FILE IDENTIFICATION
3  *
4  *   Name:          clsql-uffi.c
5  *   Purpose:       Helper functions for common interfaces using UFFI
6  *   Programmer:    Kevin M. Rosenberg
7  *   Date Started:  Mar 2002
8  *
9  * $Id: clsql-uffi.c,v 1.1 2002/03/27 08:09:25 kevin Exp $
10  *
11  * This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
12  *
13  * CLSQL users are granted the rights to distribute and use this software
14  * as governed by the terms of the Lisp Lesser GNU Public License
15  * (http://opensource.franz.com/preamble.html), also known as the LLGPL.
16  ***************************************************************************/
17
18 #ifdef WIN32
19 #include <windows.h>
20
21 BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll, DWORD fdwReason,
22                           LPVOID lpvReserved)
23 {
24         return 1;
25 }
26        
27 #define DLLEXPORT __declspec(dllexport)
28
29 #else
30 #define DLLEXPORT 
31 #endif
32
33
34 const unsigned int bitmask_32bits = 0xFFFFFFFF;
35 #define lower_32bits(int64) ((unsigned int) int64 & bitmask_32bits)
36 #define upper_32bits(int64) ((unsigned int) (int64 >> 32))
37
38 /* Reads a 64-bit integer string, returns result as two 32-bit integers */
39
40 DLLEXPORT
41 unsigned int
42 atol64 (const unsigned char* str, int* pHigh32)
43 {
44   long long result = 0;
45   int minus = 0;
46   int first_char = *str;
47   if (first_char == '+')
48     ++str;
49   else if (first_char == '-') {
50     minus = 1;
51     ++str;
52   }
53
54   while (*str) {
55     int i = *str - '0';
56     if (i < 0 || i > 9) /* Non-numeric character -- quit */
57       break;
58     result = i + (10 * result);
59     str++;
60   }
61   if (minus)
62     result = -result;
63
64   *pHigh32 = upper_32bits(result);
65   return lower_32bits(result);
66 }
67
68   
69   
70
71