]> git.proxmox.com Git - libgit2.git/blame - src/posix.h
Define WINHTTP_IGNORE_REQUEST_TOTAL_LENGTH if not defined
[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
ca1b6e54 15#ifndef S_IFGITLINK
f79026b4
VM
16#define S_IFGITLINK 0160000
17#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
ca1b6e54
RB
18#endif
19
20/* if S_ISGID is not defined, then don't try to set it */
21#ifndef S_ISGID
22#define S_ISGID 0
23#endif
f79026b4
VM
24
25#if !defined(O_BINARY)
26#define O_BINARY 0
27#endif
3d3ea4dc
RB
28#if !defined(O_CLOEXEC)
29#define O_CLOEXEC 0
30#endif
f79026b4 31
0197d410 32/* Determine whether an errno value indicates that a read or write failed
33 * because the descriptor is blocked.
34 */
35#if defined(EWOULDBLOCK)
36#define GIT_ISBLOCKED(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)
37#else
38#define GIT_ISBLOCKED(e) ((e) == EAGAIN)
39#endif
40
f79026b4
VM
41typedef int git_file;
42
f79026b4
VM
43/**
44 * Standard POSIX Methods
45 *
46 * All the methods starting with the `p_` prefix are
e40f1c2d 47 * direct ports of the standard POSIX methods.
f79026b4
VM
48 *
49 * Some of the methods are slightly wrapped to provide
50 * saner defaults. Some of these methods are emulated
1b57699a 51 * in Windows platforms.
f79026b4
VM
52 *
53 * Use your manpages to check the docs on these.
f79026b4 54 */
7998ae5a 55
f79026b4 56extern int p_read(git_file fd, void *buf, size_t cnt);
2ba222c5 57extern int p_write(git_file fd, const void *buf, size_t cnt);
f79026b4 58
7998ae5a 59#define p_fstat(f,b) fstat(f, b)
f79026b4 60#define p_lseek(f,n,w) lseek(f, n, w)
7998ae5a 61#define p_close(fd) close(fd)
ce8cd006 62#define p_umask(m) umask(m)
7998ae5a 63
3191ae89 64extern int p_open(const char *path, int flags, ...);
33127043 65extern int p_creat(const char *path, mode_t mode);
7998ae5a 66extern int p_getcwd(char *buffer_out, size_t size);
0c49ec2d 67extern int p_rename(const char *from, const char *to);
7998ae5a
PB
68
69#ifndef GIT_WIN32
70
f79026b4 71#define p_stat(p,b) stat(p, b)
f79026b4
VM
72#define p_chdir(p) chdir(p)
73#define p_rmdir(p) rmdir(p)
74#define p_chmod(p,m) chmod(p, m)
dd44887a 75#define p_access(p,m) access(p,m)
0731a5b4 76#define p_ftruncate(fd, sz) ftruncate(fd, sz)
44ef8b1b
RB
77#define p_recv(s,b,l,f) recv(s,b,l,f)
78#define p_send(s,b,l,f) send(s,b,l,f)
79typedef int GIT_SOCKET;
80#define INVALID_SOCKET -1
81
9ecf860d
BS
82#define p_localtime_r localtime_r
83#define p_gmtime_r gmtime_r
9ecf860d 84
44ef8b1b
RB
85#else
86
87typedef SOCKET GIT_SOCKET;
9ecf860d
BS
88extern struct tm * p_localtime_r (const time_t *timer, struct tm *result);
89extern struct tm * p_gmtime_r (const time_t *timer, struct tm *result);
7998ae5a
PB
90
91#endif
f79026b4 92
2fcf9c82
VM
93/**
94 * Platform-dependent methods
95 */
96#ifdef GIT_WIN32
97# include "win32/posix.h"
98#else
99# include "unix/posix.h"
100#endif
101
24f3024f 102#include "strnlen.h"
57f31f05 103
798e4d53
VM
104#ifdef NO_READDIR_R
105# include <dirent.h>
d043013f 106GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
a8df98c6
CY
107{
108 GIT_UNUSED(entry);
109 *result = readdir(dirp);
110 return 0;
111}
798e4d53
VM
112#else /* NO_READDIR_R */
113# define p_readdir_r(d,e,r) readdir_r(d,e,r)
aa5a92d1 114#endif
74fa4bfa 115
798e4d53 116#ifdef NO_ADDRINFO
60029f49 117# include <netdb.h>
798e4d53
VM
118struct addrinfo {
119 struct hostent *ai_hostent;
120 struct servent *ai_servent;
121 struct sockaddr_in ai_addr_in;
122 struct sockaddr *ai_addr;
123 size_t ai_addrlen;
124 int ai_family;
125 int ai_socktype;
126 int ai_protocol;
127 long ai_port;
128 struct addrinfo *ai_next;
129};
130
131extern int p_getaddrinfo(const char *host, const char *port,
132 struct addrinfo *hints, struct addrinfo **info);
133extern void p_freeaddrinfo(struct addrinfo *info);
134extern const char *p_gai_strerror(int ret);
135#else
136# define p_getaddrinfo(a, b, c, d) getaddrinfo(a, b, c, d)
137# define p_freeaddrinfo(a) freeaddrinfo(a)
138# define p_gai_strerror(c) gai_strerror(c)
139#endif /* NO_ADDRINFO */
140
f79026b4 141#endif