source: trunk/sys/dietlibc/strtol.c @ 204

Last change on this file since 204 was 1, checked in by alain, 8 years ago

First import

File size: 696 bytes
Line 
1#include <ctype.h>
2#include "dietfeatures.h"
3#include <errno.h>
4#include <limits.h>
5#include <stdlib.h>
6
7#if __WORDSIZE == 64
8#define ABS_LONG_MIN 9223372036854775808UL
9#else
10#define ABS_LONG_MIN 2147483648UL
11#endif
12long int strtol(const char *nptr, char **endptr, int base)
13{
14  int neg=0;
15  unsigned long int v;
16  const char*orig=nptr;
17
18  while(isspace(*nptr)) nptr++;
19
20  if (*nptr == '-' && isalnum(nptr[1])) { neg=-1; ++nptr; }
21  v=strtoul(nptr,endptr,base);
22  if (endptr && *endptr==nptr) *endptr=(char *)orig;
23  if (v>=ABS_LONG_MIN) {
24    if (v==ABS_LONG_MIN && neg) {
25      //errno=0;
26      return v;
27    }
28    //errno=ERANGE;
29    return (neg?LONG_MIN:LONG_MAX);
30  }
31  return (neg?-v:v);
32}
Note: See TracBrowser for help on using the repository browser.