Blame src/posix.h

Packit ae9e2a
/*
Packit ae9e2a
 * Copyright (C) the libgit2 contributors. All rights reserved.
Packit ae9e2a
 *
Packit ae9e2a
 * This file is part of libgit2, distributed under the GNU GPL v2 with
Packit ae9e2a
 * a Linking Exception. For full terms see the included COPYING file.
Packit ae9e2a
 */
Packit ae9e2a
#ifndef INCLUDE_posix_h__
Packit ae9e2a
#define INCLUDE_posix_h__
Packit ae9e2a
Packit ae9e2a
#include "common.h"
Packit ae9e2a
#include <fcntl.h>
Packit ae9e2a
#include <time.h>
Packit ae9e2a
#include "fnmatch.h"
Packit ae9e2a
Packit ae9e2a
/* stat: file mode type testing macros */
Packit ae9e2a
#ifndef S_IFGITLINK
Packit ae9e2a
#define S_IFGITLINK 0160000
Packit ae9e2a
#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK)
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifndef S_IFLNK
Packit ae9e2a
#define S_IFLNK 0120000
Packit ae9e2a
#undef _S_IFLNK
Packit ae9e2a
#define _S_IFLNK S_IFLNK
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifndef S_IWUSR
Packit ae9e2a
#define S_IWUSR 00200
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifndef S_IXUSR
Packit ae9e2a
#define S_IXUSR 00100
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifndef S_ISLNK
Packit ae9e2a
#define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK)
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifndef S_ISDIR
Packit ae9e2a
#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifndef S_ISREG
Packit ae9e2a
#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifndef S_ISFIFO
Packit ae9e2a
#define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO)
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
/* if S_ISGID is not defined, then don't try to set it */
Packit ae9e2a
#ifndef S_ISGID
Packit ae9e2a
#define S_ISGID 0
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifndef O_BINARY
Packit ae9e2a
#define O_BINARY 0
Packit ae9e2a
#endif
Packit ae9e2a
#ifndef O_CLOEXEC
Packit ae9e2a
#define O_CLOEXEC 0
Packit ae9e2a
#endif
Packit ae9e2a
#ifndef SOCK_CLOEXEC
Packit ae9e2a
#define SOCK_CLOEXEC 0
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
/* access() mode parameter #defines	*/
Packit ae9e2a
#ifndef F_OK
Packit ae9e2a
#define F_OK 0 /* existence check */
Packit ae9e2a
#endif
Packit ae9e2a
#ifndef W_OK
Packit ae9e2a
#define W_OK 2 /* write mode check */
Packit ae9e2a
#endif
Packit ae9e2a
#ifndef R_OK
Packit ae9e2a
#define R_OK 4 /* read mode check */
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
/* Determine whether an errno value indicates that a read or write failed
Packit ae9e2a
 * because the descriptor is blocked.
Packit ae9e2a
 */
Packit ae9e2a
#if defined(EWOULDBLOCK)
Packit ae9e2a
#define GIT_ISBLOCKED(e) ((e) == EAGAIN || (e) == EWOULDBLOCK)
Packit ae9e2a
#else
Packit ae9e2a
#define GIT_ISBLOCKED(e) ((e) == EAGAIN)
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
/* define some standard errnos that the runtime may be missing.  for example,
Packit ae9e2a
 * mingw lacks EAFNOSUPPORT. */
Packit ae9e2a
#ifndef EAFNOSUPPORT
Packit ae9e2a
#define EAFNOSUPPORT (INT_MAX-1)
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
typedef int git_file;
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Standard POSIX Methods
Packit ae9e2a
 *
Packit ae9e2a
 * All the methods starting with the `p_` prefix are
Packit ae9e2a
 * direct ports of the standard POSIX methods.
Packit ae9e2a
 *
Packit ae9e2a
 * Some of the methods are slightly wrapped to provide
Packit ae9e2a
 * saner defaults. Some of these methods are emulated
