mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-21 10:17:20 +00:00
win32: define our own POSIX struct stat, and support USE_NSEC
This commit is contained in:
parent
c963fe1d3d
commit
360dd4dafd
@ -87,7 +87,7 @@ ENDIF()
|
|||||||
|
|
||||||
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
|
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim.tv_nsec sys/stat.h
|
||||||
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
|
HAVE_STRUCT_STAT_NSEC LANGUAGE C)
|
||||||
IF(HAVE_STRUCT_STAT_NSEC)
|
IF(HAVE_STRUCT_STAT_NSEC OR WIN32)
|
||||||
OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" OFF )
|
OPTION( USE_NSEC "Care about sub-second file mtimes and ctimes" OFF )
|
||||||
ENDIF()
|
ENDIF()
|
||||||
|
|
||||||
|
@ -41,6 +41,7 @@
|
|||||||
# include <ws2tcpip.h>
|
# include <ws2tcpip.h>
|
||||||
# include "win32/msvc-compat.h"
|
# include "win32/msvc-compat.h"
|
||||||
# include "win32/mingw-compat.h"
|
# include "win32/mingw-compat.h"
|
||||||
|
# include "win32/win32-compat.h"
|
||||||
# include "win32/error.h"
|
# include "win32/error.h"
|
||||||
# include "win32/version.h"
|
# include "win32/version.h"
|
||||||
# ifdef GIT_THREADS
|
# ifdef GIT_THREADS
|
||||||
|
@ -11,12 +11,6 @@
|
|||||||
|
|
||||||
#undef stat
|
#undef stat
|
||||||
|
|
||||||
#if _WIN32_WINNT >= 0x0601
|
|
||||||
#define stat __stat64
|
|
||||||
#else
|
|
||||||
#define stat _stati64
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if _WIN32_WINNT < 0x0600 && !defined(__MINGW64_VERSION_MAJOR)
|
#if _WIN32_WINNT < 0x0600 && !defined(__MINGW64_VERSION_MAJOR)
|
||||||
#undef MemoryBarrier
|
#undef MemoryBarrier
|
||||||
void __mingworg_MemoryBarrier(void);
|
void __mingworg_MemoryBarrier(void);
|
||||||
|
@ -9,9 +9,6 @@
|
|||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
|
|
||||||
/* 64-bit stat information, regardless of USE_32BIT_TIME_T define */
|
|
||||||
#define stat __stat64
|
|
||||||
|
|
||||||
typedef unsigned short mode_t;
|
typedef unsigned short mode_t;
|
||||||
typedef SSIZE_T ssize_t;
|
typedef SSIZE_T ssize_t;
|
||||||
|
|
||||||
|
@ -76,17 +76,23 @@ size_t git_win32__path_trim_end(wchar_t *str, size_t len);
|
|||||||
size_t git_win32__canonicalize_path(wchar_t *str, size_t len);
|
size_t git_win32__canonicalize_path(wchar_t *str, size_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a FILETIME structure to a time_t.
|
* Converts a FILETIME structure to a struct timespec.
|
||||||
*
|
*
|
||||||
* @param FILETIME A pointer to a FILETIME
|
* @param FILETIME A pointer to a FILETIME
|
||||||
* @return A time_t containing the same time
|
* @param ts A pointer to the timespec structure to fill in
|
||||||
*/
|
*/
|
||||||
GIT_INLINE(time_t) git_win32__filetime_to_time_t(const FILETIME *ft)
|
GIT_INLINE(void) git_win32__filetime_to_timespec(
|
||||||
|
const FILETIME *ft,
|
||||||
|
struct timespec *ts)
|
||||||
{
|
{
|
||||||
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
|
long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime;
|
||||||
winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */
|
winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */
|
||||||
winTime /= 10000000; /* Nano to seconds resolution */
|
ts->tv_sec = (time_t)(winTime / 10000000);
|
||||||
return (time_t)winTime;
|
#ifdef GIT_USE_NSEC
|
||||||
|
ts->tv_nsec = (winTime % 10000000) * 100;
|
||||||
|
#else
|
||||||
|
ts->tv_nsec = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GIT_INLINE(void) git_win32__timeval_to_filetime(
|
GIT_INLINE(void) git_win32__timeval_to_filetime(
|
||||||
@ -122,9 +128,9 @@ GIT_INLINE(int) git_win32__file_attribute_to_stat(
|
|||||||
st->st_size = ((git_off_t)attrdata->nFileSizeHigh << 32) + attrdata->nFileSizeLow;
|
st->st_size = ((git_off_t)attrdata->nFileSizeHigh << 32) + attrdata->nFileSizeLow;
|
||||||
st->st_dev = _getdrive() - 1;
|
st->st_dev = _getdrive() - 1;
|
||||||
st->st_rdev = st->st_dev;
|
st->st_rdev = st->st_dev;
|
||||||
st->st_atime = git_win32__filetime_to_time_t(&(attrdata->ftLastAccessTime));
|
git_win32__filetime_to_timespec(&(attrdata->ftLastAccessTime), &(st->st_atim));
|
||||||
st->st_mtime = git_win32__filetime_to_time_t(&(attrdata->ftLastWriteTime));
|
git_win32__filetime_to_timespec(&(attrdata->ftLastWriteTime), &(st->st_mtim));
|
||||||
st->st_ctime = git_win32__filetime_to_time_t(&(attrdata->ftCreationTime));
|
git_win32__filetime_to_timespec(&(attrdata->ftCreationTime), &(st->st_ctim));
|
||||||
|
|
||||||
if (attrdata->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && path) {
|
if (attrdata->dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT && path) {
|
||||||
git_win32_path target;
|
git_win32_path target;
|
||||||
|
42
src/win32/win32-compat.h
Normal file
42
src/win32/win32-compat.h
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) the libgit2 contributors. All rights reserved.
|
||||||
|
*
|
||||||
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
||||||
|
* a Linking Exception. For full terms see the included COPYING file.
|
||||||
|
*/
|
||||||
|
#ifndef INCLUDE_win32_compat__
|
||||||
|
#define INCLUDE_win32_compat__
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
struct p_timespec {
|
||||||
|
time_t tv_sec;
|
||||||
|
long tv_nsec;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define timespec p_timespec
|
||||||
|
|
||||||
|
struct p_stat {
|
||||||
|
_dev_t st_dev;
|
||||||
|
_ino_t st_ino;
|
||||||
|
mode_t st_mode;
|
||||||
|
short st_nlink;
|
||||||
|
short st_uid;
|
||||||
|
short st_gid;
|
||||||
|
_dev_t st_rdev;
|
||||||
|
uint64_t st_size;
|
||||||
|
struct timespec st_atim;
|
||||||
|
struct timespec st_mtim;
|
||||||
|
struct timespec st_ctim;
|
||||||
|
#define st_atime st_atim.tv_sec
|
||||||
|
#define st_mtime st_mtim.tv_sec
|
||||||
|
#define st_ctime st_ctim.tv_sec
|
||||||
|
};
|
||||||
|
|
||||||
|
#define stat p_stat
|
||||||
|
|
||||||
|
#endif /* INCLUDE_win32_compat__ */
|
Loading…
Reference in New Issue
Block a user