compat.c

来自「最经典的bittorrent协议的实现的源码」· C语言 代码 · 共 59 行

C
59
字号
#include "def.h"#ifdef HAVE_SYS_PARAM_H#include <sys/param.h>#endif#include "compat.h"#ifndef HAVE_CLOCK_GETTIMEint clock_gettime(clockid_t clock_id, struct timespec *tp){  int r = 0;#if defined(HAVE_GETTIMEOFDAY)  struct timeval tv;  if( (r = gettimeofday(&tv, (struct timezone *)0)) == 0 ){    tp->tv_sec = tv.tv_sec;    tp->tv_nsec = tv.tv_usec * 1000;  }#else#error No suitable precision timing functions appear to be available!#error Please report this problem and identify your system platform.#endif  return r;}#endif#ifndef HAVE_VSNPRINTFint vsnprintf(char *str, size_t size, const char *format, va_list ap){  int r;  char *buffer[4*MAXPATHLEN];  // git-r-dun  if( (r = vsprintf(buffer, format, ap)) >= 0){    strncpy(str, buffer, size-1);    str[size] = '\0';  }  return r;}#endif#ifndef HAVE_SNPRINTFint snprintf(char *str, size_t size, const char *format, ...){  int r;  va_list ap;  va_start(ap, format);  r = vsnprintf(str, size, format, ap);  va_end(ap);  return r;}#endif

⌨️ 快捷键说明

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