At this point it becomes clear there ACKs and ACKs
[swift-upb.git] / compat.h
1 /*
2  *  compat.h
3  *  compatibility wrappers
4  *
5  *  Created by Arno Bakker, Victor Grishchenko
6  *  Copyright 2009 Delft University of Technology. All rights reserved.
7  *
8  */
9 #ifndef SWIFT_COMPAT_H
10 #define SWIFT_COMPAT_H
11
12 #ifdef _MSC_VER
13 #include "compat/stdint.h"
14 #else
15 #include <stdint.h>
16 #endif
17 #ifdef _WIN32
18 #include <winsock2.h>
19 #include <sys/stat.h>
20 #include <io.h>
21 #else
22 #include <sys/mman.h>
23 #endif
24 #include <fcntl.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27
28 #ifdef _WIN32
29 #define open(a,b,c)    _open(a,b,c)
30 #define S_IRUSR _S_IREAD
31 #define S_IWUSR    _S_IWRITE
32 #define S_IRGRP _S_IREAD
33 #define S_IROTH _S_IREAD
34 #endif
35
36 namespace swift {
37
38 /** tint is the time integer type; microsecond-precise. */
39 typedef int64_t tint;
40 #define TINT_HOUR ((tint)1000000*60*60)
41 #define TINT_MIN ((tint)1000000*60)
42 #define TINT_SEC ((tint)1000000)
43 #define TINT_MSEC ((tint)1000)
44 #define TINT_uSEC ((tint)1)
45 #define TINT_NEVER ((tint)0x7fffffffffffffffLL)
46
47
48 size_t  file_size (int fd);
49
50 int     file_seek (int fd, size_t offset);
51
52 int     file_resize (int fd, size_t new_size);
53
54 void*   memory_map (int fd, size_t size=0);
55 void    memory_unmap (int fd, void*, size_t size);
56
57 void    print_error (const char* msg);
58
59 #ifdef _WIN32
60
61 /** UNIX pread approximation. Does change file pointer. Is not thread-safe */
62 size_t  pread(int fildes, void *buf, size_t nbyte, long offset);
63
64 /** UNIX pwrite approximation. Does change file pointer. Is not thread-safe */
65 size_t  pwrite(int fildes, const void *buf, size_t nbyte, long offset);
66
67 int     inet_aton(const char *cp, struct in_addr *inp);
68
69 #endif
70
71 tint    usec_time ();
72
73 };
74
75 #endif
76