]> git.proxmox.com Git - libgit2.git/blame - src/unix/posix.h
New upstream version 1.0.0+dfsg.1
[libgit2.git] / src / unix / posix.h
CommitLineData
bb742ede 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.
6 */
eae0bfdc
PP
7#ifndef INCLUDE_unix_posix_h__
8#define INCLUDE_unix_posix_h__
9
10#ifndef LIBGIT2_NO_FEATURES_H
11# include "git2/sys/features.h"
12#endif
f79026b4 13
6fb1c0b4 14#include <stdio.h>
edbfc52c 15#include <dirent.h>
e40f1c2d 16#include <sys/param.h>
85a5e8eb 17#include <sys/time.h>
69c8bf7e 18#include <sys/stat.h>
6fb1c0b4 19
2f795d8f
JG
20typedef int GIT_SOCKET;
21#define INVALID_SOCKET -1
22
2f795d8f
JG
23#define p_lseek(f,n,w) lseek(f, n, w)
24#define p_fstat(f,b) fstat(f, b)
f79026b4 25#define p_lstat(p,b) lstat(p,b)
07d03d31 26#define p_stat(p,b) stat(p, b)
2f795d8f 27
3d6a42d1
ET
28#if defined(GIT_USE_STAT_MTIMESPEC)
29# define st_atime_nsec st_atimespec.tv_nsec
30# define st_mtime_nsec st_mtimespec.tv_nsec
31# define st_ctime_nsec st_ctimespec.tv_nsec
32#elif defined(GIT_USE_STAT_MTIM)
33# define st_atime_nsec st_atim.tv_nsec
34# define st_mtime_nsec st_mtim.tv_nsec
35# define st_ctime_nsec st_ctim.tv_nsec
66a70851 36#elif !defined(GIT_USE_STAT_MTIME_NSEC) && defined(GIT_USE_NSEC)
3d6a42d1
ET
37# error GIT_USE_NSEC defined but unknown struct stat nanosecond type
38#endif
39
121c3171 40#define p_utimes(f, t) utimes(f, t)
121c3171 41
f79026b4 42#define p_readlink(a, b, c) readlink(a, b, c)
ca1b6e54 43#define p_symlink(o,n) symlink(o, n)
f79026b4
VM
44#define p_link(o,n) link(o, n)
45#define p_unlink(p) unlink(p)
46#define p_mkdir(p,m) mkdir(p, m)
662f90e6 47extern char *p_realpath(const char *, char *);
67fcac56 48
e6ed0d2f
ET
49GIT_INLINE(int) p_fsync(int fd)
50{
51 p_fsync__cnt++;
52 return fsync(fd);
53}
54
2f795d8f
JG
55#define p_recv(s,b,l,f) recv(s,b,l,f)
56#define p_send(s,b,l,f) send(s,b,l,f)
57#define p_inet_pton(a, b, c) inet_pton(a, b, c)
58
07d03d31
JG
59#define p_strcasecmp(s1, s2) strcasecmp(s1, s2)
60#define p_strncasecmp(s1, s2, c) strncasecmp(s1, s2, c)
2fc78e70 61#define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
0c9c969a 62#define p_snprintf snprintf
f978b748 63#define p_mkstemp(p) mkstemp(p)
2f795d8f
JG
64#define p_chdir(p) chdir(p)
65#define p_chmod(p,m) chmod(p, m)
66#define p_rmdir(p) rmdir(p)
67#define p_access(p,m) access(p,m)
68#define p_ftruncate(fd, sz) ftruncate(fd, sz)
f79026b4 69
cccacac5
RB
70/* see win32/posix.h for explanation about why this exists */
71#define p_lstat_posixly(p,b) lstat(p,b)
72
2f795d8f
JG
73#define p_localtime_r(c, r) localtime_r(c, r)
74#define p_gmtime_r(c, r) gmtime_r(c, r)
75
35439f59
ET
76#define p_timeval timeval
77
eae0bfdc 78#ifdef GIT_USE_FUTIMENS
35439f59 79GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2])
8649dfd8
ET
80{
81 struct timespec s[2];
82 s[0].tv_sec = t[0].tv_sec;
83 s[0].tv_nsec = t[0].tv_usec * 1000;
84 s[1].tv_sec = t[1].tv_sec;
85 s[1].tv_nsec = t[1].tv_usec * 1000;
86 return futimens(f, s);
87}
88#else
89# define p_futimes futimes
90#endif
91
f79026b4 92#endif