Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TLMSP curl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CYBER - Cyber Security
TS 103 523 MSP
TLMSP
TLMSP curl
Commits
9363d94f
Commit
9363d94f
authored
21 years ago
by
Daniel Stenberg
Browse files
Options
Downloads
Patches
Plain Diff
new files for the large file support number parsing
parent
ea1c98dc
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/strtoofft.c
+153
-0
153 additions, 0 deletions
lib/strtoofft.c
lib/strtoofft.h
+50
-0
50 additions, 0 deletions
lib/strtoofft.h
with
203 additions
and
0 deletions
lib/strtoofft.c
0 → 100644
+
153
−
0
View file @
9363d94f
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2003, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* $Id$
***************************************************************************/
#include
"setup.h"
#include
"strtoofft.h"
#ifdef NEED_CURL_STRTOLL
#include
<stdlib.h>
#include
<ctype.h>
#include
<errno.h>
static
int
get_char
(
char
c
,
int
base
);
/**
* Emulated version of the strtoll function. This extracts a long long
* value from the given input string and returns it.
*/
long
long
Curl_strtoll
(
const
char
*
nptr
,
char
**
endptr
,
int
base
)
{
char
*
end
;
int
is_negative
=
0
;
int
overflow
;
int
i
;
long
long
value
=
0
;
long
long
newval
;
/* Skip leading whitespace. */
end
=
(
char
*
)
nptr
;
while
(
isspace
((
int
)
end
[
0
]))
{
end
++
;
}
/* Handle the sign, if any. */
if
(
end
[
0
]
==
'-'
)
{
is_negative
=
1
;
end
++
;
}
else
if
(
end
[
0
]
==
'+'
)
{
end
++
;
}
else
if
(
end
[
0
]
==
'\0'
)
{
/* We had nothing but perhaps some whitespace -- there was no number. */
if
(
endptr
)
{
*
endptr
=
end
;
}
return
0
;
}
/* Handle special beginnings, if present and allowed. */
if
(
end
[
0
]
==
'0'
&&
end
[
1
]
==
'x'
)
{
if
(
base
==
16
||
base
==
0
)
{
end
+=
2
;
base
=
16
;
}
}
else
if
(
end
[
0
]
==
'0'
)
{
if
(
base
==
8
||
base
==
0
)
{
end
++
;
base
=
8
;
}
}
/* Matching strtol, if the base is 0 and it doesn't look like
* the number is octal or hex, we assume it's base 10.
*/
if
(
base
==
0
)
{
base
=
10
;
}
/* Loop handling digits. */
value
=
0
;
overflow
=
0
;
for
(
i
=
get_char
(
end
[
0
],
base
);
i
!=
-
1
;
end
++
,
i
=
get_char
(
end
[
0
],
base
))
{
newval
=
base
*
value
+
i
;
if
(
newval
<
value
)
{
/* We've overflowed. */
overflow
=
1
;
break
;
}
else
{
value
=
newval
;
}
}
if
(
!
overflow
)
{
if
(
is_negative
)
{
/* Fix the sign. */
value
*=
-
1
;
}
}
else
{
if
(
is_negative
)
{
value
=
0x8000000000000000L
;
}
else
{
value
=
0x7FFFFFFFFFFFFFFFL
;
}
errno
=
ERANGE
;
}
if
(
endptr
)
{
*
endptr
=
end
;
}
return
value
;
}
/**
* Returns the value of c in the given base, or -1 if c cannot
* be interpreted properly in that base (i.e., is out of range,
* is a null, etc.).
*
* @param c the character to interpret according to base
* @param base the base in which to interpret c
*
* @return the value of c in base, or -1 if c isn't in range
*/
static
int
get_char
(
char
c
,
int
base
)
{
int
value
=
-
1
;
if
(
c
<=
'9'
&&
c
>=
'0'
)
{
value
=
c
-
'0'
;
}
else
if
(
c
<=
'Z'
&&
c
>=
'A'
)
{
value
=
c
-
'A'
+
10
;
}
else
if
(
c
<=
'z'
&&
c
>=
'a'
)
{
value
=
c
-
'a'
+
10
;
}
if
(
value
>=
base
)
{
value
=
-
1
;
}
return
value
;
}
#endif
/* Only present if we need strtoll, but don't have it. */
This diff is collapsed.
Click to expand it.
lib/strtoofft.h
0 → 100644
+
50
−
0
View file @
9363d94f
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2003, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at http://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
* $Id$
***************************************************************************/
#ifndef _CURL_STRTOOFFT_R_H
#define _CURL_STRTOOFFT_R_H
#include
"setup.h"
#include
<stddef.h>
/* Determine what type of file offset conversion handling we wish
* to use. For systems with a 32-bit off_t type, we should use
* strtol. For systems with a 64-bit off_t type, we should use
* strtoll if it exists, and if not, should try to emulate its
* functionality. At any rate, we define 'strtoofft' such that it
* can be used to work with off_t's regardless.
*/
#if SIZEOF_OFF_T > 4
#if HAVE_STRTOLL
#define strtoofft strtoll
#else
long
long
Curl_strtoll
(
const
char
*
nptr
,
char
**
endptr
,
int
base
);
#define strtoofft Curl_strtoll
#define NEED_CURL_STRTOLL
#endif
#else
#define strtoofft strtol
#endif
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment