]>
Commit | Line | Data |
---|---|---|
f79026b4 | 1 | /* |
359fc2d2 | 2 | * Copyright (C) the libgit2 contributors. All rights reserved. |
bb742ede VM |
3 | * |
4 | * This file is part of libgit2, distributed under the GNU GPL v2 with | |
5 | * a Linking Exception. For full terms see the included COPYING file. | |
f79026b4 VM |
6 | */ |
7 | #ifndef INCLUDE_posix_h__ | |
8 | #define INCLUDE_posix_h__ | |
9 | ||
10 | #include "common.h" | |
eae0bfdc | 11 | |
f79026b4 VM |
12 | #include <fcntl.h> |
13 | #include <time.h> | |
14 | ||
2f795d8f | 15 | /* stat: file mode type testing macros */ |
ca1b6e54 | 16 | #ifndef S_IFGITLINK |
f79026b4 VM |
17 | #define S_IFGITLINK 0160000 |
18 | #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK) | |
ca1b6e54 RB |
19 | #endif |
20 | ||
2f795d8f JG |
21 | #ifndef S_IFLNK |
22 | #define S_IFLNK 0120000 | |
23 | #undef _S_IFLNK | |
24 | #define _S_IFLNK S_IFLNK | |
25 | #endif | |
26 | ||
89d403cc ET |
27 | #ifndef S_IWUSR |
28 | #define S_IWUSR 00200 | |
29 | #endif | |
30 | ||
2f795d8f JG |
31 | #ifndef S_IXUSR |
32 | #define S_IXUSR 00100 | |
33 | #endif | |
34 | ||
35 | #ifndef S_ISLNK | |
36 | #define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) | |
37 | #endif | |
38 | ||
39 | #ifndef S_ISDIR | |
40 | #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) | |
41 | #endif | |
42 | ||
43 | #ifndef S_ISREG | |
44 | #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) | |
45 | #endif | |
46 | ||
47 | #ifndef S_ISFIFO | |
48 | #define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) | |
49 | #endif | |
50 | ||
ca1b6e54 RB |
51 | /* if S_ISGID is not defined, then don't try to set it */ |
52 | #ifndef S_ISGID | |
53 | #define S_ISGID 0 | |
54 | #endif | |
f79026b4 | 55 | |
2f795d8f | 56 | #ifndef O_BINARY |
f79026b4 VM |
57 | #define O_BINARY 0 |
58 | #endif | |
2f795d8f | 59 | #ifndef O_CLOEXEC |
3d3ea4dc RB |
60 | #define O_CLOEXEC 0 |
61 | #endif | |
eae0bfdc PP |
62 | #ifndef SOCK_CLOEXEC |
63 | #define SOCK_CLOEXEC 0 | |
64 | #endif | |
f79026b4 | 65 | |
2f795d8f JG |
66 | /* access() mode parameter #defines */ |
67 | #ifndef F_OK | |
68 | #define F_OK 0 /* existence check */ | |
69 | #endif | |
70 | #ifndef W_OK | |
71 | #define W_OK 2 /* write mode check */ | |
72 | #endif | |
73 | #ifndef R_OK | |
74 | #define R_OK 4 /* read mode check */ | |
75 | #endif | |
76 | ||
0197d410 | 77 | /* Determine whether an errno value indicates that a read or write failed |
78 | * because the descriptor is blocked. | |
79 | */ | |
80 | #if defined(EWOULDBLOCK) | |
81 | #define GIT_ISBLOCKED(e) ((e) == EAGAIN || (e) == EWOULDBLOCK) | |
82 | #else | |
83 | #define GIT_ISBLOCKED(e) ((e) == EAGAIN) | |
84 | #endif | |
85 | ||
2f795d8f JG |
86 | /* define some standard errnos that the runtime may be missing. for example, |
87 | * mingw lacks EAFNOSUPPORT. */ | |
88 | #ifndef EAFNOSUPPORT | |
89 | #define EAFNOSUPPORT (INT_MAX-1) | |
90 | #endif | |
91 | ||
c25aa7cd PP |
92 | /* Compiler independent macro to handle signal interrpted system calls */ |
93 | #define HANDLE_EINTR(result, x) do { \ | |
94 | result = (x); \ | |
95 | } while (result == -1 && errno == EINTR); | |
96 | ||
97 | ||
22a2d3d5 UG |
98 | /* Provide a 64-bit size for offsets. */ |
99 | ||
100 | #if defined(_MSC_VER) | |
101 | typedef __int64 off64_t; | |
102 | #elif defined(__HAIKU__) | |
103 | typedef __haiku_std_int64 off64_t; | |
104 | #elif defined(__APPLE__) | |
105 | typedef __int64_t off64_t; | |
106 | #else | |
107 | typedef int64_t off64_t; | |
108 | #endif | |
109 | ||
f79026b4 VM |
110 | typedef int git_file; |
111 | ||
f79026b4 VM |
112 | /** |
113 | * Standard POSIX Methods | |
114 | * | |
115 | * All the methods starting with the `p_` prefix are | |
e40f1c2d | 116 | * direct ports of the standard POSIX methods. |
f79026b4 VM |
117 | * |
118 | * Some of the methods are slightly wrapped to provide | |
119 | * saner defaults. Some of these methods are emulated | |
1b57699a | 120 | * in Windows platforms. |
f79026b4 VM |
121 | * |
122 | * Use your manpages to check the docs on these. | |
f79026b4 | 123 | */ |
7998ae5a | 124 | |
c6ba8a37 | 125 | extern ssize_t p_read(git_file fd, void *buf, size_t cnt); |
2ba222c5 | 126 | extern int p_write(git_file fd, const void *buf, size_t cnt); |
f79026b4 | 127 | |
c25aa7cd PP |
128 | extern ssize_t p_pread(int fd, void *data, size_t size, off64_t offset); |
129 | extern ssize_t p_pwrite(int fd, const void *data, size_t size, off64_t offset); | |
130 | ||
7998ae5a | 131 | #define p_close(fd) close(fd) |
ce8cd006 | 132 | #define p_umask(m) umask(m) |
7998ae5a | 133 | |
3191ae89 | 134 | extern int p_open(const char *path, int flags, ...); |
33127043 | 135 | extern int p_creat(const char *path, mode_t mode); |
7998ae5a | 136 | extern int p_getcwd(char *buffer_out, size_t size); |
0c49ec2d | 137 | extern int p_rename(const char *from, const char *to); |
7998ae5a | 138 | |
62e562f9 | 139 | extern int git__page_size(size_t *page_size); |
87c18197 | 140 | extern int git__mmap_alignment(size_t *page_size); |
62e562f9 | 141 | |
e6ed0d2f ET |
142 | /* The number of times `p_fsync` has been called. Note that this is for |
143 | * test code only; it it not necessarily thread-safe and should not be | |
144 | * relied upon in production. | |
145 | */ | |
146 | extern size_t p_fsync__cnt; | |
147 | ||
2fcf9c82 VM |
148 | /** |
149 | * Platform-dependent methods | |
150 | */ | |
151 | #ifdef GIT_WIN32 | |
152 | # include "win32/posix.h" | |
153 | #else | |
154 | # include "unix/posix.h" | |
155 | #endif | |
156 | ||
24f3024f | 157 | #include "strnlen.h" |
57f31f05 | 158 | |
798e4d53 | 159 | #ifdef NO_READDIR_R |
d043013f | 160 | GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) |
a8df98c6 CY |
161 | { |
162 | GIT_UNUSED(entry); | |
163 | *result = readdir(dirp); | |
164 | return 0; | |
165 | } | |
798e4d53 VM |
166 | #else /* NO_READDIR_R */ |
167 | # define p_readdir_r(d,e,r) readdir_r(d,e,r) | |
aa5a92d1 | 168 | #endif |
74fa4bfa | 169 | |
798e4d53 | 170 | #ifdef NO_ADDRINFO |
60029f49 | 171 | # include <netdb.h> |
798e4d53 VM |
172 | struct addrinfo { |
173 | struct hostent *ai_hostent; | |
174 | struct servent *ai_servent; | |
175 | struct sockaddr_in ai_addr_in; | |
176 | struct sockaddr *ai_addr; | |
177 | size_t ai_addrlen; | |
178 | int ai_family; | |
179 | int ai_socktype; | |
180 | int ai_protocol; | |
181 | long ai_port; | |
182 | struct addrinfo *ai_next; | |
183 | }; | |
184 | ||
185 | extern int p_getaddrinfo(const char *host, const char *port, | |
186 | struct addrinfo *hints, struct addrinfo **info); | |
187 | extern void p_freeaddrinfo(struct addrinfo *info); | |
188 | extern const char *p_gai_strerror(int ret); | |
189 | #else | |
190 | # define p_getaddrinfo(a, b, c, d) getaddrinfo(a, b, c, d) | |
191 | # define p_freeaddrinfo(a) freeaddrinfo(a) | |
192 | # define p_gai_strerror(c) gai_strerror(c) | |
193 | #endif /* NO_ADDRINFO */ | |
194 | ||
f79026b4 | 195 | #endif |