📄 strtol.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/common/lib/strtol.c,v 1.3 2003/01/16 18:18:57 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** * Copyright 1993-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* * $Log: strtol.c,v $ * Revision 1.3 2003/01/16 18:18:57 josh * directory structure shifting * * Revision 1.2 2001/11/06 22:15:55 tneale * Fixed for newest file layout * * Revision 1.1.1.1 2001/11/05 17:48:40 tneale * Tornado shuffle * * Revision 1.4 2001/01/19 22:21:32 paul * Update copyright. * * Revision 1.3 2000/03/17 00:16:58 meister * Update copyright message * * Revision 1.2 1998/10/14 13:03:20 sar * Removed setting of errno on errors as it isn't portable enough. * * Revision 1.1 1998/06/03 20:12:52 sar * Added some common string functions. The user can choose to install * these if his library doesn't include them or they are broken. * *//* [clearcase]modification history-------------------01b,20apr05,job update copyright notices01a,11dec03,job fix copyright statements*/#include <wrn/wm/common/install.h>#include <wrn/wm/common/stdf.h>#include <errno.h>/* PORTABLE 'Standard' C FUNCTIONS - these are written in C because not * all systems provide them consistently. Sometimes they're even broken. * This code used to be in snark/snmptalk/stdf.c but was moved here to * be available to more code. *//* This doesn't accept 0x if the radix is 16. The overflow code assumes * a 2's complement architecture */long etc_strtol(char *string, char **endptr, int radix){ char *s; long value; long new_value; int sign; int increment; value = 0; sign = 1; s = string; if ((radix == 1) || (radix > 36) || (radix < 0)) { goto done; } /* skip whitespace */ while ((*s == ' ') || (*s == '\t') || (*s == '\n') || (*s == '\r')) s++; if (*s == '-') { sign = -1; s++; } else if (*s == '+') s++; if (radix == 0) { if (*s == '0') { s++; if ((*s == 'x') || (*s == 'X')) { s++; radix = 16; } else radix = 8; } else radix = 10; } /* read number */ while (1) { if ((*s >= '0') && (*s <= '9')) increment = *s - '0'; else if ((*s >= 'a') && (*s <= 'z')) increment = *s - 'a' + 10; else if ((*s >= 'A') && (*s <= 'Z')) increment = *s - 'A' + 10; else break; if (increment >= radix) break; new_value = value * radix + increment; /* detect overflow */ if ((new_value - increment)/radix != value) { s = string; value = -1 >> 1; if (sign < 0) value += 1; goto done; } value = new_value; s++; } done: if (endptr) *endptr = s; return value*sign;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -