Automated commit for upstream build of version 4.1.1
[clsql/s11.git] / uffi / clsql_uffi.c
blob39754ff359488d01e4449e6bb3b1efb55f81bf71
1 /****************************************************************************
2 * FILE IDENTIFICATION
4 * Name: clsql-uffi.c
5 * Purpose: Helper functions for common interfaces using UFFI
6 * Programmer: Kevin M. Rosenberg
7 * Date Started: Mar 2002
9 * $Id$
11 * This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
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 ***************************************************************************/
18 #if defined(WIN32)||defined(WIN64)
19 #include <windows.h>
21 BOOL WINAPI DllEntryPoint(HINSTANCE hinstdll, DWORD fdwReason,
22 LPVOID lpvReserved)
24 return 1;
27 #define DLLEXPORT __declspec(dllexport)
29 #else
30 #define DLLEXPORT
31 #endif
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))
38 /* Reads a 64-bit integer string, returns result as two 32-bit integers */
40 DLLEXPORT
41 unsigned int
42 atol64 (const unsigned char* str, unsigned int* pHigh32)
44 #if defined(WIN32)||defined(WIN64)
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;
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++;
65 if (minus)
66 result = -result;
68 *pHigh32 = upper_32bits(result);
69 return lower_32bits(result);