📄 dtutil.c
字号:
#if defined(_BSD) if ( (bp = (u_char *) valloc (size + offset)) == (u_char *) 0) { LogMsg (efp, logLevelCrit, 0, "valloc() failed allocating %lu bytes.\n", (size + offset)); exit (FATAL_ERROR); }#elif defined(_QNX_SOURCE) && !defined(_QNX_32BIT) if ( (bp = (u_char *) malloc (size + offset)) == (u_char *) 0) { LogMsg (efp, logLevelCrit, 0, "malloc() failed allocating %u bytes.\n", (size + offset)); exit (FATAL_ERROR); }#else /* !defined_BSD) || !defined(_QNX_SOURCE) */ if ( (bp = (u_char *) malloc (size + offset + page_size)) == (u_char *) 0) { LogMsg (efp, logLevelCrit, 0, "malloc() failed allocating %lu bytes.\n", (size + offset + page_size)); exit (FATAL_ERROR); } else { bp = (u_char *)( ((ptr_t)bp + (page_size-1)) &~ (page_size-1) ); }#endif /* defined(_BSD) */ bp += offset; if (debug_flag) { Printf ( "Allocated buffer at address %#lx of %u bytes, using offset %u\n", bp, size, offset); } return (bp);}/* * Allocate memory with appropriate error checking. */void *Malloc (size_t size){ void *bp; if ( (bp = malloc (size)) == NULL) { LogMsg (efp, logLevelCrit, 0, "malloc() failed allocating %u bytes.\n", size); exit (ENOMEM); } memset (bp, '\0', size); return (bp);}/************************************************************************ * * * CvtStrtoValue() - Converts ASCII String into Numeric Value. * * * * Inputs: nstr = String to convert. * * eptr = Pointer for terminating character pointer. * * base = The base used for the conversion. * * * * Outputs: eptr = Points to terminating character or nstr if an * * invalid if numeric value cannot be formed. * * * * Return Value: * * Returns converted number or -1 for FAILURE. * * * ************************************************************************/u_longCvtStrtoValue (char *nstr, char **eptr, int base){ u_long n = 0, val; if ( (n = strtoul (nstr, eptr, base)) == 0L) { if (nstr == *eptr) { n++; } }#ifdef notdef if (nstr == *eptr) { return (n); }#endif /* notdef */ nstr = *eptr; for (;;) { switch (*nstr++) { case 'k': case 'K': /* Kilobytes */ n *= KBYTE_SIZE; continue; case 'g': case 'G': /* Gigibytes */ n *= GBYTE_SIZE; continue; case 'm': case 'M': /* Megabytes */ n *= MBYTE_SIZE; continue;#if defined(QuadIsLong) case 't': case 'T': n *= TBYTE_SIZE; continue;#endif /* defined(QuadIsLong) */ case 'w': case 'W': /* Word count. */ n *= sizeof(int); continue; case 'q': case 'Q': /* Quadword count. */ n *= sizeof(large_t); continue; case 'b': case 'B': /* Block count. */ n *= BLOCK_SIZE; continue; case 'd': case 'D': /* Device size. */ n *= device_size; continue; case 'c': case 'C': /* Core clicks. */ case 'p': case 'P': /* Page size. */ n *= page_size; continue; case 'i': case 'I': if ( ( ( nstr[0] == 'N' ) || ( nstr[0] == 'n' ) ) && ( ( nstr[1] == 'F' ) || ( nstr[1] == 'f' ) )) { nstr += 2; n = (u_long)INFINITY; continue; } else { goto error; } case '+': n += CvtStrtoValue (nstr, eptr, base); nstr = *eptr; continue; case '-': n -= CvtStrtoValue (nstr, eptr, base); nstr = *eptr; continue; case '*': case 'x': case 'X': n *= CvtStrtoValue (nstr, eptr, base); nstr = *eptr; continue; case '/': val = CvtStrtoValue (nstr, eptr, base); if (val) n /= val; nstr = *eptr; continue; case '%': val = CvtStrtoValue (nstr, eptr, base); if (val) n %= val; nstr = *eptr; continue; case '~': n = ~CvtStrtoValue (nstr, eptr, base); nstr = *eptr; continue; case '|': n |= CvtStrtoValue (nstr, eptr, base); nstr = *eptr; continue; case '&': n &= CvtStrtoValue (nstr, eptr, base); nstr = *eptr; continue; case '^': n ^= CvtStrtoValue (nstr, eptr, base); nstr = *eptr; continue; case '<': if (*nstr++ != '<') goto error; n <<= CvtStrtoValue (nstr, eptr, base); nstr = *eptr; continue; case '>': if (*nstr++ != '>') goto error; n >>= CvtStrtoValue (nstr, eptr, base); nstr = *eptr; continue; case ' ': case '\t': continue; case '\0': *eptr = --nstr; break; default:error: n = 0L; *eptr = --nstr; break; } return (n); }}/************************************************************************ * * * CvtStrtoLarge() - Converts ASCII String into Large Value. * * * * Inputs: nstr = String to convert. * * eptr = Pointer for terminating character pointer. * * base = The base used for the conversion. * * * * Outputs: eptr = Points to terminating character or nstr if an * * invalid if numeric value cannot be formed. * * * * Return Value: * * Returns converted number or -1 for FAILURE. * * * ************************************************************************/large_tCvtStrtoLarge (char *nstr, char **eptr, int base){ large_t n = 0, val;#if defined(QuadIsLong) || defined(HP_UX) if ( (n = strtoul (nstr, eptr, base)) == (large_t) 0) {#elif defined(QuadIsLongLong)# if defined(SCO) || defined(__QNXNTO__) || defined(SOLARIS) || defined(AIX) || defined(_NT_SOURCE) if ( (n = strtoull (nstr, eptr, base)) == (large_t) 0) {# else /* !defined(SCO) && !defined(__QNXNTO__) && !defined(AIX) && !defined(_NT_SOURCE) */ if ( (n = strtouq (nstr, eptr, base)) == (large_t) 0) {# endif /* defined(SCO) || defined(__QNXNTO__) || defined(SOLARIS) || defined(AIX) || defined(_NT_SOURCE) */#else /* assume QuadIsDouble */ if ( (n = strtod (nstr, eptr)) == (large_t) 0) {#endif if (nstr == *eptr) { n++; } }#ifdef notdef if (nstr == *eptr) { return (n); }#endif /* notdef */ nstr = *eptr; for (;;) { switch (*nstr++) { case 'k': case 'K': /* Kilobytes */ n *= KBYTE_SIZE; continue; case 'g': case 'G': /* Gigibytes */ n *= GBYTE_SIZE; continue; case 'm': case 'M': /* Megabytes */ n *= MBYTE_SIZE; continue; case 't': case 'T': n *= TBYTE_SIZE; continue; case 'w': case 'W': /* Word count. */ n *= sizeof(int); continue; case 'q': case 'Q': /* Quadword count. */ n *= sizeof(large_t); continue; case 'b': case 'B': /* Block count. */ n *= BLOCK_SIZE; continue; case 'd': case 'D': /* Device size. */ n *= device_size; continue; case 'c': case 'C': /* Core clicks. */ case 'p': case 'P': /* Page size. */ n *= page_size; continue; case 'i': case 'I': if ( ( ( nstr[0] == 'N' ) || ( nstr[0] == 'n' ) ) && ( ( nstr[1] == 'F' ) || ( nstr[1] == 'f' ) )) { nstr += 2; n = INFINITY; continue; } else { goto error; } case '+': n += CvtStrtoLarge (nstr, eptr, base); nstr = *eptr; continue; case '-': n -= CvtStrtoLarge (nstr, eptr, base); nstr = *eptr; continue; case '*': case 'x': case 'X': n *= CvtStrtoLarge (nstr, eptr, base); nstr = *eptr; continue; case '/': val = CvtStrtoLarge (nstr, eptr, base); if (val) n /= val; nstr = *eptr; continue;#if !defined(QuadIsDouble) case '%': val = CvtStrtoLarge (nstr, eptr, base); if (val) n %= val; nstr = *eptr; continue; case '~': n = ~CvtStrtoLarge (nstr, eptr, base); nstr = *eptr; continue; case '|': n |= CvtStrtoLarge (nstr, eptr, base); nstr = *eptr; continue; case '&': n &= CvtStrtoLarge (nstr, eptr, base); nstr = *eptr; continue; case '^': n ^= CvtStrtoLarge (nstr, eptr, base); nstr = *eptr; continue; case '<': if (*nstr++ != '<') goto error; n <<= CvtStrtoLarge (nstr, eptr, base); nstr = *eptr; continue; case '>': if (*nstr++ != '>') goto error; n >>= CvtStrtoLarge (nstr, eptr, base); nstr = *eptr; continue;#endif /* !defined(QuadIsDouble) */ case ' ': case '\t': continue; case '\0': *eptr = --nstr; break; default:error: n = 0; *eptr = --nstr; break; } return (n); }}/************************************************************************ * * * CvtTimetoValue() - Converts ASCII Time String to Numeric Value. * * * * Inputs: nstr = String to convert. * * eptr = Pointer for terminating character pointer. * * * * Outputs: eptr = Points to terminating character or nstr if an * * invalid if numeric value cannot be formed. * * * * Return Value: * * Returns converted number in seconds or -1 for FAILURE. * * * ************************************************************************/time_tCvtTimetoValue (char *nstr, char **eptr){ time_t n = 0; int base = ANY_RADIX; if ( (n = strtoul (nstr, eptr, base)) == 0L) { if (nstr == *eptr) { n++; } }#ifdef notdef if (nstr == *eptr) { return (n); }#endif /* notdef */ nstr = *eptr; for (;;) { switch (*nstr++) { case 'd': case 'D': /* Days */ n *= SECS_PER_DAY; continue; case 'h': case 'H': /* Hours */ n *= SECS_PER_HOUR; continue; case 'm': case 'M': /* Minutes */ n *= SECS_PER_MIN; continue; case 's': case 'S': /* Seconds */ continue; /* default */ case '+': n += CvtTimetoValue (nstr, eptr); nstr = *eptr; continue; case '-': n -= CvtTimetoValue (nstr, eptr); nstr = *eptr; continue; case '*': case 'x': case 'X': n *= CvtTimetoValue (nstr, eptr);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -