diff options
| -rw-r--r-- | src/fileio.c | 27 |
1 files changed, 12 insertions, 15 deletions
diff --git a/src/fileio.c b/src/fileio.c index 82ee22d2187..a3a49d179c4 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -4271,24 +4271,21 @@ by calling `format-decode', which see. */) | |||
| 4271 | { | 4271 | { |
| 4272 | /* Find a coding system specified in the heading two | 4272 | /* Find a coding system specified in the heading two |
| 4273 | lines or in the tailing several lines of the file. | 4273 | lines or in the tailing several lines of the file. |
| 4274 | We assume that the 1K-byte and 3K-byte for heading | 4274 | Assume that the 1 KiB and 3 KiB for heading |
| 4275 | and tailing respectively are sufficient for this | 4275 | and tailing respectively are sufficient for this |
| 4276 | purpose. */ | 4276 | purpose. Because the file may be in /proc, |
| 4277 | int nread; | 4277 | do not use st_size or report any SEEK_END failure. */ |
| 4278 | 4278 | ptrdiff_t nread = emacs_fd_read (fd, read_buf, 4 * 1024); | |
| 4279 | if (st.st_size <= (1024 * 4)) | 4279 | if (nread == 4 * 1024) |
| 4280 | nread = emacs_fd_read (fd, read_buf, 1024 * 4); | ||
| 4281 | else | ||
| 4282 | { | 4280 | { |
| 4283 | nread = emacs_fd_read (fd, read_buf, 1024); | 4281 | off_t tailoff = emacs_fd_lseek (fd, - 3 * 1024, SEEK_END); |
| 4284 | if (nread == 1024) | 4282 | if (tailoff < 0) |
| 4283 | seekable = false; | ||
| 4284 | else if (1024 < tailoff) | ||
| 4285 | { | 4285 | { |
| 4286 | int ntail; | 4286 | ptrdiff_t ntail = emacs_fd_read (fd, read_buf + 1024, |
| 4287 | if (emacs_fd_lseek (fd, st.st_size - 1024 * 3, SEEK_CUR) < 0) | 4287 | 3 * 1024); |
| 4288 | report_file_error ("Setting file position", | 4288 | nread = ntail < 0 ? ntail : 1024 + ntail; |
| 4289 | orig_filename); | ||
| 4290 | ntail = emacs_fd_read (fd, read_buf + nread, 1024 * 3); | ||
| 4291 | nread = ntail < 0 ? ntail : nread + ntail; | ||
| 4292 | } | 4289 | } |
| 4293 | } | 4290 | } |
| 4294 | 4291 | ||