r11859: Canonicalize whitespace
[clsql.git] / 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$
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, unsigned int* pHigh32)
43 {
44 #ifdef WIN32
45   __int64 result = 0;
46 #else
47   long long result = 0;
48 #endif
49   int minus = 0;
50   int first_char = *str;
51   if (first_char == '+')
52     ++str;
53   else if (first_char == '-') {
54     minus = 1;
55     ++str;
56   }
57
58   while (*str) {
59     int i = *str - '0';
60     if (i < 0 || i > 9) /* Non-numeric character -- quit */
61       break;
62     result = i + (10 * result);
63     str++;
64   }
65   if (minus)
66     result = -result;
67
68   *pHigh32 = upper_32bits(result);
69   return lower_32bits(result);
70 }
71
72
73
74
75