Packit ae9e2a
 * in Windows platforms.
Packit ae9e2a
 *
Packit ae9e2a
 * Use your manpages to check the docs on these.
Packit ae9e2a
 */
Packit ae9e2a
Packit ae9e2a
extern ssize_t p_read(git_file fd, void *buf, size_t cnt);
Packit ae9e2a
extern int p_write(git_file fd, const void *buf, size_t cnt);
Packit ae9e2a
Packit ae9e2a
#define p_close(fd) close(fd)
Packit ae9e2a
#define p_umask(m) umask(m)
Packit ae9e2a
Packit ae9e2a
extern int p_open(const char *path, int flags, ...);
Packit ae9e2a
extern int p_creat(const char *path, mode_t mode);
Packit ae9e2a
extern int p_getcwd(char *buffer_out, size_t size);
Packit ae9e2a
extern int p_rename(const char *from, const char *to);
Packit ae9e2a
Packit ae9e2a
extern int git__page_size(size_t *page_size);
Packit ae9e2a
extern int git__mmap_alignment(size_t *page_size);
Packit ae9e2a
Packit ae9e2a
/* The number of times `p_fsync` has been called.  Note that this is for
Packit ae9e2a
 * test code only; it it not necessarily thread-safe and should not be
Packit ae9e2a
 * relied upon in production.
Packit ae9e2a
 */
Packit ae9e2a
extern size_t p_fsync__cnt;
Packit ae9e2a
Packit ae9e2a
/**
Packit ae9e2a
 * Platform-dependent methods
Packit ae9e2a
 */
Packit ae9e2a
#ifdef GIT_WIN32
Packit ae9e2a
#	include "win32/posix.h"
Packit ae9e2a
#else
Packit ae9e2a
#	include "unix/posix.h"
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#include "strnlen.h"
Packit ae9e2a
Packit ae9e2a
#ifdef NO_READDIR_R
Packit ae9e2a
GIT_INLINE(int) p_readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result)
Packit ae9e2a
{
Packit ae9e2a
	GIT_UNUSED(entry);
Packit ae9e2a
	*result = readdir(dirp);
Packit ae9e2a
	return 0;
Packit ae9e2a
}
Packit ae9e2a
#else /* NO_READDIR_R */
Packit ae9e2a
#	define p_readdir_r(d,e,r) readdir_r(d,e,r)
Packit ae9e2a
#endif
Packit ae9e2a
Packit ae9e2a
#ifdef NO_ADDRINFO
Packit ae9e2a
#	include <netdb.h>
Packit ae9e2a
struct addrinfo {
Packit ae9e2a
	struct hostent *ai_hostent;
Packit ae9e2a
	struct servent *ai_servent;
Packit ae9e2a
	struct sockaddr_in ai_addr_in;
Packit ae9e2a
	struct sockaddr *ai_addr;
Packit ae9e2a
	size_t ai_addrlen;
Packit ae9e2a
	int ai_family;
Packit ae9e2a
	int ai_socktype;
Packit ae9e2a
	int ai_protocol;
Packit ae9e2a
	long ai_port;
Packit ae9e2a
	struct addrinfo *ai_next;
Packit ae9e2a
};
Packit ae9e2a
Packit ae9e2a
extern int p_getaddrinfo(const char *host, const char *port,
Packit ae9e2a
	struct addrinfo *hints, struct addrinfo **info);
Packit ae9e2a
extern void p_freeaddrinfo(struct addrinfo *info);
Packit ae9e2a
extern const char *p_gai_strerror(int ret);
Packit ae9e2a
#else
Packit ae9e2a
#	define p_getaddrinfo(a, b, c, d) getaddrinfo(a, b, c, d)
Packit ae9e2a
#	define p_freeaddrinfo(a) freeaddrinfo(a)
Packit ae9e2a
#	define p_gai_strerror(c) gai_strerror(c)
Packit ae9e2a
#endif /* NO_ADDRINFO */
Packit ae9e2a
Packit ae9e2a
#endif