strtouint.h

来自「Firestorm NIDS是一个性能非常高的网络入侵检测系统 (NIDS)。目」· C头文件 代码 · 共 61 行

H
61
字号
#ifndef __STRTOUINT_HEADER_INCLUDED__#define __STRTOUINT_HEADER_INCLUDED__/* Error detecting string to unsigned int conversion.*  Return values:*   <0 - error (such as overflow, or not-a-number)*   =0 - the input string was perfect*   >0 - the input string had trailing garbage, return*        value tells you how many bytes were numbers.*/#include <ctype.h>static inline int strtouint(const char *s, unsigned int *v){	unsigned int d;	int p=0;	int base=10;	if ( s[0]=='0' ) {		base=8;		s++;		p++;	}	if ( *s && base==8 && *s=='x' ) {		base=16;		s++;		p++;	}	if ( base <= 10 ) {		for(*v=0; (d=(unsigned int)(*s - '0')) < base; p++) {			*v=*v*base+d;			s++;		}	}else{		for(*v=0; ; p++) {			if ( (d=(unsigned int)(*s - '0'))>=10 &&				(d=((unsigned int)(tolower(*s) - 'a')+10))>=base ) break;			*v=*v*base+d;			s++;		}	}	if ( p==0 ) {		if ( base==8 ) {			*v=0;		}else{			*v=0;			return -1;		}	}	if ( *s==0 ) return 0;	return p;}#ifndef __PLUGIN__#else#endif#endif /* __STRTOUINT_HEADER_INCLUDED__ */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?