1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[Bug #5317] Use rb_off_t instead of off_t

Get rid of the conflict with system-provided small `off_t`.
This commit is contained in:
Nobuyoshi Nakada 2022-09-05 20:23:27 +09:00
parent 55fef084da
commit e2ccb316b4
Notes: git 2022-09-08 23:01:30 +09:00
10 changed files with 117 additions and 122 deletions

8
file.c
View file

@ -2517,7 +2517,7 @@ rb_file_birthtime(VALUE obj)
* *
*/ */
off_t rb_off_t
rb_file_size(VALUE file) rb_file_size(VALUE file)
{ {
if (RB_TYPE_P(file, T_FILE)) { if (RB_TYPE_P(file, T_FILE)) {
@ -5089,7 +5089,7 @@ rb_file_s_join(VALUE klass, VALUE args)
#if defined(HAVE_TRUNCATE) #if defined(HAVE_TRUNCATE)
struct truncate_arg { struct truncate_arg {
const char *path; const char *path;
off_t pos; rb_off_t pos;
}; };
static void * static void *
@ -5138,7 +5138,7 @@ rb_file_s_truncate(VALUE klass, VALUE path, VALUE len)
#if defined(HAVE_FTRUNCATE) #if defined(HAVE_FTRUNCATE)
struct ftruncate_arg { struct ftruncate_arg {
int fd; int fd;
off_t pos; rb_off_t pos;
}; };
static VALUE static VALUE
@ -6093,7 +6093,7 @@ rb_stat_z(VALUE obj)
static VALUE static VALUE
rb_stat_s(VALUE obj) rb_stat_s(VALUE obj)
{ {
off_t size = get_stat(obj)->st_size; rb_off_t size = get_stat(obj)->st_size;
if (size == 0) return Qnil; if (size == 0) return Qnil;
return OFFT2NUM(size); return OFFT2NUM(size);

View file

@ -276,7 +276,7 @@ VALUE rb_fiber_scheduler_io_write(VALUE scheduler, VALUE io, VALUE buffer, size_
* @retval RUBY_Qundef `scheduler` doesn't have `#io_read`. * @retval RUBY_Qundef `scheduler` doesn't have `#io_read`.
* @return otherwise What `scheduler.io_read` returns. * @return otherwise What `scheduler.io_read` returns.
*/ */
VALUE rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, VALUE buffer, size_t length, off_t offset); VALUE rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, VALUE buffer, size_t length, rb_off_t offset);
/** /**
* Nonblocking write to the passed IO at the specified offset. * Nonblocking write to the passed IO at the specified offset.
@ -289,7 +289,7 @@ VALUE rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, VALUE buffer, size_
* @retval RUBY_Qundef `scheduler` doesn't have `#io_write`. * @retval RUBY_Qundef `scheduler` doesn't have `#io_write`.
* @return otherwise What `scheduler.io_write` returns. * @return otherwise What `scheduler.io_write` returns.
*/ */
VALUE rb_fiber_scheduler_io_pwrite(VALUE scheduler, VALUE io, VALUE buffer, size_t length, off_t offset); VALUE rb_fiber_scheduler_io_pwrite(VALUE scheduler, VALUE io, VALUE buffer, size_t length, rb_off_t offset);
/** /**
* Nonblocking read from the passed IO using a native buffer. * Nonblocking read from the passed IO using a native buffer.

View file

@ -206,7 +206,7 @@ int rb_is_absolute_path(const char *path);
* unpredictable. POSIX's `<sys/stat.h>` states that "the use of * unpredictable. POSIX's `<sys/stat.h>` states that "the use of
* this field is unspecified" then. * this field is unspecified" then.
*/ */
off_t rb_file_size(VALUE file); rb_off_t rb_file_size(VALUE file);
RBIMPL_SYMBOL_EXPORT_END() RBIMPL_SYMBOL_EXPORT_END()

View file

@ -65,7 +65,7 @@ enum rb_io_buffer_endian {
}; };
VALUE rb_io_buffer_new(void *base, size_t size, enum rb_io_buffer_flags flags); VALUE rb_io_buffer_new(void *base, size_t size, enum rb_io_buffer_flags flags);
VALUE rb_io_buffer_map(VALUE io, size_t size, off_t offset, enum rb_io_buffer_flags flags); VALUE rb_io_buffer_map(VALUE io, size_t size, rb_off_t offset, enum rb_io_buffer_flags flags);
VALUE rb_io_buffer_lock(VALUE self); VALUE rb_io_buffer_lock(VALUE self);
VALUE rb_io_buffer_unlock(VALUE self); VALUE rb_io_buffer_unlock(VALUE self);
@ -82,9 +82,9 @@ void rb_io_buffer_clear(VALUE self, uint8_t value, size_t offset, size_t length)
// The length is the minimum required length. // The length is the minimum required length.
VALUE rb_io_buffer_read(VALUE self, VALUE io, size_t length); VALUE rb_io_buffer_read(VALUE self, VALUE io, size_t length);
VALUE rb_io_buffer_pread(VALUE self, VALUE io, size_t length, off_t offset); VALUE rb_io_buffer_pread(VALUE self, VALUE io, size_t length, rb_off_t offset);
VALUE rb_io_buffer_write(VALUE self, VALUE io, size_t length); VALUE rb_io_buffer_write(VALUE self, VALUE io, size_t length);
VALUE rb_io_buffer_pwrite(VALUE self, VALUE io, size_t length, off_t offset); VALUE rb_io_buffer_pwrite(VALUE self, VALUE io, size_t length, rb_off_t offset);
RBIMPL_SYMBOL_EXPORT_END() RBIMPL_SYMBOL_EXPORT_END()

View file

@ -195,7 +195,6 @@ struct stati128 {
long st_ctimensec; long st_ctimensec;
}; };
#define off_t __int64
#define stat stati128 #define stat stati128
#undef SIZEOF_STRUCT_STAT_ST_INO #undef SIZEOF_STRUCT_STAT_ST_INO
#define SIZEOF_STRUCT_STAT_ST_INO sizeof(unsigned __int64) #define SIZEOF_STRUCT_STAT_ST_INO sizeof(unsigned __int64)
@ -401,9 +400,9 @@ scalb(double a, long b)
#define SUFFIX #define SUFFIX
extern int rb_w32_ftruncate(int fd, off_t length); extern int rb_w32_ftruncate(int fd, rb_off_t length);
extern int rb_w32_truncate(const char *path, off_t length); extern int rb_w32_truncate(const char *path, rb_off_t length);
extern int rb_w32_utruncate(const char *path, off_t length); extern int rb_w32_utruncate(const char *path, rb_off_t length);
#undef HAVE_FTRUNCATE #undef HAVE_FTRUNCATE
#define HAVE_FTRUNCATE 1 #define HAVE_FTRUNCATE 1
@ -722,7 +721,7 @@ int rb_w32_fclose(FILE*);
int rb_w32_pipe(int[2]); int rb_w32_pipe(int[2]);
ssize_t rb_w32_read(int, void *, size_t); ssize_t rb_w32_read(int, void *, size_t);
ssize_t rb_w32_write(int, const void *, size_t); ssize_t rb_w32_write(int, const void *, size_t);
off_t rb_w32_lseek(int, off_t, int); rb_off_t rb_w32_lseek(int, rb_off_t, int);
int rb_w32_uutime(const char *, const struct utimbuf *); int rb_w32_uutime(const char *, const struct utimbuf *);
int rb_w32_uutimes(const char *, const struct timeval *); int rb_w32_uutimes(const char *, const struct timeval *);
int rb_w32_uutimensat(int /* must be AT_FDCWD */, const char *, const struct timespec *, int /* must be 0 */); int rb_w32_uutimensat(int /* must be AT_FDCWD */, const char *, const struct timespec *, int /* must be 0 */);
@ -815,7 +814,7 @@ double rb_w32_pow(double x, double y);
#define MAP_ANON 0x1000 #define MAP_ANON 0x1000
#define MAP_ANONYMOUS MAP_ANON #define MAP_ANONYMOUS MAP_ANON
extern void *rb_w32_mmap(void *, size_t, int, int, int, off_t); extern void *rb_w32_mmap(void *, size_t, int, int, int, rb_off_t);
extern int rb_w32_munmap(void *, size_t); extern int rb_w32_munmap(void *, size_t);
extern int rb_w32_mprotect(void *, size_t, int); extern int rb_w32_mprotect(void *, size_t, int);

156
io.c
View file

@ -75,10 +75,6 @@
#include <sys/fcntl.h> #include <sys/fcntl.h>
#endif #endif
#if !HAVE_OFF_T && !defined(off_t)
# define off_t long
#endif
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
# include <sys/time.h> # include <sys/time.h>
#endif #endif
@ -149,10 +145,6 @@
#define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR) #define O_ACCMODE (O_RDONLY | O_WRONLY | O_RDWR)
#endif #endif
#if SIZEOF_OFF_T > SIZEOF_LONG && !defined(HAVE_LONG_LONG)
# error off_t is bigger than long, but you have no long long...
#endif
#ifndef PIPE_BUF #ifndef PIPE_BUF
# ifdef _POSIX_PIPE_BUF # ifdef _POSIX_PIPE_BUF
# define PIPE_BUF _POSIX_PIPE_BUF # define PIPE_BUF _POSIX_PIPE_BUF
@ -620,7 +612,7 @@ raise_on_write(rb_io_t *fptr, int e, VALUE errinfo)
static void static void
io_unread(rb_io_t *fptr) io_unread(rb_io_t *fptr)
{ {
off_t r, pos; rb_off_t r, pos;
ssize_t read_size; ssize_t read_size;
long i; long i;
long newlines = 0; long newlines = 0;
@ -859,7 +851,7 @@ rb_io_s_try_convert(VALUE dummy, VALUE io)
static void static void
io_unread(rb_io_t *fptr) io_unread(rb_io_t *fptr)
{ {
off_t r; rb_off_t r;
rb_io_check_closed(fptr); rb_io_check_closed(fptr);
if (fptr->rbuf.len == 0 || fptr->mode & FMODE_DUPLEX) if (fptr->rbuf.len == 0 || fptr->mode & FMODE_DUPLEX)
return; return;
@ -2224,7 +2216,7 @@ static VALUE
rb_io_tell(VALUE io) rb_io_tell(VALUE io)
{ {
rb_io_t *fptr; rb_io_t *fptr;
off_t pos; rb_off_t pos;
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
pos = io_tell(fptr); pos = io_tell(fptr);
@ -2237,7 +2229,7 @@ static VALUE
rb_io_seek(VALUE io, VALUE offset, int whence) rb_io_seek(VALUE io, VALUE offset, int whence)
{ {
rb_io_t *fptr; rb_io_t *fptr;
off_t pos; rb_off_t pos;
pos = NUM2OFFT(offset); pos = NUM2OFFT(offset);
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
@ -2348,7 +2340,7 @@ static VALUE
rb_io_set_pos(VALUE io, VALUE offset) rb_io_set_pos(VALUE io, VALUE offset)
{ {
rb_io_t *fptr; rb_io_t *fptr;
off_t pos; rb_off_t pos;
pos = NUM2OFFT(offset); pos = NUM2OFFT(offset);
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
@ -2884,8 +2876,8 @@ static long
remain_size(rb_io_t *fptr) remain_size(rb_io_t *fptr)
{ {
struct stat st; struct stat st;
off_t siz = READ_DATA_PENDING_COUNT(fptr); rb_off_t siz = READ_DATA_PENDING_COUNT(fptr);
off_t pos; rb_off_t pos;
if (fstat(fptr->fd, &st) == 0 && S_ISREG(st.st_mode) if (fstat(fptr->fd, &st) == 0 && S_ISREG(st.st_mode)
#if defined(__HAIKU__) #if defined(__HAIKU__)
@ -5662,7 +5654,7 @@ rb_io_sysseek(int argc, VALUE *argv, VALUE io)
VALUE offset, ptrname; VALUE offset, ptrname;
int whence = SEEK_SET; int whence = SEEK_SET;
rb_io_t *fptr; rb_io_t *fptr;
off_t pos; rb_off_t pos;
if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) { if (rb_scan_args(argc, argv, "11", &offset, &ptrname) == 2) {
whence = interpret_seek_whence(ptrname); whence = interpret_seek_whence(ptrname);
@ -5790,7 +5782,7 @@ struct prdwr_internal_arg {
int fd; int fd;
void *buf; void *buf;
size_t count; size_t count;
off_t offset; rb_off_t offset;
}; };
#endif /* HAVE_PREAD || HAVE_PWRITE */ #endif /* HAVE_PREAD || HAVE_PWRITE */
@ -7984,7 +7976,7 @@ io_reopen(VALUE io, VALUE nfile)
{ {
rb_io_t *fptr, *orig; rb_io_t *fptr, *orig;
int fd, fd2; int fd, fd2;
off_t pos = 0; rb_off_t pos = 0;
nfile = rb_io_get_io(nfile); nfile = rb_io_get_io(nfile);
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
@ -8204,7 +8196,7 @@ rb_io_init_copy(VALUE dest, VALUE io)
rb_io_t *fptr, *orig; rb_io_t *fptr, *orig;
int fd; int fd;
VALUE write_io; VALUE write_io;
off_t pos; rb_off_t pos;
io = rb_io_get_io(io); io = rb_io_get_io(io);
if (!OBJ_INIT_COPY(dest, io)) return dest; if (!OBJ_INIT_COPY(dest, io)) return dest;
@ -10345,8 +10337,8 @@ static VALUE sym_normal, sym_sequential, sym_random,
struct io_advise_struct { struct io_advise_struct {
int fd; int fd;
int advice; int advice;
off_t offset; rb_off_t offset;
off_t len; rb_off_t len;
}; };
static VALUE static VALUE
@ -10393,7 +10385,7 @@ io_advise_sym_to_const(VALUE sym)
} }
static VALUE static VALUE
do_io_advise(rb_io_t *fptr, VALUE advice, off_t offset, off_t len) do_io_advise(rb_io_t *fptr, VALUE advice, rb_off_t offset, rb_off_t len)
{ {
int rv; int rv;
struct io_advise_struct ias; struct io_advise_struct ias;
@ -10483,7 +10475,7 @@ static VALUE
rb_io_advise(int argc, VALUE *argv, VALUE io) rb_io_advise(int argc, VALUE *argv, VALUE io)
{ {
VALUE advice, offset, len; VALUE advice, offset, len;
off_t off, l; rb_off_t off, l;
rb_io_t *fptr; rb_io_t *fptr;
rb_scan_args(argc, argv, "12", &advice, &offset, &len); rb_scan_args(argc, argv, "12", &advice, &offset, &len);
@ -12029,15 +12021,15 @@ rb_io_s_binwrite(int argc, VALUE *argv, VALUE io)
struct copy_stream_struct { struct copy_stream_struct {
VALUE src; VALUE src;
VALUE dst; VALUE dst;
off_t copy_length; /* (off_t)-1 if not specified */ rb_off_t copy_length; /* (rb_off_t)-1 if not specified */
off_t src_offset; /* (off_t)-1 if not specified */ rb_off_t src_offset; /* (rb_off_t)-1 if not specified */
rb_io_t *src_fptr; rb_io_t *src_fptr;
rb_io_t *dst_fptr; rb_io_t *dst_fptr;
unsigned close_src : 1; unsigned close_src : 1;
unsigned close_dst : 1; unsigned close_dst : 1;
int error_no; int error_no;
off_t total; rb_off_t total;
const char *syserr; const char *syserr;
const char *notimp; const char *notimp;
VALUE th; VALUE th;
@ -12202,7 +12194,7 @@ nogvl_copy_stream_wait_write(struct copy_stream_struct *stp)
#ifdef USE_COPY_FILE_RANGE #ifdef USE_COPY_FILE_RANGE
static ssize_t static ssize_t
simple_copy_file_range(int in_fd, off_t *in_offset, int out_fd, off_t *out_offset, size_t count, unsigned int flags) simple_copy_file_range(int in_fd, rb_off_t *in_offset, int out_fd, rb_off_t *out_offset, size_t count, unsigned int flags)
{ {
#ifdef HAVE_COPY_FILE_RANGE #ifdef HAVE_COPY_FILE_RANGE
return copy_file_range(in_fd, in_offset, out_fd, out_offset, count, flags); return copy_file_range(in_fd, in_offset, out_fd, out_offset, count, flags);
@ -12215,15 +12207,15 @@ static int
nogvl_copy_file_range(struct copy_stream_struct *stp) nogvl_copy_file_range(struct copy_stream_struct *stp)
{ {
ssize_t ss; ssize_t ss;
off_t src_size; rb_off_t src_size;
off_t copy_length, src_offset, *src_offset_ptr; rb_off_t copy_length, src_offset, *src_offset_ptr;
if (!S_ISREG(stp->src_stat.st_mode)) if (!S_ISREG(stp->src_stat.st_mode))
return 0; return 0;
src_size = stp->src_stat.st_size; src_size = stp->src_stat.st_size;
src_offset = stp->src_offset; src_offset = stp->src_offset;
if (src_offset >= (off_t)0) { if (src_offset >= (rb_off_t)0) {
src_offset_ptr = &src_offset; src_offset_ptr = &src_offset;
} }
else { else {
@ -12231,12 +12223,12 @@ nogvl_copy_file_range(struct copy_stream_struct *stp)
} }
copy_length = stp->copy_length; copy_length = stp->copy_length;
if (copy_length < (off_t)0) { if (copy_length < (rb_off_t)0) {
if (src_offset < (off_t)0) { if (src_offset < (rb_off_t)0) {
off_t current_offset; rb_off_t current_offset;
errno = 0; errno = 0;
current_offset = lseek(stp->src_fptr->fd, 0, SEEK_CUR); current_offset = lseek(stp->src_fptr->fd, 0, SEEK_CUR);
if (current_offset < (off_t)0 && errno) { if (current_offset < (rb_off_t)0 && errno) {
stp->syserr = "lseek"; stp->syserr = "lseek";
stp->error_no = errno; stp->error_no = errno;
return (int)current_offset; return (int)current_offset;
@ -12251,7 +12243,7 @@ nogvl_copy_file_range(struct copy_stream_struct *stp)
retry_copy_file_range: retry_copy_file_range:
# if SIZEOF_OFF_T > SIZEOF_SIZE_T # if SIZEOF_OFF_T > SIZEOF_SIZE_T
/* we are limited by the 32-bit ssize_t return value on 32-bit */ /* we are limited by the 32-bit ssize_t return value on 32-bit */
ss = (copy_length > (off_t)SSIZE_MAX) ? SSIZE_MAX : (ssize_t)copy_length; ss = (copy_length > (rb_off_t)SSIZE_MAX) ? SSIZE_MAX : (ssize_t)copy_length;
# else # else
ss = (ssize_t)copy_length; ss = (ssize_t)copy_length;
# endif # endif
@ -12310,11 +12302,11 @@ nogvl_copy_file_range(struct copy_stream_struct *stp)
static int static int
nogvl_fcopyfile(struct copy_stream_struct *stp) nogvl_fcopyfile(struct copy_stream_struct *stp)
{ {
off_t cur, ss = 0; rb_off_t cur, ss = 0;
const off_t src_offset = stp->src_offset; const rb_off_t src_offset = stp->src_offset;
int ret; int ret;
if (stp->copy_length >= (off_t)0) { if (stp->copy_length >= (rb_off_t)0) {
/* copy_length can't be specified in fcopyfile(3) */ /* copy_length can't be specified in fcopyfile(3) */
return 0; return 0;
} }
@ -12324,30 +12316,30 @@ nogvl_fcopyfile(struct copy_stream_struct *stp)
if (!S_ISREG(stp->dst_stat.st_mode)) if (!S_ISREG(stp->dst_stat.st_mode))
return 0; return 0;
if (lseek(stp->dst_fptr->fd, 0, SEEK_CUR) > (off_t)0) /* if dst IO was already written */ if (lseek(stp->dst_fptr->fd, 0, SEEK_CUR) > (rb_off_t)0) /* if dst IO was already written */
return 0; return 0;
if (fcntl(stp->dst_fptr->fd, F_GETFL) & O_APPEND) { if (fcntl(stp->dst_fptr->fd, F_GETFL) & O_APPEND) {
/* fcopyfile(3) appends src IO to dst IO and then truncates /* fcopyfile(3) appends src IO to dst IO and then truncates
* dst IO to src IO's original size. */ * dst IO to src IO's original size. */
off_t end = lseek(stp->dst_fptr->fd, 0, SEEK_END); rb_off_t end = lseek(stp->dst_fptr->fd, 0, SEEK_END);
lseek(stp->dst_fptr->fd, 0, SEEK_SET); lseek(stp->dst_fptr->fd, 0, SEEK_SET);
if (end > (off_t)0) return 0; if (end > (rb_off_t)0) return 0;
} }
if (src_offset > (off_t)0) { if (src_offset > (rb_off_t)0) {
off_t r; rb_off_t r;
/* get current offset */ /* get current offset */
errno = 0; errno = 0;
cur = lseek(stp->src_fptr->fd, 0, SEEK_CUR); cur = lseek(stp->src_fptr->fd, 0, SEEK_CUR);
if (cur < (off_t)0 && errno) { if (cur < (rb_off_t)0 && errno) {
stp->error_no = errno; stp->error_no = errno;
return 1; return 1;
} }
errno = 0; errno = 0;
r = lseek(stp->src_fptr->fd, src_offset, SEEK_SET); r = lseek(stp->src_fptr->fd, src_offset, SEEK_SET);
if (r < (off_t)0 && errno) { if (r < (rb_off_t)0 && errno) {
stp->error_no = errno; stp->error_no = errno;
return 1; return 1;
} }
@ -12359,12 +12351,12 @@ nogvl_fcopyfile(struct copy_stream_struct *stp)
if (ret == 0) { /* success */ if (ret == 0) { /* success */
stp->total = ss; stp->total = ss;
if (src_offset > (off_t)0) { if (src_offset > (rb_off_t)0) {
off_t r; rb_off_t r;
errno = 0; errno = 0;
/* reset offset */ /* reset offset */
r = lseek(stp->src_fptr->fd, cur, SEEK_SET); r = lseek(stp->src_fptr->fd, cur, SEEK_SET);
if (r < (off_t)0 && errno) { if (r < (rb_off_t)0 && errno) {
stp->error_no = errno; stp->error_no = errno;
return 1; return 1;
} }
@ -12395,7 +12387,7 @@ nogvl_fcopyfile(struct copy_stream_struct *stp)
# endif # endif
static ssize_t static ssize_t
simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count) simple_sendfile(int out_fd, int in_fd, rb_off_t *offset, rb_off_t count)
{ {
return sendfile(out_fd, in_fd, offset, (size_t)count); return sendfile(out_fd, in_fd, offset, (size_t)count);
} }
@ -12407,11 +12399,11 @@ simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count)
# define USE_SENDFILE # define USE_SENDFILE
static ssize_t static ssize_t
simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count) simple_sendfile(int out_fd, int in_fd, rb_off_t *offset, rb_off_t count)
{ {
int r; int r;
off_t pos = offset ? *offset : lseek(in_fd, 0, SEEK_CUR); rb_off_t pos = offset ? *offset : lseek(in_fd, 0, SEEK_CUR);
off_t sbytes; rb_off_t sbytes;
# ifdef __APPLE__ # ifdef __APPLE__
r = sendfile(in_fd, out_fd, pos, &count, NULL, 0); r = sendfile(in_fd, out_fd, pos, &count, NULL, 0);
sbytes = count; sbytes = count;
@ -12437,9 +12429,9 @@ static int
nogvl_copy_stream_sendfile(struct copy_stream_struct *stp) nogvl_copy_stream_sendfile(struct copy_stream_struct *stp)
{ {
ssize_t ss; ssize_t ss;
off_t src_size; rb_off_t src_size;
off_t copy_length; rb_off_t copy_length;
off_t src_offset; rb_off_t src_offset;
int use_pread; int use_pread;
if (!S_ISREG(stp->src_stat.st_mode)) if (!S_ISREG(stp->src_stat.st_mode))
@ -12452,17 +12444,17 @@ nogvl_copy_stream_sendfile(struct copy_stream_struct *stp)
#endif #endif
src_offset = stp->src_offset; src_offset = stp->src_offset;
use_pread = src_offset >= (off_t)0; use_pread = src_offset >= (rb_off_t)0;
copy_length = stp->copy_length; copy_length = stp->copy_length;
if (copy_length < (off_t)0) { if (copy_length < (rb_off_t)0) {
if (use_pread) if (use_pread)
copy_length = src_size - src_offset; copy_length = src_size - src_offset;
else { else {
off_t cur; rb_off_t cur;
errno = 0; errno = 0;
cur = lseek(stp->src_fptr->fd, 0, SEEK_CUR); cur = lseek(stp->src_fptr->fd, 0, SEEK_CUR);
if (cur < (off_t)0 && errno) { if (cur < (rb_off_t)0 && errno) {
stp->syserr = "lseek"; stp->syserr = "lseek";
stp->error_no = errno; stp->error_no = errno;
return (int)cur; return (int)cur;
@ -12474,7 +12466,7 @@ nogvl_copy_stream_sendfile(struct copy_stream_struct *stp)
retry_sendfile: retry_sendfile:
# if SIZEOF_OFF_T > SIZEOF_SIZE_T # if SIZEOF_OFF_T > SIZEOF_SIZE_T
/* we are limited by the 32-bit ssize_t return value on 32-bit */ /* we are limited by the 32-bit ssize_t return value on 32-bit */
ss = (copy_length > (off_t)SSIZE_MAX) ? SSIZE_MAX : (ssize_t)copy_length; ss = (copy_length > (rb_off_t)SSIZE_MAX) ? SSIZE_MAX : (ssize_t)copy_length;
# else # else
ss = (ssize_t)copy_length; ss = (ssize_t)copy_length;
# endif # endif
@ -12545,11 +12537,11 @@ maygvl_read(int has_gvl, rb_io_t *fptr, void *buf, size_t count)
} }
static ssize_t static ssize_t
maygvl_copy_stream_read(int has_gvl, struct copy_stream_struct *stp, char *buf, size_t len, off_t offset) maygvl_copy_stream_read(int has_gvl, struct copy_stream_struct *stp, char *buf, size_t len, rb_off_t offset)
{ {
ssize_t ss; ssize_t ss;
retry_read: retry_read:
if (offset < (off_t)0) { if (offset < (rb_off_t)0) {
ss = maygvl_read(has_gvl, stp->src_fptr, buf, len); ss = maygvl_read(has_gvl, stp->src_fptr, buf, len);
} }
else { else {
@ -12582,7 +12574,7 @@ maygvl_copy_stream_read(int has_gvl, struct copy_stream_struct *stp, char *buf,
return ss; return ss;
#endif #endif
} }
stp->syserr = offset < (off_t)0 ? "read" : "pread"; stp->syserr = offset < (rb_off_t)0 ? "read" : "pread";
stp->error_no = errno; stp->error_no = errno;
} }
return ss; return ss;
@ -12621,31 +12613,31 @@ nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
size_t len; size_t len;
ssize_t ss; ssize_t ss;
int ret; int ret;
off_t copy_length; rb_off_t copy_length;
rb_off_t src_offset;
int use_eof; int use_eof;
off_t src_offset;
int use_pread; int use_pread;
copy_length = stp->copy_length; copy_length = stp->copy_length;
use_eof = copy_length < (off_t)0; use_eof = copy_length < (rb_off_t)0;
src_offset = stp->src_offset; src_offset = stp->src_offset;
use_pread = src_offset >= (off_t)0; use_pread = src_offset >= (rb_off_t)0;
if (use_pread && stp->close_src) { if (use_pread && stp->close_src) {
off_t r; rb_off_t r;
errno = 0; errno = 0;
r = lseek(stp->src_fptr->fd, src_offset, SEEK_SET); r = lseek(stp->src_fptr->fd, src_offset, SEEK_SET);
if (r < (off_t)0 && errno) { if (r < (rb_off_t)0 && errno) {
stp->syserr = "lseek"; stp->syserr = "lseek";
stp->error_no = errno; stp->error_no = errno;
return; return;
} }
src_offset = (off_t)-1; src_offset = (rb_off_t)-1;
use_pread = 0; use_pread = 0;
} }
while (use_eof || 0 < copy_length) { while (use_eof || 0 < copy_length) {
if (!use_eof && copy_length < (off_t)sizeof(buf)) { if (!use_eof && copy_length < (rb_off_t)sizeof(buf)) {
len = (size_t)copy_length; len = (size_t)copy_length;
} }
else { else {
@ -12657,7 +12649,7 @@ nogvl_copy_stream_read_write(struct copy_stream_struct *stp)
src_offset += ss; src_offset += ss;
} }
else { else {
ss = maygvl_copy_stream_read(0, stp, buf, len, (off_t)-1); ss = maygvl_copy_stream_read(0, stp, buf, len, (rb_off_t)-1);
} }
if (ss <= 0) /* EOF or error */ if (ss <= 0) /* EOF or error */
return; return;
@ -12712,8 +12704,8 @@ copy_stream_fallback_body(VALUE arg)
const int buflen = 16*1024; const int buflen = 16*1024;
VALUE n; VALUE n;
VALUE buf = rb_str_buf_new(buflen); VALUE buf = rb_str_buf_new(buflen);
off_t rest = stp->copy_length; rb_off_t rest = stp->copy_length;
off_t off = stp->src_offset; rb_off_t off = stp->src_offset;
ID read_method = id_readpartial; ID read_method = id_readpartial;
if (!stp->src_fptr) { if (!stp->src_fptr) {
@ -12725,7 +12717,7 @@ copy_stream_fallback_body(VALUE arg)
while (1) { while (1) {
long numwrote; long numwrote;
long l; long l;
if (stp->copy_length < (off_t)0) { if (stp->copy_length < (rb_off_t)0) {
l = buflen; l = buflen;
} }
else { else {
@ -12750,7 +12742,7 @@ copy_stream_fallback_body(VALUE arg)
return Qnil; return Qnil;
if (ss == 0) if (ss == 0)
rb_eof_error(); rb_eof_error();
if (off >= (off_t)0) if (off >= (rb_off_t)0)
off += ss; off += ss;
} }
n = rb_io_write(stp->dst, buf); n = rb_io_write(stp->dst, buf);
@ -12768,7 +12760,7 @@ copy_stream_fallback_body(VALUE arg)
static VALUE static VALUE
copy_stream_fallback(struct copy_stream_struct *stp) copy_stream_fallback(struct copy_stream_struct *stp)
{ {
if (!stp->src_fptr && stp->src_offset >= (off_t)0) { if (!stp->src_fptr && stp->src_offset >= (rb_off_t)0) {
rb_raise(rb_eArgError, "cannot specify src_offset for non-IO"); rb_raise(rb_eArgError, "cannot specify src_offset for non-IO");
} }
rb_rescue2(copy_stream_fallback_body, (VALUE)stp, rb_rescue2(copy_stream_fallback_body, (VALUE)stp,
@ -12868,10 +12860,10 @@ copy_stream_body(VALUE arg)
if (stp->dst_fptr) if (stp->dst_fptr)
io_ascii8bit_binmode(stp->dst_fptr); io_ascii8bit_binmode(stp->dst_fptr);
if (stp->src_offset < (off_t)0 && stp->src_fptr && stp->src_fptr->rbuf.len) { if (stp->src_offset < (rb_off_t)0 && stp->src_fptr && stp->src_fptr->rbuf.len) {
size_t len = stp->src_fptr->rbuf.len; size_t len = stp->src_fptr->rbuf.len;
VALUE str; VALUE str;
if (stp->copy_length >= (off_t)0 && stp->copy_length < (off_t)len) { if (stp->copy_length >= (rb_off_t)0 && stp->copy_length < (rb_off_t)len) {
len = (size_t)stp->copy_length; len = (size_t)stp->copy_length;
} }
str = rb_str_buf_new(len); str = rb_str_buf_new(len);
@ -12885,7 +12877,7 @@ copy_stream_body(VALUE arg)
rb_io_write(dst_io, str); rb_io_write(dst_io, str);
rb_str_resize(str, 0); rb_str_resize(str, 0);
stp->total += len; stp->total += len;
if (stp->copy_length >= (off_t)0) if (stp->copy_length >= (rb_off_t)0)
stp->copy_length -= len; stp->copy_length -= len;
} }
@ -12998,12 +12990,12 @@ rb_io_s_copy_stream(int argc, VALUE *argv, VALUE io)
st.dst_fptr = NULL; st.dst_fptr = NULL;
if (NIL_P(length)) if (NIL_P(length))
st.copy_length = (off_t)-1; st.copy_length = (rb_off_t)-1;
else else
st.copy_length = NUM2OFFT(length); st.copy_length = NUM2OFFT(length);
if (NIL_P(src_offset)) if (NIL_P(src_offset))
st.src_offset = (off_t)-1; st.src_offset = (rb_off_t)-1;
else else
st.src_offset = NUM2OFFT(src_offset); st.src_offset = NUM2OFFT(src_offset);

View file

@ -64,7 +64,7 @@ io_buffer_map_memory(size_t size)
} }
static void static void
io_buffer_map_file(struct rb_io_buffer *data, int descriptor, size_t size, off_t offset, enum rb_io_buffer_flags flags) io_buffer_map_file(struct rb_io_buffer *data, int descriptor, size_t size, rb_off_t offset, enum rb_io_buffer_flags flags)
{ {
#if defined(_WIN32) #if defined(_WIN32)
HANDLE file = (HANDLE)_get_osfhandle(descriptor); HANDLE file = (HANDLE)_get_osfhandle(descriptor);
@ -409,7 +409,7 @@ rb_io_buffer_new(void *base, size_t size, enum rb_io_buffer_flags flags)
} }
VALUE VALUE
rb_io_buffer_map(VALUE io, size_t size, off_t offset, enum rb_io_buffer_flags flags) rb_io_buffer_map(VALUE io, size_t size, rb_off_t offset, enum rb_io_buffer_flags flags)
{ {
io_buffer_experimental(); io_buffer_experimental();
@ -478,7 +478,7 @@ io_buffer_map(int argc, VALUE *argv, VALUE klass)
size = RB_NUM2SIZE(argv[1]); size = RB_NUM2SIZE(argv[1]);
} }
else { else {
off_t file_size = rb_file_size(io); rb_off_t file_size = rb_file_size(io);
// Compiler can confirm that we handled file_size < 0 case: // Compiler can confirm that we handled file_size < 0 case:
if (file_size < 0) { if (file_size < 0) {
@ -494,7 +494,7 @@ io_buffer_map(int argc, VALUE *argv, VALUE klass)
} }
} }
off_t offset = 0; rb_off_t offset = 0;
if (argc >= 3) { if (argc >= 3) {
offset = NUM2OFFT(argv[2]); offset = NUM2OFFT(argv[2]);
} }
@ -2037,7 +2037,7 @@ io_buffer_read(VALUE self, VALUE io, VALUE length)
} }
VALUE VALUE
rb_io_buffer_pread(VALUE self, VALUE io, size_t length, off_t offset) rb_io_buffer_pread(VALUE self, VALUE io, size_t length, rb_off_t offset)
{ {
VALUE scheduler = rb_fiber_scheduler_current(); VALUE scheduler = rb_fiber_scheduler_current();
if (scheduler != Qnil) { if (scheduler != Qnil) {
@ -2063,16 +2063,16 @@ rb_io_buffer_pread(VALUE self, VALUE io, size_t length, off_t offset)
ssize_t result = pread(descriptor, base, size, offset); ssize_t result = pread(descriptor, base, size, offset);
#else #else
// This emulation is not thread safe, but the GVL means it's unlikely to be a problem. // This emulation is not thread safe, but the GVL means it's unlikely to be a problem.
off_t current_offset = lseek(descriptor, 0, SEEK_CUR); rb_off_t current_offset = lseek(descriptor, 0, SEEK_CUR);
if (current_offset == (off_t)-1) if (current_offset == (rb_off_t)-1)
return rb_fiber_scheduler_io_result(-1, errno); return rb_fiber_scheduler_io_result(-1, errno);
if (lseek(descriptor, offset, SEEK_SET) == (off_t)-1) if (lseek(descriptor, offset, SEEK_SET) == (rb_off_t)-1)
return rb_fiber_scheduler_io_result(-1, errno); return rb_fiber_scheduler_io_result(-1, errno);
ssize_t result = read(descriptor, base, size); ssize_t result = read(descriptor, base, size);
if (lseek(descriptor, current_offset, SEEK_SET) == (off_t)-1) if (lseek(descriptor, current_offset, SEEK_SET) == (rb_off_t)-1)
return rb_fiber_scheduler_io_result(-1, errno); return rb_fiber_scheduler_io_result(-1, errno);
#endif #endif
@ -2120,7 +2120,7 @@ io_buffer_write(VALUE self, VALUE io, VALUE length)
} }
VALUE VALUE
rb_io_buffer_pwrite(VALUE self, VALUE io, size_t length, off_t offset) rb_io_buffer_pwrite(VALUE self, VALUE io, size_t length, rb_off_t offset)
{ {
VALUE scheduler = rb_fiber_scheduler_current(); VALUE scheduler = rb_fiber_scheduler_current();
if (scheduler != Qnil) { if (scheduler != Qnil) {
@ -2146,16 +2146,16 @@ rb_io_buffer_pwrite(VALUE self, VALUE io, size_t length, off_t offset)
ssize_t result = pwrite(descriptor, base, length, offset); ssize_t result = pwrite(descriptor, base, length, offset);
#else #else
// This emulation is not thread safe, but the GVL means it's unlikely to be a problem. // This emulation is not thread safe, but the GVL means it's unlikely to be a problem.
off_t current_offset = lseek(descriptor, 0, SEEK_CUR); rb_off_t current_offset = lseek(descriptor, 0, SEEK_CUR);
if (current_offset == (off_t)-1) if (current_offset == (rb_off_t)-1)
return rb_fiber_scheduler_io_result(-1, errno); return rb_fiber_scheduler_io_result(-1, errno);
if (lseek(descriptor, offset, SEEK_SET) == (off_t)-1) if (lseek(descriptor, offset, SEEK_SET) == (rb_off_t)-1)
return rb_fiber_scheduler_io_result(-1, errno); return rb_fiber_scheduler_io_result(-1, errno);
ssize_t result = write(descriptor, base, length); ssize_t result = write(descriptor, base, length);
if (lseek(descriptor, current_offset, SEEK_SET) == (off_t)-1) if (lseek(descriptor, current_offset, SEEK_SET) == (rb_off_t)-1)
return rb_fiber_scheduler_io_result(-1, errno); return rb_fiber_scheduler_io_result(-1, errno);
#endif #endif

View file

@ -242,7 +242,7 @@ rb_fiber_scheduler_io_read(VALUE scheduler, VALUE io, VALUE buffer, size_t lengt
} }
VALUE VALUE
rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, VALUE buffer, size_t length, off_t offset) rb_fiber_scheduler_io_pread(VALUE scheduler, VALUE io, VALUE buffer, size_t length, rb_off_t offset)
{ {
VALUE arguments[] = { VALUE arguments[] = {
io, buffer, SIZET2NUM(length), OFFT2NUM(offset) io, buffer, SIZET2NUM(length), OFFT2NUM(offset)
@ -262,7 +262,7 @@ rb_fiber_scheduler_io_write(VALUE scheduler, VALUE io, VALUE buffer, size_t leng
} }
VALUE VALUE
rb_fiber_scheduler_io_pwrite(VALUE scheduler, VALUE io, VALUE buffer, size_t length, off_t offset) rb_fiber_scheduler_io_pwrite(VALUE scheduler, VALUE io, VALUE buffer, size_t length, rb_off_t offset)
{ {
VALUE arguments[] = { VALUE arguments[] = {
io, buffer, SIZET2NUM(length), OFFT2NUM(offset) io, buffer, SIZET2NUM(length), OFFT2NUM(offset)

View file

@ -632,6 +632,10 @@ $(CONFIG_H): $(MKFILES) $(srcdir)/win32/Makefile.sub $(win_srcdir)/Makefile.sub
#define ULL_TO_DOUBLE(n) ((double)(unsigned long)((n)>>32) * (1I64 << 32) + (unsigned long)(n)) #define ULL_TO_DOUBLE(n) ((double)(unsigned long)((n)>>32) * (1I64 << 32) + (unsigned long)(n))
!endif !endif
#define HAVE_OFF_T 1 #define HAVE_OFF_T 1
#define rb_off_t __int64
#define SIGNEDNESS_OF_OFF_T -1
#define OFFT2NUM(v) LL2NUM(v)
#define NUM2OFFT(v) NUM2LL(v)
#define SIZEOF_INT 4 #define SIZEOF_INT 4
#define SIZEOF_SHORT 2 #define SIZEOF_SHORT 2
#define SIZEOF_LONG 4 #define SIZEOF_LONG 4

View file

@ -5899,8 +5899,8 @@ rb_w32_lstati128(const char *path, struct stati128 *st)
} }
/* License: Ruby's */ /* License: Ruby's */
off_t rb_off_t
rb_w32_lseek(int fd, off_t ofs, int whence) rb_w32_lseek(int fd, rb_off_t ofs, int whence)
{ {
SOCKET sock = TO_SOCKET(fd); SOCKET sock = TO_SOCKET(fd);
if (is_socket(sock) || is_pipe(sock)) { if (is_socket(sock) || is_pipe(sock)) {
@ -5941,7 +5941,7 @@ rb_w32_uaccess(const char *path, int mode)
/* License: Ruby's */ /* License: Ruby's */
static int static int
rb_chsize(HANDLE h, off_t size) rb_chsize(HANDLE h, rb_off_t size)
{ {
long upos, lpos, usize, lsize; long upos, lpos, usize, lsize;
int ret = -1; int ret = -1;
@ -5970,7 +5970,7 @@ rb_chsize(HANDLE h, off_t size)
/* License: Ruby's */ /* License: Ruby's */
static int static int
w32_truncate(const char *path, off_t length, UINT cp) w32_truncate(const char *path, rb_off_t length, UINT cp)
{ {
HANDLE h; HANDLE h;
int ret; int ret;
@ -5992,21 +5992,21 @@ w32_truncate(const char *path, off_t length, UINT cp)
/* License: Ruby's */ /* License: Ruby's */
int int
rb_w32_utruncate(const char *path, off_t length) rb_w32_utruncate(const char *path, rb_off_t length)
{ {
return w32_truncate(path, length, CP_UTF8); return w32_truncate(path, length, CP_UTF8);
} }
/* License: Ruby's */ /* License: Ruby's */
int int
rb_w32_truncate(const char *path, off_t length) rb_w32_truncate(const char *path, rb_off_t length)
{ {
return w32_truncate(path, length, filecp()); return w32_truncate(path, length, filecp());
} }
/* License: Ruby's */ /* License: Ruby's */
int int
rb_w32_ftruncate(int fd, off_t length) rb_w32_ftruncate(int fd, rb_off_t length)
{ {
HANDLE h; HANDLE h;
@ -8214,7 +8214,7 @@ VALUE (*const rb_f_notimplement_)(int, const VALUE *, VALUE, VALUE) = rb_f_notim
#endif #endif
void * void *
rb_w32_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) rb_w32_mmap(void *addr, size_t len, int prot, int flags, int fd, rb_off_t offset)
{ {
void *ptr; void *ptr;
//DWORD protect = 0; //DWORD protect = 0;