From 8a2cbd723c0b453b70dc1fcefe5b489f58605258 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sun, 10 Apr 2011 23:43:08 +0300 Subject: [PATCH] Fix write-region and its subroutines for buffers > 2GB. src/fileio.c (a_write, e_write): Modify declaration of arguments and local variables to support buffers larger than 2GB. (Fcopy_file): Use EMACS_INT for return value of emacs_read. src/sysdep.c (emacs_write, emacs_read): Use ssize_t for last argument, local variables, and return value. src/lisp.h: Update prototypes of emacs_write and emacs_read. src/sound.c (vox_write): Use ssize_t for return value of emacs_write. --- src/ChangeLog | 14 ++++++++++++++ src/fileio.c | 23 ++++++++++++++--------- src/lisp.h | 4 ++-- src/sound.c | 2 +- src/sysdep.c | 12 ++++++------ 5 files changed, 37 insertions(+), 18 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 3b5f00a542..242752cd77 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2011-04-10 Eli Zaretskii + + Fix write-region and its subroutines for buffers > 2GB. + * fileio.c (a_write, e_write): Modify declaration of arguments and + local variables to support buffers larger than 2GB. + (Fcopy_file): Use EMACS_INT for return value of emacs_read. + + * sysdep.c (emacs_write, emacs_read): Use ssize_t for last + argument, local variables, and return value. + + * lisp.h: Update prototypes of emacs_write and emacs_read. + + * sound.c (vox_write): Use ssize_t for return value of emacs_write. + 2011-04-10 Paul Eggert * xdisp.c (vmessage): Use memchr, not strnlen, which some hosts lack. diff --git a/src/fileio.c b/src/fileio.c index f9923c420a..7e2d888b22 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -143,9 +143,10 @@ Lisp_Object Qfile_name_history; Lisp_Object Qcar_less_than_car; -static int a_write (int, Lisp_Object, int, int, +static int a_write (int, Lisp_Object, EMACS_INT, EMACS_INT, Lisp_Object *, struct coding_system *); -static int e_write (int, Lisp_Object, int, int, struct coding_system *); +static int e_write (int, Lisp_Object, EMACS_INT, EMACS_INT, + struct coding_system *); void @@ -1805,7 +1806,8 @@ If PRESERVE-SELINUX-CONTEXT is non-nil and SELinux is enabled on the system, we copy the SELinux context of FILE to NEWNAME. */) (Lisp_Object file, Lisp_Object newname, Lisp_Object ok_if_already_exists, Lisp_Object keep_time, Lisp_Object preserve_uid_gid, Lisp_Object preserve_selinux_context) { - int ifd, ofd, n; + int ifd, ofd; + EMACS_INT n; char buf[16 * 1024]; struct stat st, out_st; Lisp_Object handler; @@ -4792,11 +4794,13 @@ build_annotations (Lisp_Object start, Lisp_Object end) The return value is negative in case of system call failure. */ static int -a_write (int desc, Lisp_Object string, int pos, register int nchars, Lisp_Object *annot, struct coding_system *coding) +a_write (int desc, Lisp_Object string, EMACS_INT pos, + register EMACS_INT nchars, Lisp_Object *annot, + struct coding_system *coding) { Lisp_Object tem; - int nextpos; - int lastpos = pos + nchars; + EMACS_INT nextpos; + EMACS_INT lastpos = pos + nchars; while (NILP (*annot) || CONSP (*annot)) { @@ -4836,7 +4840,8 @@ a_write (int desc, Lisp_Object string, int pos, register int nchars, Lisp_Object are indexes to the string STRING. */ static int -e_write (int desc, Lisp_Object string, int start, int end, struct coding_system *coding) +e_write (int desc, Lisp_Object string, EMACS_INT start, EMACS_INT end, + struct coding_system *coding) { if (STRINGP (string)) { @@ -4867,8 +4872,8 @@ e_write (int desc, Lisp_Object string, int start, int end, struct coding_system } else { - int start_byte = CHAR_TO_BYTE (start); - int end_byte = CHAR_TO_BYTE (end); + EMACS_INT start_byte = CHAR_TO_BYTE (start); + EMACS_INT end_byte = CHAR_TO_BYTE (end); coding->src_multibyte = (end - start) < (end_byte - start_byte); if (CODING_REQUIRE_ENCODING (coding)) diff --git a/src/lisp.h b/src/lisp.h index 4859862c88..d3e43c1cf1 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3346,8 +3346,8 @@ extern long get_random (void); extern void seed_random (long); extern int emacs_open (const char *, int, int); extern int emacs_close (int); -extern int emacs_read (int, char *, unsigned int); -extern int emacs_write (int, const char *, unsigned int); +extern ssize_t emacs_read (int, char *, ssize_t); +extern ssize_t emacs_write (int, const char *, ssize_t); enum { READLINK_BUFSIZE = 1024 }; extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]); #ifndef HAVE_MEMSET diff --git a/src/sound.c b/src/sound.c index a972809e2c..a9bd540aaa 100644 --- a/src/sound.c +++ b/src/sound.c @@ -897,7 +897,7 @@ vox_init (struct sound_device *sd) static void vox_write (struct sound_device *sd, const char *buffer, int nbytes) { - int nwritten = emacs_write (sd->fd, buffer, nbytes); + ssize_t nwritten = emacs_write (sd->fd, buffer, nbytes); if (nwritten < 0) sound_perror ("Error writing to sound device"); } diff --git a/src/sysdep.c b/src/sysdep.c index f4f767dac3..37c9f73dba 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1825,10 +1825,10 @@ emacs_close (int fd) return rtnval; } -int -emacs_read (int fildes, char *buf, unsigned int nbyte) +ssize_t +emacs_read (int fildes, char *buf, ssize_t nbyte) { - register int rtnval; + register ssize_t rtnval; while ((rtnval = read (fildes, buf, nbyte)) == -1 && (errno == EINTR)) @@ -1836,10 +1836,10 @@ emacs_read (int fildes, char *buf, unsigned int nbyte) return (rtnval); } -int -emacs_write (int fildes, const char *buf, unsigned int nbyte) +ssize_t +emacs_write (int fildes, const char *buf, ssize_t nbyte) { - register int rtnval, bytes_written; + register ssize_t rtnval, bytes_written; bytes_written = 0; -- 2.20.1