nbase.h
来自「Ubuntu packages of security software。 相」· C头文件 代码 · 共 438 行 · 第 1/2 页
H
438 行
/* Mathematicial MIN/MAX/ABS (absolute value) macros */#ifndef MAX#define MAX(x,y) (((x)>(y))?(x):(y))#endif#ifndef MIN#define MIN(x,y) (((x)<(y))?(x):(y))#endif#ifndef ABS#define ABS(x) (((x) >= 0)?(x):(-x)) #endif/* sprintf family */#if !defined(HAVE_SNPRINTF) && defined(__cplusplus)extern "C" int snprintf (char *str, size_t sz, const char *format, ...) __attribute__ ((format (printf, 3, 4)));#endif#if !defined(HAVE_VSNPRINTF) && defined(__cplusplus)extern "C" int vsnprintf (char *str, size_t sz, const char *format, va_list ap) __attribute__((format (printf, 3, 0)));#endif#if !defined(HAVE_ASPRINTF) && defined(__cplusplus)extern "C" int asprintf (char **ret, const char *format, ...) __attribute__ ((format (printf, 2, 3)));#endif#if !defined(HAVE_VASPRINTF) && defined(__cplusplus)extern "C" int vasprintf (char **ret, const char *format, va_list ap) __attribute__((format (printf, 2, 0)));#endif#if !defined(HAVE_ASNPRINTF) && defined(__cplusplus)extern "C" int asnprintf (char **ret, size_t max_sz, const char *format, ...) __attribute__ ((format (printf, 3, 4)));#endif#if !defined(HAVE_VASNPRINTF) && defined(__cplusplus)extern "C" int vasnprintf (char **ret, size_t max_sz, const char *format, va_list ap) __attribute__((format (printf, 3, 0)));#endif#if defined(NEED_SNPRINTF_PROTO) && defined(__cplusplus)extern "C" int snprintf (char *, size_t, const char *, ...);#endif#if defined(NEED_VSNPRINTF_PROTO) && defined(__cplusplus)extern "C" int vsnprintf (char *, size_t, const char *, va_list);#endif#ifdef HAVE_GETOPT_H#include <getopt.h>#else#ifndef HAVE_GETOPT_LONG_ONLY#include "getopt.h"#endif#endif /* HAVE_GETOPT_H *//* More Windows-specific stuff */#ifdef WIN32#define WIN32_LEAN_AND_MEAN /* Whatever this means! From winclude.h*//* Apparently Windows doesn't have S_ISDIR */#ifndef S_ISDIR#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)#endif/* Windows doesn't have the access() defines */#ifndef F_OK#define F_OK 00#endif#ifndef W_OK#define W_OK 02#endif#ifndef R_OK#define R_OK 04#endif#define access _access#define stat _stat /* wtf was ms thinking? */#define execve _execve#define getpid _getpid#define dup _dup#define dup2 _dup2#define strdup _strdup#define write _write#define open _open#define stricmp _stricmp#define putenv _putenv#if !defined(__GNUC__)#define snprintf _snprintf#define vsnprintf _vsnprintf#endif#define strcasecmp _stricmp#define strncasecmp _strnicmp#define execv _execv#endif /* WIN32 *//* Apparently Windows doesn't like /dev/null */#ifdef WIN32#define DEVNULL "NUL"#else#define DEVNULL "/dev/null"#endif#ifdef __cplusplusextern "C" {#endif /* Returns the UNIX/Windows errno-equivalent. Note that the Windows call is socket/networking specific. Also, WINDOWS TENDS TO RESET THE ERROR, so it will return success the next time. So SAVE THE RESULTS and re-use them, don't keep calling socket_errno(). The windows error number returned is like WSAMSGSIZE, but nbase.h includes #defines to correlate many of the common UNIX errors with their closest Windows equivalents. So you can use EMSGSIZE or EINTR. */int socket_errno();/* The usleep() function is important as well */#ifndef HAVE_USLEEP#if defined( HAVE_NANOSLEEP) || defined(WIN32)void usleep(unsigned long usec);#endif#endif/***************** String functions -- See nbase_str.c ******************//* I modified this conditional because !@# Redhat does not easily provide the prototype even though the function exists */#if !defined(HAVE_STRCASESTR) || (defined(LINUX) && !defined(__USE_GNU) && !defined(_GNU_SOURCE))/* strcasestr is like strstr() except case insensitive */char *strcasestr(const char *haystack, const char *pneedle);#endif#ifndef HAVE_STRCASECMPint strcasecmp(const char *s1, const char *s2);#endif#ifndef HAVE_STRNCASECMPint strncasecmp(const char *s1, const char *s2, size_t n);#endif#ifndef HAVE_GETTIMEOFDAYint gettimeofday(struct timeval *tv, struct timeval *tz);#endif#ifndef HAVE_SLEEPunsigned int sleep(unsigned int seconds);#endif/* Strncpy is like strcpy() except it ALWAYS zero-terminates, even if it must truncate */int Strncpy(char *dest, const char *src, size_t n);int Vsnprintf(char *, size_t, const char *, va_list) __attribute__ ((format (printf, 3, 0)));int Snprintf(char *, size_t, const char *, ...) __attribute__ ((format (printf, 3, 4)));/* Trivial function that returns nonzero if all characters in str of length strlength are printable (as defined by isprint()) */int stringisprintable(const char *str, int strlength);/* Convert non-printable characters to replchar in the string */void replacenonprintable(char *str, int strlength, char replchar);/* Portable, incompatible replacements for dirname and basename. */char *path_get_dirname(const char *path);char *path_get_basename(const char *path);/* A few simple wrappers for the most common memory allocation routines which will exit() if the allocation fails, so you don't always have to check -- see nbase_memalloc.c */void *safe_malloc(size_t size);void *safe_realloc(void *ptr, size_t size);/* Zero-initializing version of safe_malloc */void *safe_zalloc(size_t size); /* Some routines for obtaining simple (not secure on systems that lack /dev/random and friends' "random" numbers */int get_random_bytes(void *buf, int numbytes);int get_random_int();unsigned short get_random_ushort();unsigned int get_random_uint();u32 get_random_u32();u16 get_random_u16();u8 get_random_u8();/* CRC16 Cyclic Redundancy Check */unsigned long crc16(unsigned char *buf, int len);#ifndef STDIN_FILENO#define STDIN_FILENO 0#endif#ifndef STDOUT_FILENO#define STDOUT_FILENO 1#endif#ifndef STDERR_FILENO#define STDERR_FILENO 2#endif#include "nbase_ipv6.h"#ifdef __cplusplus}#endif#endif /* NBASE_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?