]> git.proxmox.com Git - libgit2.git/blame - src/posix.h
Add `ENABLE_SYNCHRONIZED_OBJECT_CREATION` option
[libgit2.git] / src / posix.h
CommitLineData
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
85typedef 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 100extern ssize_t p_read(git_file fd, void *buf, size_t cnt);
2ba222c5 101extern 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 106extern int p_open(const char *path, int flags, ...);
33127043 107extern int p_creat(const char *path, mode_t mode);
7998ae5a 108extern int p_getcwd(char *buffer_out, size_t size);
0c49ec2d 109extern int p_rename(const char *from, const char *to);
7998ae5a 110
62e562f9 111extern int git__page_size(size_t *page_size);
87c18197 112extern int git__mmap_alignment(size_t *page_size);
62e562f9 113
2fcf9c82
VM
114/**
115 * Platform-dependent methods
116 */
117#ifdef GIT_WIN32
118# include "win32/posix.h"
119#else
120# include "unix/posix.h"
121#endif
122
24f3024f 123#include "strnlen.h"
57f31f05 124
798e4d53 125#ifdef NO_READDIR_R
d043013f 126GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
a8df98c6
CY
127{
128 GIT_UNUSED(entry);
129 *result = readdir(dirp);
130 return 0;
131}
798e4d53
VM
132#else /* NO_READDIR_R */
133# define p_readdir_r(d,e,r) readdir_r(d,e,r)
aa5a92d1 134#endif
74fa4bfa 135
798e4d53 136#ifdef NO_ADDRINFO
60029f49 137# include <netdb.h>
798e4d53
VM
138struct addrinfo {
139 struct hostent *ai_hostent;
140 struct servent *ai_servent;
141 struct sockaddr_in ai_addr_in;
142 struct sockaddr *ai_addr;
143 size_t ai_addrlen;
144 int ai_family;
145 int ai_socktype;
146 int ai_protocol;
147 long ai_port;
148 struct addrinfo *ai_next;
149};
150
151extern int p_getaddrinfo(const char *host, const char *port,
152 struct addrinfo *hints, struct addrinfo **info);
153extern void p_freeaddrinfo(struct addrinfo *info);
154extern const char *p_gai_strerror(int ret);
155#else
156# define p_getaddrinfo(a, b, c, d) getaddrinfo(a, b, c, d)
157# define p_freeaddrinfo(a) freeaddrinfo(a)
158# define p_gai_strerror(c) gai_strerror(c)
159#endif /* NO_ADDRINFO */
160
f79026b4 161#endif