diff options
Diffstat (limited to 'src/doc.c')
| -rw-r--r-- | src/doc.c | 41 |
1 files changed, 23 insertions, 18 deletions
| @@ -21,6 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 21 | 21 | ||
| 22 | #include <config.h> | 22 | #include <config.h> |
| 23 | 23 | ||
| 24 | #include <errno.h> | ||
| 24 | #include <sys/types.h> | 25 | #include <sys/types.h> |
| 25 | #include <sys/file.h> /* Must be after sys/types.h for USG. */ | 26 | #include <sys/file.h> /* Must be after sys/types.h for USG. */ |
| 26 | #include <fcntl.h> | 27 | #include <fcntl.h> |
| @@ -84,6 +85,7 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) | |||
| 84 | int offset; | 85 | int offset; |
| 85 | EMACS_INT position; | 86 | EMACS_INT position; |
| 86 | Lisp_Object file, tem, pos; | 87 | Lisp_Object file, tem, pos; |
| 88 | ptrdiff_t count; | ||
| 87 | USE_SAFE_ALLOCA; | 89 | USE_SAFE_ALLOCA; |
| 88 | 90 | ||
| 89 | if (INTEGERP (filepos)) | 91 | if (INTEGERP (filepos)) |
| @@ -143,9 +145,14 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) | |||
| 143 | } | 145 | } |
| 144 | #endif | 146 | #endif |
| 145 | if (fd < 0) | 147 | if (fd < 0) |
| 146 | return concat3 (build_string ("Cannot open doc string file \""), | 148 | { |
| 147 | file, build_string ("\"\n")); | 149 | SAFE_FREE (); |
| 150 | return concat3 (build_string ("Cannot open doc string file \""), | ||
| 151 | file, build_string ("\"\n")); | ||
| 152 | } | ||
| 148 | } | 153 | } |
| 154 | count = SPECPDL_INDEX (); | ||
| 155 | record_unwind_protect_int (close_file_unwind, fd); | ||
| 149 | 156 | ||
| 150 | /* Seek only to beginning of disk block. */ | 157 | /* Seek only to beginning of disk block. */ |
| 151 | /* Make sure we read at least 1024 bytes before `position' | 158 | /* Make sure we read at least 1024 bytes before `position' |
| @@ -153,13 +160,8 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) | |||
| 153 | offset = min (position, max (1024, position % (8 * 1024))); | 160 | offset = min (position, max (1024, position % (8 * 1024))); |
| 154 | if (TYPE_MAXIMUM (off_t) < position | 161 | if (TYPE_MAXIMUM (off_t) < position |
| 155 | || lseek (fd, position - offset, 0) < 0) | 162 | || lseek (fd, position - offset, 0) < 0) |
| 156 | { | 163 | error ("Position %"pI"d out of range in doc string file \"%s\"", |
| 157 | emacs_close (fd); | 164 | position, name); |
| 158 | error ("Position %"pI"d out of range in doc string file \"%s\"", | ||
| 159 | position, name); | ||
| 160 | } | ||
| 161 | |||
| 162 | SAFE_FREE (); | ||
| 163 | 165 | ||
| 164 | /* Read the doc string into get_doc_string_buffer. | 166 | /* Read the doc string into get_doc_string_buffer. |
| 165 | P points beyond the data just read. */ | 167 | P points beyond the data just read. */ |
| @@ -189,10 +191,7 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) | |||
| 189 | space_left = 1024 * 8; | 191 | space_left = 1024 * 8; |
| 190 | nread = emacs_read (fd, p, space_left); | 192 | nread = emacs_read (fd, p, space_left); |
| 191 | if (nread < 0) | 193 | if (nread < 0) |
| 192 | { | 194 | report_file_error ("Read error on documentation file", file); |
| 193 | emacs_close (fd); | ||
| 194 | error ("Read error on documentation file"); | ||
| 195 | } | ||
| 196 | p[nread] = 0; | 195 | p[nread] = 0; |
| 197 | if (!nread) | 196 | if (!nread) |
| 198 | break; | 197 | break; |
| @@ -208,7 +207,8 @@ get_doc_string (Lisp_Object filepos, bool unibyte, bool definition) | |||
| 208 | } | 207 | } |
| 209 | p += nread; | 208 | p += nread; |
| 210 | } | 209 | } |
| 211 | emacs_close (fd); | 210 | unbind_to (count, Qnil); |
| 211 | SAFE_FREE (); | ||
| 212 | 212 | ||
| 213 | /* Sanity checking. */ | 213 | /* Sanity checking. */ |
| 214 | if (CONSP (filepos)) | 214 | if (CONSP (filepos)) |
| @@ -573,6 +573,7 @@ the same file name is found in the `doc-directory'. */) | |||
| 573 | Lisp_Object sym; | 573 | Lisp_Object sym; |
| 574 | char *p, *name; | 574 | char *p, *name; |
| 575 | bool skip_file = 0; | 575 | bool skip_file = 0; |
| 576 | ptrdiff_t count; | ||
| 576 | 577 | ||
| 577 | CHECK_STRING (filename); | 578 | CHECK_STRING (filename); |
| 578 | 579 | ||
| @@ -609,8 +610,13 @@ the same file name is found in the `doc-directory'. */) | |||
| 609 | 610 | ||
| 610 | fd = emacs_open (name, O_RDONLY, 0); | 611 | fd = emacs_open (name, O_RDONLY, 0); |
| 611 | if (fd < 0) | 612 | if (fd < 0) |
| 612 | report_file_error ("Opening doc string file", | 613 | { |
| 613 | Fcons (build_string (name), Qnil)); | 614 | int open_errno = errno; |
| 615 | report_file_errno ("Opening doc string file", build_string (name), | ||
| 616 | open_errno); | ||
| 617 | } | ||
| 618 | count = SPECPDL_INDEX (); | ||
| 619 | record_unwind_protect_int (close_file_unwind, fd); | ||
| 614 | Vdoc_file_name = filename; | 620 | Vdoc_file_name = filename; |
| 615 | filled = 0; | 621 | filled = 0; |
| 616 | pos = 0; | 622 | pos = 0; |
| @@ -688,8 +694,7 @@ the same file name is found in the `doc-directory'. */) | |||
| 688 | filled -= end - buf; | 694 | filled -= end - buf; |
| 689 | memmove (buf, end, filled); | 695 | memmove (buf, end, filled); |
| 690 | } | 696 | } |
| 691 | emacs_close (fd); | 697 | return unbind_to (count, Qnil); |
| 692 | return Qnil; | ||
| 693 | } | 698 | } |
| 694 | 699 | ||
| 695 | DEFUN ("substitute-command-keys", Fsubstitute_command_keys, | 700 | DEFUN ("substitute-command-keys", Fsubstitute_command_keys, |