* src/emacs.c (read_full):
Simplify by assuming MAX_RW_COUNT is defined.
* src/lisp.h (MAX_RW_COUNT): Move here from src/sysdep.c.
* src/pdumper.c (dump_read_all):
Use MAX_RW_COUNT rather than defining our own equivalent.
(cherry picked from commit
46314aef87fbda25e0a7fb5055624dc1c6e90ad9)
eassert (0 <= fd);
eassert (buffer != NULL);
eassert (0 <= size);
- enum
- {
- /* See MAX_RW_COUNT in sysdep.c. */
-#ifdef MAX_RW_COUNT
- max_size = MAX_RW_COUNT
-#else
- max_size = INT_MAX >> 18 << 18
-#endif
- };
- if (PTRDIFF_MAX < size || max_size < size)
+ if (max (PTRDIFF_MAX, MAX_RW_COUNT) < size)
{
errno = EFBIG;
return -1;
return argc;
}
#endif
+/* Maximum number of bytes to read or write in a single system call.
+ This works around a serious bug in Linux kernels before 2.6.16; see
+ <https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=612839>
+ and see Linux kernel commit e28cc71572da38a5a12c1cfe4d7032017adccf69.
+ It's likely to work around similar bugs in other operating systems, so do it
+ on all platforms. Round INT_MAX down to a page size, with the conservative
+ assumption that page sizes are at most 2**18 bytes (any kernel with a
+ page size larger than that shouldn't have the bug). */
+#ifndef MAX_RW_COUNT
+# define MAX_RW_COUNT (INT_MAX >> 18 << 18)
+#endif
extern int emacs_exec_file (char const *, char *const *, char *const *);
extern void init_standard_fds (void);
extern char *emacs_get_current_dir_name (void);
size_t bytes_read = 0;
while (bytes_read < bytes_to_read)
{
- /* Some platforms accept only int-sized values to read.
- Round this down to a page size (see MAX_RW_COUNT in sysdep.c). */
- int max_rw_count = INT_MAX >> 18 << 18;
- int chunk_to_read = min (bytes_to_read - bytes_read, max_rw_count);
+ int chunk_to_read = min (bytes_to_read - bytes_read, MAX_RW_COUNT);
ssize_t chunk = read (fd, (char *) buf + bytes_read, chunk_to_read);
if (chunk < 0)
return chunk;
#endif /* !(defined HAVE_ANDROID && !defined ANDROID_STUBIFY) */
}
-/* Maximum number of bytes to read or write in a single system call.
- This works around a serious bug in Linux kernels before 2.6.16; see
- <https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=612839>.
- It's likely to work around similar bugs in other operating systems, so do it
- on all platforms. Round INT_MAX down to a page size, with the conservative
- assumption that page sizes are at most 2**18 bytes (any kernel with a
- page size larger than that shouldn't have the bug). */
-#ifndef MAX_RW_COUNT
-#define MAX_RW_COUNT (INT_MAX >> 18 << 18)
-#endif
-
/* Verify that MAX_RW_COUNT fits in the relevant standard types. */
#ifndef SSIZE_MAX
# define SSIZE_MAX TYPE_MAXIMUM (ssize_t)