Remove CVS $Id$ keyword
[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  * This file, part of CLSQL, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
10  *
11  * CLSQL users are granted the rights to distribute and use this software
12  * as governed by the terms of the Lisp Lesser GNU Public License
13  * (http://opensource.franz.com/preamble.html), also known as the LLGPL.
14  ***************************************************************************/
15
16 #if defined(WIN32)||defined(WIN64)
17 #include <windows.h>
18
19 BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll, DWORD fdwReason,
20                           LPVOID lpvReserved)
21 {
22         return 1;
23 }
24
25 #define DLLEXPORT __declspec(dllexport)
26
27 #else
28 #define DLLEXPORT
29 #endif
30
31
32 const unsigned int bitmask_32bits = 0xFFFFFFFF;
33 #define lower_32bits(int64) ((unsigned int) int64 & bitmask_32bits)
34 #define upper_32bits(int64) ((unsigned int) (int64 >> 32))
35
36 /* Reads a 64-bit integer string, returns result as two 32-bit integers */
37
38 DLLEXPORT
39 unsigned int
40 atol64 (const unsigned char* str, unsigned int* pHigh32)
41 {
42 #if defined(WIN32)||defined(WIN64)
43   __int64 result = 0;
44 #else
45   long long result = 0;
46 #endif
47   int minus = 0;
48   int first_char = *str;
49   if (first_char == '+')
50     ++str;
51   else if (first_char == '-') {
52     minus = 1;
53     ++str;
54   }
55
56   while (*str) {
57     int i = *str - '0';
58     if (i < 0 || i > 9) /* Non-numeric character -- quit */
59       break;
60     result = i + (10 * result);
61     str++;
62   }
63   if (minus)
64     result = -result;
65
66   *pHigh32 = upper_32bits(result);
67   return lower_32bits(result);
68 }
69
70
71
72
73