diff options
Diffstat (limited to 'compat')
-rw-r--r-- | compat/apple-common-crypto.h | 4 | ||||
-rw-r--r-- | compat/bswap.h | 4 | ||||
-rw-r--r-- | compat/mingw.c | 15 | ||||
-rw-r--r-- | compat/mingw.h | 17 | ||||
-rw-r--r-- | compat/poll/poll.c | 16 | ||||
-rw-r--r-- | compat/regex/regcomp.c | 6 | ||||
-rw-r--r-- | compat/sha1-chunked.c | 19 | ||||
-rw-r--r-- | compat/sha1-chunked.h | 2 | ||||
-rw-r--r-- | compat/stat.c | 48 |
9 files changed, 123 insertions, 8 deletions
diff --git a/compat/apple-common-crypto.h b/compat/apple-common-crypto.h index c8b9b0e1a6..d3fb264181 100644 --- a/compat/apple-common-crypto.h +++ b/compat/apple-common-crypto.h @@ -16,6 +16,10 @@ #undef TYPE_BOOL #endif +#ifndef SHA1_MAX_BLOCK_SIZE +#error Using Apple Common Crypto library requires setting SHA1_MAX_BLOCK_SIZE +#endif + #ifdef APPLE_LION_OR_NEWER #define git_CC_error_check(pattern, err) \ do { \ diff --git a/compat/bswap.h b/compat/bswap.h index f6fd9a6a6c..7fed637ed0 100644 --- a/compat/bswap.h +++ b/compat/bswap.h @@ -122,6 +122,10 @@ static inline uint64_t git_bswap64(uint64_t x) # define GIT_BYTE_ORDER GIT_BIG_ENDIAN # elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) # define GIT_BYTE_ORDER GIT_LITTLE_ENDIAN +# elif defined(__THW_BIG_ENDIAN__) && !defined(__THW_LITTLE_ENDIAN__) +# define GIT_BYTE_ORDER GIT_BIG_ENDIAN +# elif defined(__THW_LITTLE_ENDIAN__) && !defined(__THW_BIG_ENDIAN__) +# define GIT_BYTE_ORDER GIT_LITTLE_ENDIAN # else # error "Cannot determine endianness" # endif diff --git a/compat/mingw.c b/compat/mingw.c index c5c37e53ce..f74da235f5 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -312,7 +312,7 @@ int mingw_open (const char *filename, int oflags, ...) return -1; fd = _wopen(wfilename, oflags, mode); - if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) { + if (fd < 0 && (oflags & O_ACCMODE) != O_RDONLY && errno == EACCES) { DWORD attrs = GetFileAttributesW(wfilename); if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY)) errno = EISDIR; @@ -681,7 +681,7 @@ int pipe(int filedes[2]) return -1; } filedes[1] = _open_osfhandle((int)h[1], O_NOINHERIT); - if (filedes[0] < 0) { + if (filedes[1] < 0) { close(filedes[0]); CloseHandle(h[1]); return -1; @@ -2128,3 +2128,14 @@ void mingw_startup() /* initialize Unicode console */ winansi_init(); } + +int uname(struct utsname *buf) +{ + DWORD v = GetVersion(); + memset(buf, 0, sizeof(*buf)); + strcpy(buf->sysname, "Windows"); + sprintf(buf->release, "%u.%u", v & 0xff, (v >> 8) & 0xff); + /* assuming NT variants only.. */ + sprintf(buf->version, "%u", (v >> 16) & 0x7fff); + return 0; +} diff --git a/compat/mingw.h b/compat/mingw.h index 5e499cfb71..738865c6c0 100644 --- a/compat/mingw.h +++ b/compat/mingw.h @@ -76,6 +76,14 @@ struct itimerval { }; #define ITIMER_REAL 0 +struct utsname { + char sysname[16]; + char nodename[1]; + char release[16]; + char version[16]; + char machine[1]; +}; + /* * sanitize preprocessor namespace polluted by Windows headers defining * macros which collide with git local versions @@ -98,8 +106,6 @@ static inline unsigned int alarm(unsigned int seconds) { return 0; } static inline int fsync(int fd) { return _commit(fd); } -static inline pid_t getppid(void) -{ return 1; } static inline void sync(void) {} static inline uid_t getuid(void) @@ -121,6 +127,12 @@ static inline int sigaddset(sigset_t *set, int signum) #define SIG_UNBLOCK 0 static inline int sigprocmask(int how, const sigset_t *set, sigset_t *oldset) { return 0; } +static inline pid_t getppid(void) +{ return 1; } +static inline pid_t getpgid(pid_t pid) +{ return pid == 0 ? getpid() : pid; } +static inline pid_t tcgetpgrp(int fd) +{ return getpid(); } /* * simple adaptors @@ -171,6 +183,7 @@ struct passwd *getpwuid(uid_t uid); int setitimer(int type, struct itimerval *in, struct itimerval *out); int sigaction(int sig, struct sigaction *in, struct sigaction *out); int link(const char *oldpath, const char *newpath); +int uname(struct utsname *buf); /* * replacements of existing functions diff --git a/compat/poll/poll.c b/compat/poll/poll.c index a9b41d89f4..db4e03ed79 100644 --- a/compat/poll/poll.c +++ b/compat/poll/poll.c @@ -446,7 +446,7 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout) static HANDLE hEvent; WSANETWORKEVENTS ev; HANDLE h, handle_array[FD_SETSIZE + 2]; - DWORD ret, wait_timeout, nhandles; + DWORD ret, wait_timeout, nhandles, start = 0, elapsed, orig_timeout = 0; fd_set rfds, wfds, xfds; BOOL poll_again; MSG msg; @@ -459,6 +459,12 @@ poll (struct pollfd *pfd, nfds_t nfd, int timeout) return -1; } + if (timeout != INFTIM) + { + orig_timeout = timeout; + start = GetTickCount(); + } + if (!hEvent) hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); @@ -603,7 +609,13 @@ restart: rc++; } - if (!rc && timeout == INFTIM) + if (!rc && orig_timeout && timeout != INFTIM) + { + elapsed = GetTickCount() - start; + timeout = elapsed >= orig_timeout ? 0 : orig_timeout - elapsed; + } + + if (!rc && timeout) { SleepEx (1, TRUE); goto restart; diff --git a/compat/regex/regcomp.c b/compat/regex/regcomp.c index 06f3088708..fba5986399 100644 --- a/compat/regex/regcomp.c +++ b/compat/regex/regcomp.c @@ -18,6 +18,8 @@ Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include <stdint.h> + static reg_errcode_t re_compile_internal (regex_t *preg, const char * pattern, size_t length, reg_syntax_t syntax); static void re_compile_fastmap_iter (regex_t *bufp, @@ -2577,7 +2579,7 @@ parse_dup_op (bin_tree_t *elem, re_string_t *regexp, re_dfa_t *dfa, old_tree = NULL; if (elem->token.type == SUBEXP) - postorder (elem, mark_opt_subexp, (void *) (long) elem->token.opr.idx); + postorder (elem, mark_opt_subexp, (void *) (intptr_t) elem->token.opr.idx); tree = create_tree (dfa, elem, NULL, (end == -1 ? OP_DUP_ASTERISK : OP_ALT)); if (BE (tree == NULL, 0)) @@ -3806,7 +3808,7 @@ create_token_tree (re_dfa_t *dfa, bin_tree_t *left, bin_tree_t *right, static reg_errcode_t mark_opt_subexp (void *extra, bin_tree_t *node) { - int idx = (int) (long) extra; + int idx = (int) (intptr_t) extra; if (node->token.type == SUBEXP && node->token.opr.idx == idx) node->token.opt_subexp = 1; diff --git a/compat/sha1-chunked.c b/compat/sha1-chunked.c new file mode 100644 index 0000000000..6adfcfd540 --- /dev/null +++ b/compat/sha1-chunked.c @@ -0,0 +1,19 @@ +#include "cache.h" + +int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len) +{ + size_t nr; + size_t total = 0; + const char *cdata = (const char*)data; + + while (len) { + nr = len; + if (nr > SHA1_MAX_BLOCK_SIZE) + nr = SHA1_MAX_BLOCK_SIZE; + platform_SHA1_Update(c, cdata, nr); + total += nr; + cdata += nr; + len -= nr; + } + return total; +} diff --git a/compat/sha1-chunked.h b/compat/sha1-chunked.h new file mode 100644 index 0000000000..7b2df28eec --- /dev/null +++ b/compat/sha1-chunked.h @@ -0,0 +1,2 @@ + +int git_SHA1_Update_Chunked(platform_SHA_CTX *c, const void *data, size_t len); diff --git a/compat/stat.c b/compat/stat.c new file mode 100644 index 0000000000..a2d3931cb7 --- /dev/null +++ b/compat/stat.c @@ -0,0 +1,48 @@ +#define _POSIX_C_SOURCE 200112L +#include <sys/stat.h> /* *stat, S_IS* */ +#include <sys/types.h> /* mode_t */ + +static inline mode_t mode_native_to_git(mode_t native_mode) +{ + mode_t perm_bits = native_mode & 07777; + if (S_ISREG(native_mode)) + return 0100000 | perm_bits; + if (S_ISDIR(native_mode)) + return 0040000 | perm_bits; + if (S_ISLNK(native_mode)) + return 0120000 | perm_bits; + if (S_ISBLK(native_mode)) + return 0060000 | perm_bits; + if (S_ISCHR(native_mode)) + return 0020000 | perm_bits; + if (S_ISFIFO(native_mode)) + return 0010000 | perm_bits; + if (S_ISSOCK(native_mode)) + return 0140000 | perm_bits; + /* Non-standard type bits were given. */ + return perm_bits; +} + +int git_stat(const char *path, struct stat *buf) +{ + int rc = stat(path, buf); + if (rc == 0) + buf->st_mode = mode_native_to_git(buf->st_mode); + return rc; +} + +int git_fstat(int fd, struct stat *buf) +{ + int rc = fstat(fd, buf); + if (rc == 0) + buf->st_mode = mode_native_to_git(buf->st_mode); + return rc; +} + +int git_lstat(const char *path, struct stat *buf) +{ + int rc = lstat(path, buf); + if (rc == 0) + buf->st_mode = mode_native_to_git(buf->st_mode); + return rc; +} |