]>
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" | |
11 | #include <fcntl.h> | |
12 | #include <time.h> | |
824d5e4d | 13 | #include "fnmatch.h" |
f79026b4 | 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 | ||
27 | #ifndef S_IXUSR | |
28 | #define S_IXUSR 00100 | |
29 | #endif | |
30 | ||
31 | #ifndef S_ISLNK | |
32 | #define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) | |
33 | #endif | |
34 | ||
35 | #ifndef S_ISDIR | |
36 | #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) | |
37 | #endif | |
38 | ||
39 | #ifndef S_ISREG | |
40 | #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) | |
41 | #endif | |
42 | ||
43 | #ifndef S_ISFIFO | |
44 | #define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) | |
45 | #endif | |
46 | ||
ca1b6e54 RB |
47 | /* if S_ISGID is not defined, then don't try to set it */ |
48 | #ifndef S_ISGID | |
49 | #define S_ISGID 0 | |
50 | #endif | |
f79026b4 | 51 | |
2f795d8f | 52 | #ifndef O_BINARY |
f79026b4 VM |
53 | #define O_BINARY 0 |
54 | #endif | |
2f795d8f | 55 | #ifndef O_CLOEXEC |
3d3ea4dc RB |
56 | #define O_CLOEXEC 0 |
57 | #endif | |
f79026b4 | 58 | |
2f795d8f JG |
59 | /* access() mode parameter #defines */ |
60 | #ifndef F_OK | |
61 | #define F_OK 0 /* existence check */ | |
62 | #endif | |
63 | #ifndef W_OK | |
64 | #define W_OK 2 /* write mode check */ | |
65 | #endif | |
66 | #ifndef R_OK | |
67 | #define R_OK 4 /* read mode check */ | |
68 | #endif | |
69 | ||
0197d410 | 70 | /* Determine whether an errno value indicates that a read or write failed |
71 | * because the descriptor is blocked. | |
72 | */ | |
73 | #if defined(EWOULDBLOCK) | |
74 | #define GIT_ISBLOCKED(e) ((e) == EAGAIN || (e) == EWOULDBLOCK) | |
75 | #else | |
76 | #define GIT_ISBLOCKED(e) ((e) == EAGAIN) | |
77 | #endif | |
78 | ||
2f795d8f JG |
79 | /* define some standard errnos that the runtime may be missing. for example, |
80 | * mingw lacks EAFNOSUPPORT. */ | |
81 | #ifndef EAFNOSUPPORT | |
82 | #define EAFNOSUPPORT (INT_MAX-1) | |
83 | #endif | |
84 | ||
f79026b4 VM |
85 | typedef int git_file; |
86 | ||
f79026b4 VM |
87 | /** |
88 | * Standard POSIX Methods | |
89 | * | |
90 | * All the methods starting with the `p_` prefix are | |
e40f1c2d | 91 | * direct ports of the standard POSIX methods. |
f79026b4 VM |
92 | * |
93 | * Some of the methods are slightly wrapped to provide | |
94 | * saner defaults. Some of these methods are emulated | |
1b57699a | 95 | * in Windows platforms. |
f79026b4 VM |
96 | * |
97 | * Use your manpages to check the docs on these. | |
f79026b4 | 98 | */ |
7998ae5a | 99 | |
c6ba8a37 | 100 | extern ssize_t p_read(git_file fd, void *buf, size_t cnt); |
2ba222c5 | 101 | extern int p_write(git_file fd, const void *buf, size_t cnt); |
f79026b4 | 102 | |
7998ae5a | 103 | #define p_close(fd) close(fd) |
ce8cd006 | 104 | #define p_umask(m) umask(m) |
7998ae5a | 105 | |
3191ae89 | 106 | extern int p_open(const char *path, int flags, ...); |
33127043 | 107 | extern int p_creat(const char *path, mode_t mode); |
7998ae5a | 108 | extern int p_getcwd(char *buffer_out, size_t size); |
0c49ec2d | 109 | extern int p_rename(const char *from, const char *to); |
7998ae5a | 110 | |
62e562f9 AM |
111 | extern int git__page_size(size_t *page_size); |
112 | ||
2fcf9c82 VM |
113 | /** |
114 | * Platform-dependent methods | |
115 | */ | |
116 | #ifdef GIT_WIN32 | |
117 | # include "win32/posix.h" | |
118 | #else | |
119 | # include "unix/posix.h" | |
120 | #endif | |
121 | ||
24f3024f | 122 | #include "strnlen.h" |
57f31f05 | 123 | |
798e4d53 | 124 | #ifdef NO_READDIR_R |
d043013f | 125 | GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result) |
a8df98c6 CY |
126 | { |
127 | GIT_UNUSED(entry); | |
128 | *result = readdir(dirp); | |
129 | return 0; | |
130 | } | |
798e4d53 VM |
131 | #else /* NO_READDIR_R */ |
132 | # define p_readdir_r(d,e,r) readdir_r(d,e,r) | |
aa5a92d1 | 133 | #endif |
74fa4bfa | 134 | |
798e4d53 | 135 | #ifdef NO_ADDRINFO |
60029f49 | 136 | # include <netdb.h> |
798e4d53 VM |
137 | struct addrinfo { |
138 | struct hostent *ai_hostent; | |
139 | struct servent *ai_servent; | |
140 | struct sockaddr_in ai_addr_in; | |
141 | struct sockaddr *ai_addr; | |
142 | size_t ai_addrlen; | |
143 | int ai_family; | |
144 | int ai_socktype; | |
145 | int ai_protocol; | |
146 | long ai_port; | |
147 | struct addrinfo *ai_next; | |
148 | }; | |
149 | ||
150 | extern int p_getaddrinfo(const char *host, const char *port, | |
151 | struct addrinfo *hints, struct addrinfo **info); | |
152 | extern void p_freeaddrinfo(struct addrinfo *info); | |
153 | extern const char *p_gai_strerror(int ret); | |
154 | #else | |
155 | # define p_getaddrinfo(a, b, c, d) getaddrinfo(a, b, c, d) | |
156 | # define p_freeaddrinfo(a) freeaddrinfo(a) | |
157 | # define p_gai_strerror(c) gai_strerror(c) | |
158 | #endif /* NO_ADDRINFO */ | |
159 | ||
f79026b4 | 160 | #endif |