SDL file times are 64-bit integers representing nanoseconds since the Unix epoch

This commit is contained in:
Sam Lantinga
2024-03-17 13:11:13 -07:00
parent 9153287fa0
commit 747300b356
8 changed files with 65 additions and 49 deletions

View File

@@ -244,16 +244,19 @@ typedef enum SDL_PathType
SDL_PATHTYPE_OTHER /**< something completely different like a device node (not a symlink, those are always followed) */
} SDL_PathType;
/* SDL file timestamps are 64-bit integers representing seconds since the Unix epoch (Jan 1, 1970) */
typedef Sint64 SDL_FileTimestamp;
/* SDL file times are 64-bit integers representing nanoseconds since the Unix epoch (Jan 1, 1970)
*
* They can be converted between to POSIX time_t values with SDL_NS_TO_SECONDS() and SDL_SECONDS_TO_NS(), and between Windows FILETIME values with SDL_FileTimeToWindows() and SDL_FileTimeFromWindows()
*/
typedef Sint64 SDL_FileTime;
typedef struct SDL_PathInfo
{
SDL_PathType type; /* the path type */
Uint64 size; /* the file size in bytes */
SDL_FileTimestamp create_time; /* the time when the path was created */
SDL_FileTimestamp modify_time; /* the last time the path was modified */
SDL_FileTimestamp access_time; /* the last time the path was read */
SDL_PathType type; /* the path type */
Uint64 size; /* the file size in bytes */
SDL_FileTime create_time; /* the time when the path was created */
SDL_FileTime modify_time; /* the last time the path was modified */
SDL_FileTime access_time; /* the last time the path was read */
} SDL_PathInfo;
/**
@@ -318,17 +321,29 @@ extern DECLSPEC int SDLCALL SDL_RenamePath(const char *oldpath, const char *newp
*/
extern DECLSPEC int SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo *info);
/* some helper functions ... */
/* Converts an SDL file timestamp into a Windows FILETIME (100-nanosecond intervals since January 1, 1601). Fills in the two 32-bit values of the FILETIME structure.
/* Converts an SDL file time into a Windows FILETIME (100-nanosecond intervals since January 1, 1601).
*
* This function fills in the two 32-bit values of the FILETIME structure.
*
* \param ftime the time to convert
* \param low a pointer filled in with the low portion of the Windows FILETIME value
* \param high a pointer filled in with the high portion of the Windows FILETIME value
* \param dwLowDateTime a pointer filled in with the low portion of the Windows FILETIME value
* \param dwHighDateTime a pointer filled in with the high portion of the Windows FILETIME value
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC void SDLCALL SDL_FileTimeToWindows(Sint64 ftime, Uint32 *low, Uint32 *high);
extern DECLSPEC void SDLCALL SDL_FileTimeToWindows(SDL_FileTime ftime, Uint32 *dwLowDateTime, Uint32 *dwHighDateTime);
/* Converts a Windows FILETIME (100-nanosecond intervals since January 1, 1601) to an SDL file time
*
* This function takes the two 32-bit values of the FILETIME structure as parameters.
*
* \param dwLowDateTime the low portion of the Windows FILETIME value
* \param dwHighDateTime the high portion of the Windows FILETIME value
* \returns the converted file time
*
* \since This function is available since SDL 3.0.0.
*/
extern DECLSPEC SDL_FileTime SDLCALL SDL_FileTimeFromWindows(Uint32 dwLowDateTime, Uint32 dwHighDateTime);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@@ -45,10 +45,12 @@ extern "C" {
#define SDL_NS_PER_SECOND 1000000000LL
#define SDL_NS_PER_MS 1000000
#define SDL_NS_PER_US 1000
#define SDL_MS_TO_NS(MS) (((Uint64)(MS)) * SDL_NS_PER_MS)
#define SDL_NS_TO_MS(NS) ((NS) / SDL_NS_PER_MS)
#define SDL_US_TO_NS(US) (((Uint64)(US)) * SDL_NS_PER_US)
#define SDL_NS_TO_US(NS) ((NS) / SDL_NS_PER_US)
#define SDL_SECONDS_TO_NS(S) (((Uint64)(S)) * SDL_NS_PER_SECOND)
#define SDL_NS_TO_SECONDS(NS) ((NS) / SDL_NS_PER_SECOND)
#define SDL_MS_TO_NS(MS) (((Uint64)(MS)) * SDL_NS_PER_MS)
#define SDL_NS_TO_MS(NS) ((NS) / SDL_NS_PER_MS)
#define SDL_US_TO_NS(US) (((Uint64)(US)) * SDL_NS_PER_US)
#define SDL_NS_TO_US(NS) ((NS) / SDL_NS_PER_US)
/**
* Get the number of milliseconds since SDL library initialization.