fix file position/size procs to use 64-bit APIs
svn: r7313
This commit is contained in:
parent
e4164955da
commit
35c63173d0
|
@ -110,6 +110,8 @@
|
||||||
# define USE_ON_EXIT_FOR_ATEXIT
|
# define USE_ON_EXIT_FOR_ATEXIT
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
#define USE_TRANSITIONAL_64_FILE_OPS
|
||||||
|
|
||||||
# ifndef i386
|
# ifndef i386
|
||||||
# define FLUSH_SPARC_REGISTER_WINDOWS
|
# define FLUSH_SPARC_REGISTER_WINDOWS
|
||||||
# endif
|
# endif
|
||||||
|
@ -203,6 +205,10 @@
|
||||||
|
|
||||||
# define MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT
|
# define MZ_TCP_LISTEN_IPV6_ONLY_SOCKOPT
|
||||||
|
|
||||||
|
#if !defined(__x86_64__)
|
||||||
|
# define USE_TRANSITIONAL_64_FILE_OPS
|
||||||
|
#endif
|
||||||
|
|
||||||
# define FLAGS_ALREADY_SET
|
# define FLAGS_ALREADY_SET
|
||||||
|
|
||||||
#if defined(i386)
|
#if defined(i386)
|
||||||
|
@ -1023,6 +1029,10 @@
|
||||||
/* NEED_RESET_STDOUT_BLOCKING enures that file descriptors 1 and 2
|
/* NEED_RESET_STDOUT_BLOCKING enures that file descriptors 1 and 2
|
||||||
are reset to blocking mode before exiting. */
|
are reset to blocking mode before exiting. */
|
||||||
|
|
||||||
|
/* USE_TRANSITIONAL_64_FILE_OPS uses fseeko64, lseek64, stat64,
|
||||||
|
etc. for file operations involving sizes (that can requires
|
||||||
|
64-bit arithmetic). Use this when off_t is only 32 bits wide. */
|
||||||
|
|
||||||
/* USE_ULIMIT uses ulimit instead of getdtablesize (Unix). */
|
/* USE_ULIMIT uses ulimit instead of getdtablesize (Unix). */
|
||||||
|
|
||||||
/* USE_DYNAMIC_FDSET_SIZE allocates fd_set records based on the
|
/* USE_DYNAMIC_FDSET_SIZE allocates fd_set records based on the
|
||||||
|
|
|
@ -5366,7 +5366,7 @@ static Scheme_Object *file_or_dir_permissions(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[])
|
||||||
{
|
{
|
||||||
char *filename;
|
char *filename;
|
||||||
unsigned long len = 0;
|
mzlonglong len = 0;
|
||||||
|
|
||||||
if (!SCHEME_PATH_STRINGP(argv[0]))
|
if (!SCHEME_PATH_STRINGP(argv[0]))
|
||||||
scheme_wrong_type("file-size", SCHEME_PATH_STRING_STR, 0, argc, argv);
|
scheme_wrong_type("file-size", SCHEME_PATH_STRING_STR, 0, argc, argv);
|
||||||
|
@ -5378,17 +5378,16 @@ static Scheme_Object *file_size(int argc, Scheme_Object *argv[])
|
||||||
|
|
||||||
#ifdef DOS_FILE_SYSTEM
|
#ifdef DOS_FILE_SYSTEM
|
||||||
{
|
{
|
||||||
mzlonglong filesize;
|
if (UNC_stat(filename, strlen(filename), NULL, NULL, NULL, &len)) {
|
||||||
if (UNC_stat(filename, strlen(filename), NULL, NULL, NULL, &filesize)) {
|
return scheme_make_integer_value_from_long_long(len);
|
||||||
return scheme_make_integer_value_from_long_long(filesize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
struct MSC_IZE(stat) buf;
|
struct MSC_IZE(BIG_OFF_T_IZE(stat)) buf;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!MSC_W_IZE(stat)(MSC_WIDE_PATH(filename), &buf))
|
if (!MSC_W_IZE(BIG_OFF_T_IZE(stat))(MSC_WIDE_PATH(filename), &buf))
|
||||||
break;
|
break;
|
||||||
else if (errno != EINTR)
|
else if (errno != EINTR)
|
||||||
goto failed;
|
goto failed;
|
||||||
|
@ -5400,7 +5399,7 @@ static Scheme_Object *file_size(int argc, Scheme_Object *argv[])
|
||||||
len = buf.st_size;
|
len = buf.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return scheme_make_integer_value_from_unsigned(len);
|
return scheme_make_integer_value_from_long_long(len);
|
||||||
|
|
||||||
failed:
|
failed:
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -87,7 +87,6 @@ extern int osk_not_console; /* set by cmd-line flag */
|
||||||
|
|
||||||
#define mzAssert(x) /* if (!(x)) abort() */
|
#define mzAssert(x) /* if (!(x)) abort() */
|
||||||
|
|
||||||
|
|
||||||
/******************** Generic FILEs ********************/
|
/******************** Generic FILEs ********************/
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -4128,26 +4127,25 @@ scheme_file_position(int argc, Scheme_Object *argv[])
|
||||||
scheme_make_provided_string(argv[0], 2, NULL),
|
scheme_make_provided_string(argv[0], 2, NULL),
|
||||||
scheme_make_provided_string(argv[1], 2, NULL));
|
scheme_make_provided_string(argv[1], 2, NULL));
|
||||||
|
|
||||||
if ((argc > 1) && SCHEME_BIGNUMP(argv[1]))
|
|
||||||
scheme_raise_exn(MZEXN_FAIL_CONTRACT,
|
|
||||||
"file-position: new position is too large: %s for port: %s",
|
|
||||||
scheme_make_provided_string(argv[1], 2, NULL),
|
|
||||||
scheme_make_provided_string(argv[0], 2, NULL));
|
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
long n;
|
mzlonglong nll;
|
||||||
int whence;
|
int whence;
|
||||||
|
|
||||||
if (SCHEME_INTP(argv[1])) {
|
if (SCHEME_EOFP(argv[1])) {
|
||||||
n = SCHEME_INT_VAL(argv[1]);
|
nll = 0;
|
||||||
|
whence = SEEK_END;
|
||||||
|
} else if (scheme_get_long_long_val(argv[1], &nll)) {
|
||||||
whence = SEEK_SET;
|
whence = SEEK_SET;
|
||||||
} else {
|
} else {
|
||||||
n = 0;
|
scheme_raise_exn(MZEXN_FAIL_CONTRACT,
|
||||||
whence = SEEK_END;
|
"file-position: new position is too large: %s for port: %s",
|
||||||
|
scheme_make_provided_string(argv[1], 2, NULL),
|
||||||
|
scheme_make_provided_string(argv[0], 2, NULL));
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f) {
|
if (f) {
|
||||||
if (fseek(f, n, whence)) {
|
if (BIG_OFF_T_IZE(fseeko)(f, nll, whence)) {
|
||||||
scheme_raise_exn(MZEXN_FAIL_FILESYSTEM,
|
scheme_raise_exn(MZEXN_FAIL_FILESYSTEM,
|
||||||
"file-position: position change failed on file (%e)",
|
"file-position: position change failed on file (%e)",
|
||||||
errno);
|
errno);
|
||||||
|
@ -4161,20 +4159,14 @@ scheme_file_position(int argc, Scheme_Object *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
# ifdef WINDOWS_FILE_HANDLES
|
# ifdef WINDOWS_FILE_HANDLES
|
||||||
lv = SetFilePointer((HANDLE)fd, n, NULL,
|
{
|
||||||
((whence == SEEK_SET) ? FILE_BEGIN : FILE_END));
|
|
||||||
# else
|
if (!SetFilePointerEx((HANDLE)fd, nll, NULL,
|
||||||
# ifdef MAC_FILE_HANDLES
|
((whence == SEEK_SET) ? FILE_BEGIN : FILE_END)))
|
||||||
{
|
lv = -1;
|
||||||
errno = SetFPos(fd, ((whence == SEEK_SET) ? fsFromStart : fsFromLEOF), n);
|
|
||||||
if (errno == noErr)
|
|
||||||
lv = 0;
|
|
||||||
else
|
|
||||||
lv = -1;
|
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
lv = lseek(fd, n, whence);
|
lv = BIG_OFF_T_IZE(lseek)(fd, nll, whence);
|
||||||
# endif
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
if (lv < 0) {
|
if (lv < 0) {
|
||||||
|
@ -4201,6 +4193,16 @@ scheme_file_position(int argc, Scheme_Object *argv[])
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
|
long n;
|
||||||
|
|
||||||
|
if (whence == SEEK_SET) {
|
||||||
|
if (!scheme_get_int_val(argv[1], &n)) {
|
||||||
|
scheme_raise_out_of_memory(NULL, NULL);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
n = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (whence == SEEK_END) {
|
if (whence == SEEK_END) {
|
||||||
if (wis)
|
if (wis)
|
||||||
n = is->u.hot;
|
n = is->u.hot;
|
||||||
|
@ -4251,64 +4253,59 @@ scheme_file_position(int argc, Scheme_Object *argv[])
|
||||||
|
|
||||||
return scheme_void;
|
return scheme_void;
|
||||||
} else {
|
} else {
|
||||||
long p;
|
mzlonglong pll;
|
||||||
if (f) {
|
if (f) {
|
||||||
p = ftell(f);
|
pll = BIG_OFF_T_IZE(ftello)(f);
|
||||||
#ifdef MZ_FDS
|
#ifdef MZ_FDS
|
||||||
} else if (had_fd) {
|
} else if (had_fd) {
|
||||||
# ifdef WINDOWS_FILE_HANDLES
|
# ifdef WINDOWS_FILE_HANDLES
|
||||||
p = SetFilePointer((HANDLE)fd, 0, NULL, FILE_CURRENT);
|
|
||||||
# else
|
|
||||||
# ifdef MAC_FILE_HANDLES
|
|
||||||
{
|
{
|
||||||
SInt32 pos;
|
LARGE_INTEGER li;
|
||||||
errno = GetFPos(fd, &pos);
|
if (!SetFilePointerEx((HANDLE)fd, 0, &li, FILE_CURRENT))
|
||||||
if (errno == noErr)
|
pll = -1;
|
||||||
p = pos;
|
else
|
||||||
else
|
pll = li;
|
||||||
p = -1;
|
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
p = lseek(fd, 0, 1);
|
pll = BIG_OFF_T_IZE(lseek)(fd, 0, 1);
|
||||||
# endif
|
|
||||||
# endif
|
# endif
|
||||||
if (p < 0) {
|
if (pll < 0) {
|
||||||
if (SCHEME_INPUT_PORTP(argv[0])) {
|
if (SCHEME_INPUT_PORTP(argv[0])) {
|
||||||
p = scheme_tell(argv[0]);
|
pll = scheme_tell(argv[0]);
|
||||||
} else {
|
} else {
|
||||||
p = scheme_output_tell(argv[0]);
|
pll = scheme_output_tell(argv[0]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (SCHEME_INPUT_PORTP(argv[0])) {
|
if (SCHEME_INPUT_PORTP(argv[0])) {
|
||||||
Scheme_Input_Port *ip;
|
Scheme_Input_Port *ip;
|
||||||
ip = scheme_input_port_record(argv[0]);
|
ip = scheme_input_port_record(argv[0]);
|
||||||
p -= ((Scheme_FD *)ip->port_data)->bufcount;
|
pll -= ((Scheme_FD *)ip->port_data)->bufcount;
|
||||||
} else {
|
} else {
|
||||||
Scheme_Output_Port *op;
|
Scheme_Output_Port *op;
|
||||||
op = scheme_output_port_record(argv[0]);
|
op = scheme_output_port_record(argv[0]);
|
||||||
p += ((Scheme_FD *)op->port_data)->bufcount;
|
pll += ((Scheme_FD *)op->port_data)->bufcount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (wis)
|
} else if (wis)
|
||||||
p = is->index;
|
pll = is->index;
|
||||||
else {
|
else {
|
||||||
/* u.pos > index implies we previously moved past the end with file-position */
|
/* u.pos > index implies we previously moved past the end with file-position */
|
||||||
if (is->u.pos > is->index)
|
if (is->u.pos > is->index)
|
||||||
p = is->u.pos;
|
pll = is->u.pos;
|
||||||
else
|
else
|
||||||
p = is->index;
|
pll = is->index;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Back up for un-gotten & peeked chars: */
|
/* Back up for un-gotten & peeked chars: */
|
||||||
if (SCHEME_INPUT_PORTP(argv[0])) {
|
if (SCHEME_INPUT_PORTP(argv[0])) {
|
||||||
Scheme_Input_Port *ip;
|
Scheme_Input_Port *ip;
|
||||||
ip = scheme_input_port_record(argv[0]);
|
ip = scheme_input_port_record(argv[0]);
|
||||||
p -= ip->ungotten_count;
|
pll -= ip->ungotten_count;
|
||||||
p -= pipe_char_count(ip->peeked_read);
|
pll -= pipe_char_count(ip->peeked_read);
|
||||||
}
|
}
|
||||||
|
|
||||||
return scheme_make_integer(p);
|
return scheme_make_integer_value_from_long_long(pll);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2565,6 +2565,12 @@ Scheme_Object *scheme_get_native_arity(Scheme_Object *closure);
|
||||||
/* filesystem utilities */
|
/* filesystem utilities */
|
||||||
/*========================================================================*/
|
/*========================================================================*/
|
||||||
|
|
||||||
|
#ifdef USE_TRANSITIONAL_64_FILE_OPS
|
||||||
|
# define BIG_OFF_T_IZE(n) n ## 64
|
||||||
|
#else
|
||||||
|
# define BIG_OFF_T_IZE(n) n
|
||||||
|
#endif
|
||||||
|
|
||||||
int scheme_is_relative_path(const char *s, long len, int kind);
|
int scheme_is_relative_path(const char *s, long len, int kind);
|
||||||
int scheme_is_complete_path(const char *s, long len, int kind);
|
int scheme_is_complete_path(const char *s, long len, int kind);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user