Mail Archives: djgpp-workers/2002/11/02/23:21:28
This is try #2 for atoll() as the C99 standard has the definition 'long long
int' not 'long long' and now includes other changes for C99 'long long int'
defintions.
Below are atoll.c and atoll.txh, which together implement the missing
atoll() function. I copied the existing atol.c and atol.txh and made
hopefully the correct changes. Please let me know if I have made any
mistakes as I don't know if I got the compatability right.
These were all the changes I could see in the stdlib.h and
src\libc\ansi\stdlib directory
The patches for the following files are after the new files
src\libc\ansi\stdlib\makefile
src\libc\ansi\stdlib\strtoll.c
src\libc\ansi\stdlib\strtoll.txh
src\libc\ansi\stdlib\strtoull.c
src\libc\ansi\stdlib\strtoull.txh
src\libc\ansi\stdlib\llabs.c
src\libc\ansi\stdlib\llabs.txh
src\libc\ansi\stdlib\lldiv.c
src\libc\ansi\stdlib\lldiv.txh
I used the C99 draft of 18-Jan-1999 to check what needed to be changed.
=============== START NEW FILE src\libc\ansi\stdlib\atoll.c
====================
/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
long long int
atoll(const char *str)
{
return strtoll(str, 0, 10);
}
==================== END atoll.c ====================
=============== START NEW FILE src\libc\ansi\stdlib\atoll.txh
====================
@node atoll, string
@subheading Syntax
@example
#include <stdlib.h>
long long int atoll(const char *string);
@end example
@subheading Description
Convert as much of the string as possible to an equivalent long long integer
value.
This function is almost like @code{strtoll(string, NULL, 10)}
(@pxref{strtol}).
@subheading Return Value
The equivalent value, or zero if the string does not represent a number.
@subheading Portability
@portability !ansi-c89, ansi-c99, !posix
@subheading Example
@example
main(int argc, char **argv)
@{
long long int l = atoll(argv[1]);
@dots{}
@end example
==================== END atoll.txh ===================
============= START of PATCHES ====================
*** old\src\libc\ansi\stdlib\makefile Fri Oct 18 09:00:24 2002
--- src\libc\ansi\stdlib\makefile Sun Nov 3 14:57:10 2002
***************
*** 10,15 ****
--- 10,16 ----
SRC += atof.c
SRC += atoi.c
SRC += atol.c
+ SRC += atoll.c
SRC += atold.c
SRC += bsearch.c
SRC += calloc.c
*** old\src\libc\ansi\stdlib\strtoll.c Fri Oct 18 09:00:24 2002
--- src\libc\ansi\stdlib\strtoll.c Sun Nov 3 14:57:10 2002
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
***************
*** 8,20 ****
#include <stdlib.h>
#include <libc/unconst.h>
! long long
strtoll(const char *nptr, char **endptr, int base)
{
const unsigned char *s = (const unsigned char *) nptr;
! unsigned long long acc;
unsigned char c;
! unsigned long long cutoff;
int neg = 0, any, cutlim;
/*
--- 9,21 ----
#include <stdlib.h>
#include <libc/unconst.h>
! long long int
strtoll(const char *nptr, char **endptr, int base)
{
const unsigned char *s = (const unsigned char *) nptr;
! unsigned long long int acc;
unsigned char c;
! unsigned long long int cutoff;
int neg = 0, any, cutlim;
/*
*** old\src\libc\ansi\stdlib\strtoll.txh Mon Sep 28 01:20:54 1998
--- src\libc\ansi\stdlib\strtoll.txh Sun Nov 3 14:26:06 2002
***************
*** 4,10 ****
@example
#include <stdlib.h>
! long long strtoll(const char *s, char **endp, int base);
@end example
@subheading Description
--- 4,10 ----
@example
#include <stdlib.h>
! long long int strtoll(const char *s, char **endp, int base);
@end example
@subheading Description
***************
*** 25,31 ****
@subheading Portability
! @portability !ansi, !posix
@subheading Example
--- 25,31 ----
@subheading Portability
! @portability !ansi-c89, ansi-c99, !posix
@subheading Example
*** old\src\libc\ansi\stdlib\strtoull.c Fri Oct 18 09:00:24 2002
--- src\libc\ansi\stdlib\strtoull.c Sun Nov 3 14:57:20 2002
***************
*** 1,3 ****
--- 1,4 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 2001 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
***************
*** 14,26 ****
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
! unsigned long long
strtoull(const char *nptr, char **endptr, int base)
{
const unsigned char *s = (const unsigned char*) nptr;
! unsigned long long acc;
unsigned char c;
! unsigned long long cutoff;
int neg = 0, any, cutlim;
/*
--- 15,27 ----
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
! unsigned long long int
strtoull(const char *nptr, char **endptr, int base)
{
const unsigned char *s = (const unsigned char*) nptr;
! unsigned long long int acc;
unsigned char c;
! unsigned long long int cutoff;
int neg = 0, any, cutlim;
/*
***************
*** 45,52 ****
}
if (base == 0)
base = c == '0' ? 8 : 10;
! cutoff = (unsigned long long)ULLONG_MAX / base;
! cutlim = (unsigned long long)ULLONG_MAX % base;
for (acc = 0, any = 0; ; c = *s++)
{
if (isdigit(c))
--- 46,53 ----
}
if (base == 0)
base = c == '0' ? 8 : 10;
! cutoff = (unsigned long long int)ULLONG_MAX / base;
! cutlim = (unsigned long long int)ULLONG_MAX % base;
for (acc = 0, any = 0; ; c = *s++)
{
if (isdigit(c))
*** old\src\libc\ansi\stdlib\strtoull.txh Mon Sep 28 01:20:56 1998
--- src\libc\ansi\stdlib\strtoull.txh Sun Nov 3 14:27:36 2002
***************
*** 4,10 ****
@example
#include <stdlib.h>
! unsigned long long strtoull(const char *s, char **endp, int base);
@end example
@subheading Description
--- 4,10 ----
@example
#include <stdlib.h>
! unsigned long long int strtoull(const char *s, char **endp, int base);
@end example
@subheading Description
***************
*** 18,24 ****
@subheading Portability
! @portability !ansi, !posix
@subheading Example
--- 18,24 ----
@subheading Portability
! @portability !ansi-c89, ansi-c99, !posix
@subheading Example
*** old\src\libc\ansi\stdlib\llabs.c Sun May 19 04:50:02 1996
--- src\libc\ansi\stdlib\llabs.c Sun Nov 3 14:56:56 2002
***************
*** 1,9 ****
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
! long long
! llabs(long long j)
{
return j<0 ? -j : j;
}
--- 1,10 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
! long long int
! llabs(long long int j)
{
return j<0 ? -j : j;
}
*** old\src\libc\ansi\stdlib\llabs.txh Mon Sep 28 01:20:54 1998
--- src\libc\ansi\stdlib\llabs.txh Sun Nov 3 14:43:14 2002
***************
*** 4,10 ****
@example
#include <stdlib.h>
! long long llabs(long long x);
@end example
@subheading Description
--- 4,10 ----
@example
#include <stdlib.h>
! long long int llabs(long long x);
@end example
@subheading Description
***************
*** 18,22 ****
@subheading Portability
! @portability !ansi, !posix
--- 18,23 ----
@subheading Portability
! @portability !ansi-c89, ansi-c99, !posix
!
*** old\src\libc\ansi\stdlib\lldiv.c Sun May 19 04:53:42 1996
--- src\libc\ansi\stdlib\lldiv.c Sun Nov 3 14:44:20 2002
***************
*** 1,9 ****
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
lldiv_t
! lldiv(long long num, long long denom)
{
lldiv_t r;
--- 1,10 ----
+ /* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
lldiv_t
! lldiv(long long int num, long long int denom)
{
lldiv_t r;
*** old\src\libc\ansi\stdlib\lldiv.txh Mon Sep 28 01:20:54 1998
--- src\libc\ansi\stdlib\lldiv.txh Sun Nov 3 14:44:56 2002
***************
*** 4,10 ****
@example
#include <stdlib.h>
! lldiv_t lldiv(long long numerator, long long denominator);
@end example
@subheading Description
--- 4,10 ----
@example
#include <stdlib.h>
! lldiv_t lldiv(long long int numerator, long long int denominator);
@end example
@subheading Description
***************
*** 14,21 ****
@example
typedef struct @{
! long long quot;
! long long rem;
@} lldiv_t;
@end example
--- 14,21 ----
@example
typedef struct @{
! long long int quot;
! long long int rem;
@} lldiv_t;
@end example
- Raw text -