getlong.c (421B)
1 /* Copyright ©2008-2010 Kris Maglione <maglione.k at Gmail> 2 * See LICENSE file for license details. 3 */ 4 #include <string.h> 5 #include <stuff/util.h> 6 7 bool 8 getlong(const char *s, long *ret) { 9 const char *end; 10 char *rend; 11 int base; 12 long sign; 13 14 if(s == nil) 15 return false; 16 end = s+strlen(s); 17 base = getbase(&s, &sign); 18 if(sign == 0) 19 return false; 20 21 *ret = sign * strtol(s, &rend, base); 22 return (end == rend); 23 }