posix.h 2.8 KB
Newer Older
Vicent Marti committed
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
Vicent Marti committed
3 4 5 6
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
7 8
#ifndef INCLUDE_unix_posix_h__
#define INCLUDE_unix_posix_h__
Vicent Marti committed
9

10
#include "git2_util.h"
11

12
#include <stdio.h>
13
#include <dirent.h>
14
#include <sys/param.h>
15
#include <sys/time.h>
16
#include <sys/stat.h>
17

18 19 20 21 22
typedef int GIT_SOCKET;
#define INVALID_SOCKET -1

#define p_lseek(f,n,w) lseek(f, n, w)
#define p_fstat(f,b) fstat(f, b)
Vicent Marti committed
23
#define p_lstat(p,b) lstat(p,b)
24
#define p_stat(p,b) stat(p, b)
25

26 27 28 29 30 31 32 33
#if defined(GIT_USE_STAT_MTIMESPEC)
# define st_atime_nsec st_atimespec.tv_nsec
# define st_mtime_nsec st_mtimespec.tv_nsec
# define st_ctime_nsec st_ctimespec.tv_nsec
#elif defined(GIT_USE_STAT_MTIM)
# define st_atime_nsec st_atim.tv_nsec
# define st_mtime_nsec st_mtim.tv_nsec
# define st_ctime_nsec st_ctim.tv_nsec
34
#elif !defined(GIT_USE_STAT_MTIME_NSEC) && defined(GIT_USE_NSEC)
35 36 37
# error GIT_USE_NSEC defined but unknown struct stat nanosecond type
#endif

38 39
#define p_utimes(f, t) utimes(f, t)

Vicent Marti committed
40
#define p_readlink(a, b, c) readlink(a, b, c)
41
#define p_symlink(o,n) symlink(o, n)
Vicent Marti committed
42 43 44
#define p_link(o,n) link(o, n)
#define p_unlink(p) unlink(p)
#define p_mkdir(p,m) mkdir(p, m)
45
extern char *p_realpath(const char *, char *);
46

47 48 49 50 51 52
GIT_INLINE(int) p_fsync(int fd)
{
	p_fsync__cnt++;
	return fsync(fd);
}

53 54 55 56
#define p_recv(s,b,l,f) recv(s,b,l,f)
#define p_send(s,b,l,f) send(s,b,l,f)
#define p_inet_pton(a, b, c) inet_pton(a, b, c)

57 58
#define p_strcasecmp(s1, s2) strcasecmp(s1, s2)
#define p_strncasecmp(s1, s2, c) strncasecmp(s1, s2, c)
59
#define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a)
60
#define p_snprintf snprintf
61 62 63 64
#define p_chdir(p) chdir(p)
#define p_rmdir(p) rmdir(p)
#define p_access(p,m) access(p,m)
#define p_ftruncate(fd, sz) ftruncate(fd, sz)
Vicent Marti committed
65

66 67 68 69 70 71 72 73 74 75 76 77 78
/*
 * Pre-Android 5 did not implement a virtual filesystem atop FAT
 * partitions for Unix permissions, which causes chmod to fail. However,
 * Unix permissions have no effect on Android anyway as file permissions
 * are not actually managed this way, so treating it as a no-op across
 * all Android is safe.
 */
#ifdef __ANDROID__
# define p_chmod(p,m) 0
#else
# define p_chmod(p,m) chmod(p, m)
#endif

79 80 81
/* see win32/posix.h for explanation about why this exists */
#define p_lstat_posixly(p,b) lstat(p,b)

82 83 84
#define p_localtime_r(c, r) localtime_r(c, r)
#define p_gmtime_r(c, r) gmtime_r(c, r)

85 86
#define p_timeval timeval

87
#ifdef GIT_USE_FUTIMENS
88
GIT_INLINE(int) p_futimes(int f, const struct p_timeval t[2])
89 90 91 92 93 94 95 96 97 98 99 100
{
	struct timespec s[2];
	s[0].tv_sec = t[0].tv_sec;
	s[0].tv_nsec = t[0].tv_usec * 1000;
	s[1].tv_sec = t[1].tv_sec;
	s[1].tv_nsec = t[1].tv_usec * 1000;
	return futimens(f, s);
}
#else
# define p_futimes futimes
#endif

101 102 103
#define p_pread(f, d, s, o) pread(f, d, s, o)
#define p_pwrite(f, d, s, o) pwrite(f, d, s, o)

Vicent Marti committed
104
#endif