aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/basetypes/MCWin32.h
blob: 24ec7448493553aea9113bf976c71e63ded8e120 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef MAILCORE_MCWIN32_H

#define MAILCORE_MCWIN32_H

// It must be included at the beginning of the file.

#ifdef _MSC_VER

#define _CRT_RAND_S
#include <stdlib.h>

#ifdef __cplusplus
#include <algorithm>
#endif

#include <stdio.h>
#include <Winsock2.h>
#include <windows.h>
#include <rpc.h>
#include <time.h>
#include <sys/stat.h>
#include <errno.h>
#include <direct.h>

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define strcasestr mailcore::win32_strcasestr
#define strdup _strdup
#define fileno _fileno
#define unlink _unlink
#define mkdir _mkdir
#define fopen mailcore::win32_fopen
#define gmtime_r mailcore::win32_gmtime_r
#define localtime_r mailcore::win32_localtime_r
#define gettimeofday mailcore::win32_gettimeofday
#define getpid mailcore::win32_getpid
#define snprintf mailcore::win32_snprintf
#define vasprintf mailcore::win32_vasprintf
#define timegm mailcore::win32_timegm
#define random mailcore::win32_random
#define getpid mailcore::win32_getpid
#define mkdtemp mailcore::win32_mkdtemp

#define S_ISDIR(m) ((m & _S_IFDIR) != 0)

#ifndef pid_t
typedef int pid_t;
#endif

#ifdef __cplusplus
namespace mailcore {

    struct tm * win32_gmtime_r(const time_t *clock, struct tm *result);
    struct tm * win32_localtime_r(const time_t *clock, struct tm *result);
    time_t win32_timegm(struct tm *timeptr);
    int win32_gettimeofday(struct timeval * tp, struct timezone * tzp);
    
    FILE * win32_fopen(const char * filename, const char * mode);
    int win32_vasprintf(char **strp, const char *fmt, va_list ap);
    int win32_snprintf(char * str, size_t size, const char * format, ...);

    char * win32_strcasestr(const char * s, const char * find);
    
    long win32_random(void);
    pid_t win32_getpid(void);
    
    char * win32_mkdtemp(char *name_template);
}
#endif

#endif

#endif