]>
git.proxmox.com Git - libgit2.git/blob - src/posix.h
2934f247923825e1be05eae68d1854e60da1c695
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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.
7 #ifndef INCLUDE_posix_h__
8 #define INCLUDE_posix_h__
16 /* stat: file mode type testing macros */
18 #define S_IFGITLINK 0160000
19 #define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
23 #define S_IFLNK 0120000
25 #define _S_IFLNK S_IFLNK
37 #define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
41 #define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
45 #define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
49 #define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
52 /* if S_ISGID is not defined, then don't try to set it */
64 #define SOCK_CLOEXEC 0
67 /* access() mode parameter #defines */
69 #define F_OK 0 /* existence check */
72 #define W_OK 2 /* write mode check */
75 #define R_OK 4 /* read mode check */
78 /* Determine whether an errno value indicates that a read or write failed
79 * because the descriptor is blocked.
81 #if defined(EWOULDBLOCK)
82 #define GIT_ISBLOCKED(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)
84 #define GIT_ISBLOCKED(e) ((e) == EAGAIN)
87 /* define some standard errnos that the runtime may be missing. for example,
88 * mingw lacks EAFNOSUPPORT. */
90 #define EAFNOSUPPORT (INT_MAX-1)
96 * Standard POSIX Methods
98 * All the methods starting with the `p_` prefix are
99 * direct ports of the standard POSIX methods.
101 * Some of the methods are slightly wrapped to provide
102 * saner defaults. Some of these methods are emulated
103 * in Windows platforms.
105 * Use your manpages to check the docs on these.
108 extern ssize_t
p_read(git_file fd
, void *buf
, size_t cnt
);
109 extern int p_write(git_file fd
, const void *buf
, size_t cnt
);
111 #define p_close(fd) close(fd)
112 #define p_umask(m) umask(m)
114 extern int p_open(const char *path
, int flags
, ...);
115 extern int p_creat(const char *path
, mode_t mode
);
116 extern int p_getcwd(char *buffer_out
, size_t size
);
117 extern int p_rename(const char *from
, const char *to
);
119 extern int git__page_size(size_t *page_size
);
120 extern int git__mmap_alignment(size_t *page_size
);
122 /* The number of times `p_fsync` has been called. Note that this is for
123 * test code only; it it not necessarily thread-safe and should not be
124 * relied upon in production.
126 extern size_t p_fsync__cnt
;
129 * Platform-dependent methods
132 # include "win32/posix.h"
134 # include "unix/posix.h"
140 GIT_INLINE(int) p_readdir_r(DIR *dirp
, struct dirent
*entry
, struct dirent
**result
)
143 *result
= readdir(dirp
);
146 #else /* NO_READDIR_R */
147 # define p_readdir_r(d,e,r) readdir_r(d,e,r)
153 struct hostent
*ai_hostent
;
154 struct servent
*ai_servent
;
155 struct sockaddr_in ai_addr_in
;
156 struct sockaddr
*ai_addr
;
162 struct addrinfo
*ai_next
;
165 extern int p_getaddrinfo(const char *host
, const char *port
,
166 struct addrinfo
*hints
, struct addrinfo
**info
);
167 extern void p_freeaddrinfo(struct addrinfo
*info
);
168 extern const char *p_gai_strerror(int ret
);
170 # define p_getaddrinfo(a, b, c, d) getaddrinfo(a, b, c, d)
171 # define p_freeaddrinfo(a) freeaddrinfo(a)
172 # define p_gai_strerror(c) gai_strerror(c)
173 #endif /* NO_ADDRINFO */