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.
This commit is contained in:
Eli Zaretskii 2011-04-10 23:43:08 +03:00
parent 1ebfdcb6ef
commit 8a2cbd723c
5 changed files with 37 additions and 18 deletions

View file

@ -1,3 +1,17 @@
2011-04-10 Eli Zaretskii <eliz@gnu.org>
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 <eggert@cs.ucla.edu>
* xdisp.c (vmessage): Use memchr, not strnlen, which some hosts lack.

View file

@ -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))

View file

@ -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

View file

@ -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");
}

View file

@ -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;