~ubuntu-branches/ubuntu/vivid/curl/vivid

« back to all changes in this revision

Viewing changes to lib/strtoofft.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Schuldei
  • Date: 2009-04-02 23:35:45 UTC
  • mto: (1.2.1 upstream) (3.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 38.
  • Revision ID: james.westby@ubuntu.com-20090402233545-geixkwhe3izccjt7
Tags: upstream-7.19.4
ImportĀ upstreamĀ versionĀ 7.19.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 *                            | (__| |_| |  _ <| |___
8
8
 *                             \___|\___/|_| \_\_____|
9
9
 *
10
 
 * Copyright (C) 1998 - 2004, Daniel Stenberg, <daniel@haxx.se>, et al.
 
10
 * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
11
11
 *
12
12
 * This software is licensed as described in the file COPYING, which
13
13
 * you should have received as part of this distribution. The terms
20
20
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21
21
 * KIND, either express or implied.
22
22
 *
23
 
 * $Id: strtoofft.h,v 1.16 2007-11-06 16:20:54 giva Exp $
 
23
 * $Id: strtoofft.h,v 1.22 2008-08-21 06:58:13 yangtse Exp $
24
24
 ***************************************************************************/
25
25
 
 
26
#include "setup.h"
 
27
 
26
28
/*
27
 
 * CAUTION: this header is designed to work when included by the app-side
28
 
 * as well as the library. Do not mix with library internals!
29
 
 */
30
 
 
31
 
#include "setup.h"
32
 
#include <stddef.h>
33
 
#include <curl/curl.h> /* for the curl_off_t type */
34
 
 
35
 
/* Determine what type of file offset conversion handling we wish to use.  For
36
 
 * systems with a 32-bit curl_off_t type, we should use strtol.  For systems
37
 
 * with a 64-bit curl_off_t type, we should use strtoll if it exists, and if
38
 
 * not, should try to emulate its functionality.  At any rate, we define
39
 
 * 'strtoofft' such that it can be used to work with curl_off_t's regardless.
40
 
 */
41
 
#if (SIZEOF_CURL_OFF_T > 4) && (SIZEOF_LONG < 8)
42
 
#ifdef HAVE_STRTOLL
43
 
#define curlx_strtoofft strtoll
44
 
#else /* HAVE_STRTOLL */
45
 
 
46
 
/* For MSVC7 we can use _strtoi64() which seems to be a strtoll() clone */
47
 
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
48
 
_CRTIMP __int64 __cdecl _strtoi64(const char *, char **, int);  /* in <crt/stdlib.h> */
49
 
#define curlx_strtoofft _strtoi64
50
 
#else /* MSVC7 or later */
51
 
curl_off_t curlx_strtoll(const char *nptr, char **endptr, int base);
52
 
#define curlx_strtoofft curlx_strtoll
53
 
#define NEED_CURL_STRTOLL
54
 
#endif /* MSVC7 or later */
55
 
 
56
 
#endif /* HAVE_STRTOLL */
57
 
#else /* (SIZEOF_CURL_OFF_T > 4) && (SIZEOF_LONG < 8) */
58
 
/* simply use strtol() to get numbers, either 32 or 64 bit */
59
 
#define curlx_strtoofft strtol
60
 
#endif
61
 
 
62
 
#if defined(_MSC_VER) || defined(__WATCOMC__)
63
 
#define CURL_LLONG_MIN 0x8000000000000000i64
64
 
#define CURL_LLONG_MAX 0x7FFFFFFFFFFFFFFFi64
65
 
#elif defined(HAVE_LL)
66
 
#define CURL_LLONG_MIN 0x8000000000000000LL
67
 
#define CURL_LLONG_MAX 0x7FFFFFFFFFFFFFFFLL
 
29
 * Determine which string to integral data type conversion function we use
 
30
 * to implement string conversion to our curl_off_t integral data type.
 
31
 *
 
32
 * Notice that curl_off_t might be 64 or 32 bit wide, and that it might use
 
33
 * an undelying data type which might be 'long', 'int64_t', 'long long' or 
 
34
 * '__int64' and more remotely other data types.
 
35
 *
 
36
 * On systems where the size of curl_off_t is greater than the size of 'long'
 
37
 * the conversion funtion to use is strtoll() if it is available, otherwise,
 
38
 * we emulate its functionality with our own clone.
 
39
 *
 
40
 * On systems where the size of curl_off_t is smaller or equal than the size
 
41
 * of 'long' the conversion funtion to use is strtol().
 
42
 */
 
43
 
 
44
#if (CURL_SIZEOF_CURL_OFF_T > CURL_SIZEOF_LONG)
 
45
#  ifdef HAVE_STRTOLL
 
46
#    define curlx_strtoofft strtoll
 
47
#  else
 
48
#    if defined(_MSC_VER) && (_MSC_VER >= 1300) && (_INTEGRAL_MAX_BITS >= 64)
 
49
       _CRTIMP __int64 __cdecl _strtoi64(const char *, char **, int);
 
50
#      define curlx_strtoofft _strtoi64
 
51
#    else
 
52
       curl_off_t curlx_strtoll(const char *nptr, char **endptr, int base);
 
53
#      define curlx_strtoofft curlx_strtoll
 
54
#      define NEED_CURL_STRTOLL 1
 
55
#    endif
 
56
#  endif
68
57
#else
69
 
#define CURL_LLONG_MIN 0x8000000000000000L
70
 
#define CURL_LLONG_MAX 0x7FFFFFFFFFFFFFFFL
 
58
#  define curlx_strtoofft strtol
71
59
#endif
 
60
 
 
61
#define CURL_LLONG_MAX CURL_OFF_T_C(0x7FFFFFFFFFFFFFFF)
 
62
#define CURL_LLONG_MIN (-CURL_LLONG_MAX - CURL_OFF_T_C(1))
72
63
 
73
64
#endif
74
65