rktio: better file size and timestamp types
This commit is contained in:
parent
d9d8c7758d
commit
49e30ea6fb
|
@ -4942,9 +4942,8 @@ static Scheme_Object *file_identity(int argc, Scheme_Object *argv[])
|
||||||
|
|
||||||
static Scheme_Object *file_size(int argc, Scheme_Object *argv[])
|
static Scheme_Object *file_size(int argc, Scheme_Object *argv[])
|
||||||
{
|
{
|
||||||
rktio_size_t *sz;
|
rktio_filesize_t *sz;
|
||||||
char *filename;
|
char *filename;
|
||||||
mzlonglong len = 0;
|
|
||||||
|
|
||||||
if (!SCHEME_PATH_STRINGP(argv[0]))
|
if (!SCHEME_PATH_STRINGP(argv[0]))
|
||||||
scheme_wrong_contract("file-size", "path-string?", 0, argc, argv);
|
scheme_wrong_contract("file-size", "path-string?", 0, argc, argv);
|
||||||
|
@ -4956,9 +4955,9 @@ static Scheme_Object *file_size(int argc, Scheme_Object *argv[])
|
||||||
|
|
||||||
sz = rktio_file_size(scheme_rktio, filename);
|
sz = rktio_file_size(scheme_rktio, filename);
|
||||||
if (sz) {
|
if (sz) {
|
||||||
len = ((mzlonglong)sz->hi << 32) + (mzlonglong)sz->lo;
|
mzlonglong szv = *sz;
|
||||||
free(sz);
|
free(sz);
|
||||||
return scheme_make_integer_value_from_long_long(len);
|
return scheme_make_integer_value_from_long_long(szv);
|
||||||
}
|
}
|
||||||
|
|
||||||
scheme_raise_exn(MZEXN_FAIL_FILESYSTEM,
|
scheme_raise_exn(MZEXN_FAIL_FILESYSTEM,
|
||||||
|
|
|
@ -341,13 +341,10 @@ RKTIO_EXTERN rktio_ok_t rktio_make_link(rktio_t *rktio, char *src, char *dest,
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
/* File attributes */
|
/* File attributes */
|
||||||
|
|
||||||
typedef struct {
|
typedef rktio_int64_t rktio_filesize_t;
|
||||||
unsigned lo, hi;
|
|
||||||
} rktio_size_t;
|
|
||||||
|
|
||||||
typedef intptr_t rktio_timestamp_t;
|
typedef intptr_t rktio_timestamp_t;
|
||||||
|
|
||||||
RKTIO_EXTERN rktio_size_t *rktio_file_size(rktio_t *rktio, char *filename);
|
RKTIO_EXTERN rktio_filesize_t *rktio_file_size(rktio_t *rktio, char *filename);
|
||||||
|
|
||||||
RKTIO_EXTERN rktio_timestamp_t *rktio_get_file_modify_seconds(rktio_t *rktio, char *file);
|
RKTIO_EXTERN rktio_timestamp_t *rktio_get_file_modify_seconds(rktio_t *rktio, char *file);
|
||||||
RKTIO_EXTERN rktio_ok_t rktio_set_file_modify_seconds(rktio_t *rktio, char *file, rktio_timestamp_t secs);
|
RKTIO_EXTERN rktio_ok_t rktio_set_file_modify_seconds(rktio_t *rktio, char *file, rktio_timestamp_t secs);
|
||||||
|
@ -463,8 +460,8 @@ RKTIO_EXTERN double rktio_get_inexact_milliseconds(void);
|
||||||
RKTIO_EXTERN intptr_t rktio_get_process_milliseconds(rktio_t *rktio);
|
RKTIO_EXTERN intptr_t rktio_get_process_milliseconds(rktio_t *rktio);
|
||||||
RKTIO_EXTERN intptr_t rktio_get_process_children_milliseconds(rktio_t *rktio);
|
RKTIO_EXTERN intptr_t rktio_get_process_children_milliseconds(rktio_t *rktio);
|
||||||
|
|
||||||
RKTIO_EXTERN intptr_t rktio_get_seconds(rktio_t *rktio);
|
RKTIO_EXTERN rktio_timestamp_t rktio_get_seconds(rktio_t *rktio);
|
||||||
RKTIO_EXTERN rktio_date_t *rktio_seconds_to_date(rktio_t *rktio, intptr_t seconds, intptr_t nanoseconds, int get_gmt);
|
RKTIO_EXTERN rktio_date_t *rktio_seconds_to_date(rktio_t *rktio, rktio_timestamp_t seconds, int nanoseconds, int get_gmt);
|
||||||
|
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
/* Errors */
|
/* Errors */
|
||||||
|
|
|
@ -21,6 +21,19 @@ typedef long intptr_t;
|
||||||
typedef unsigned long uintptr_t;
|
typedef unsigned long uintptr_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef RKTIO_SYSTEM_WINDOWS
|
||||||
|
# ifdef _MSC_VER
|
||||||
|
typedef _int64 rktio_int64_t;
|
||||||
|
typedef unsigned _int64 rktio_uint64_t;
|
||||||
|
# else
|
||||||
|
typedef __int64 rktio_int64_t;
|
||||||
|
typedef unsigned __int64 rktio_uint64_t;
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
typedef long long rktio_int64_t;
|
||||||
|
typedef unsigned long long rktio_uint64_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Whether pthread is available */
|
/* Whether pthread is available */
|
||||||
#undef RKTIO_USE_PTHREADS
|
#undef RKTIO_USE_PTHREADS
|
||||||
|
|
||||||
|
|
|
@ -337,7 +337,7 @@ static char *UNC_readlink(rktio_t *rktio, const char *fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int UNC_stat(rktio_t *rktio, const char *dirname, int *flags, int *isdir, int *islink,
|
static int UNC_stat(rktio_t *rktio, const char *dirname, int *flags, int *isdir, int *islink,
|
||||||
rktio_timestamp_t **date, rktio_size_t *filesize,
|
rktio_timestamp_t **date, rktio_filesize_t *filesize,
|
||||||
const char **resolved_path, int set_flags)
|
const char **resolved_path, int set_flags)
|
||||||
/* dirname must be absolute */
|
/* dirname must be absolute */
|
||||||
{
|
{
|
||||||
|
@ -495,8 +495,7 @@ static int UNC_stat(rktio_t *rktio, const char *dirname, int *flags, int *isdir,
|
||||||
*isdir = (GET_FF_ATTRIBS(fad) & FF_A_DIR);
|
*isdir = (GET_FF_ATTRIBS(fad) & FF_A_DIR);
|
||||||
}
|
}
|
||||||
if (filesize) {
|
if (filesize) {
|
||||||
filesize->lo = fad.nFileSizeLow;
|
*filesize = ((rktio_filesize_t)fad.nFileSizeHigh << 32) + fad.nFileSizeLow;
|
||||||
filesize->hi = fad.nFileSizeHigh;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(copy);
|
free(copy);
|
||||||
|
@ -1275,9 +1274,9 @@ int rktio_set_file_or_directory_permissions(rktio_t *rktio, char *filename, int
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
|
|
||||||
rktio_size_t *rktio_file_size(rktio_t *rktio, char *filename)
|
rktio_filesize_t *rktio_file_size(rktio_t *rktio, char *filename)
|
||||||
{
|
{
|
||||||
rktio_size_t *sz = NULL;
|
rktio_filesize_t *sz = NULL;
|
||||||
#ifdef RKTIO_SYSTEM_WINDOWS
|
#ifdef RKTIO_SYSTEM_WINDOWS
|
||||||
{
|
{
|
||||||
rktio_size_t sz_v;
|
rktio_size_t sz_v;
|
||||||
|
@ -1306,12 +1305,8 @@ rktio_size_t *rktio_file_size(rktio_t *rktio, char *filename)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
sz = malloc(sizeof(rktio_size_t));
|
sz = malloc(sizeof(rktio_filesize_t));
|
||||||
sz->lo = ((unsigned)buf.st_size & 0xFFFFFFFF);
|
*sz = buf.st_size;
|
||||||
if (sizeof(buf.st_size) > 4)
|
|
||||||
sz->hi = (buf.st_size >> 32);
|
|
||||||
else
|
|
||||||
sz->hi = 0;
|
|
||||||
|
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,16 +289,3 @@ void rktio_init_wide(rktio_t *rktio);
|
||||||
#ifdef RKTIO_USE_FCNTL_AND_FORK_FOR_FILE_LOCKS
|
#ifdef RKTIO_USE_FCNTL_AND_FORK_FOR_FILE_LOCKS
|
||||||
void rktio_release_lockf(rktio_t *rktio, int fd);
|
void rktio_release_lockf(rktio_t *rktio, int fd);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef RKTIO_SYSTEM_WINDOWS
|
|
||||||
# ifdef _MSC_VER
|
|
||||||
typedef _int64 rktio_int64_t;
|
|
||||||
typedef unsigned _int64 rktio_uint64_t;
|
|
||||||
# else
|
|
||||||
typedef __int64 rktio_int64_t;
|
|
||||||
typedef unsigned __int64 rktio_uint64_t;
|
|
||||||
# endif
|
|
||||||
#else
|
|
||||||
typedef long long rktio_int64_t;
|
|
||||||
typedef unsigned long long rktio_uint64_t;
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -175,7 +175,7 @@ intptr_t rktio_get_process_children_milliseconds(rktio_t *rktio)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
intptr_t rktio_get_seconds(rktio_t *rktio)
|
rktio_timestamp_t rktio_get_seconds(rktio_t *rktio)
|
||||||
{
|
{
|
||||||
#ifdef RKTIO_SYSTEM_WINDOWS
|
#ifdef RKTIO_SYSTEM_WINDOWS
|
||||||
return (intptr_t)(get_hectonanoseconds_as_longlong() / (rktio_int64_t)10000000);
|
return (intptr_t)(get_hectonanoseconds_as_longlong() / (rktio_int64_t)10000000);
|
||||||
|
@ -314,9 +314,8 @@ static int VALID_TIME_RANGE(intptr_t lnow)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
rktio_date_t *rktio_seconds_to_date(rktio_t *rktio, intptr_t seconds, intptr_t nanoseconds, int get_gmt)
|
rktio_date_t *rktio_seconds_to_date(rktio_t *rktio, rktio_timestamp_t seconds, int nanoseconds, int get_gmt)
|
||||||
{
|
{
|
||||||
intptr_t lnow;
|
|
||||||
int hour, min, sec, month, day, wday, yday, dst;
|
int hour, min, sec, month, day, wday, yday, dst;
|
||||||
intptr_t year;
|
intptr_t year;
|
||||||
long tzoffset;
|
long tzoffset;
|
||||||
|
@ -331,17 +330,15 @@ rktio_date_t *rktio_seconds_to_date(rktio_t *rktio, intptr_t seconds, intptr_t n
|
||||||
char *tzn;
|
char *tzn;
|
||||||
rktio_date_t *result;
|
rktio_date_t *result;
|
||||||
|
|
||||||
lnow = seconds;
|
if ((((intptr_t)(now = (CHECK_TIME_T)seconds)) == seconds)
|
||||||
|
&& VALID_TIME_RANGE(seconds)) {
|
||||||
if ((((intptr_t)(now = (CHECK_TIME_T)lnow)) == lnow)
|
|
||||||
&& VALID_TIME_RANGE(lnow)) {
|
|
||||||
int success;
|
int success;
|
||||||
|
|
||||||
#ifdef RKTIO_SYSTEM_WINDOWS
|
#ifdef RKTIO_SYSTEM_WINDOWS
|
||||||
{
|
{
|
||||||
rktio_uint64_t tmpC;
|
rktio_uint64_t tmpC;
|
||||||
tmpC = ((rktio_uint64_t)lnow * 10000000);
|
tmpC = ((rktio_uint64_t)seconds * 10000000);
|
||||||
if ((rktio_int64_t)tmpC / 10000000 != lnow) {
|
if ((rktio_int64_t)tmpC / 10000000 != seconds) {
|
||||||
/* overflow */
|
/* overflow */
|
||||||
success = 0;
|
success = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user