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