[go: up one dir, main page]

Menu

[r25]: / dtorrent / trunk / compat.c  Maximize  Restore  History

Download this file

59 lines (45 with data), 1.0 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include "def.h"
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#include "compat.h"
#ifndef HAVE_CLOCK_GETTIME
int 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_VSNPRINTF
int 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_SNPRINTF
int 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