aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard M. Stallman1996-04-12 06:04:10 +0000
committerRichard M. Stallman1996-04-12 06:04:10 +0000
commit8748735b9ee3e3144ab5b52af74d0b360d6ab1d8 (patch)
tree17c0a21065f8b8278d745ba4b859b2992a97cbdf /src
parent3d6163992d1b84d9faed1b2053832f01adb2b516 (diff)
downloademacs-8748735b9ee3e3144ab5b52af74d0b360d6ab1d8.tar.gz
emacs-8748735b9ee3e3144ab5b52af74d0b360d6ab1d8.zip
Include signal.h.
(__write) [DJGPP == 2.0]: New function, avoids calling `malloc' while writing to a text file, so that buffer text being written won't be relocated. (abort) [DJGPP > 1]: Generate traceback, to identify the abort cause.
Diffstat (limited to 'src')
-rw-r--r--src/msdos.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/src/msdos.c b/src/msdos.c
index eefd48ee564..7eba18ed6b2 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -53,6 +53,8 @@ Boston, MA 02111-1307, USA. */
53 53
54#if __DJGPP__ > 1 54#if __DJGPP__ > 1
55 55
56#include <signal.h>
57
56#ifndef SYSTEM_MALLOC 58#ifndef SYSTEM_MALLOC
57 59
58#ifdef GNU_MALLOC 60#ifdef GNU_MALLOC
@@ -2125,6 +2127,81 @@ crlf_to_lf (n, buf)
2125 *np++ = *buf++; 2127 *np++ = *buf++;
2126 return np - startp; 2128 return np - startp;
2127} 2129}
2130
2131#if defined(__DJGPP__) && __DJGPP__ == 2 && __DJGPP_MINOR__ == 0
2132
2133/* In DJGPP v2.0, library `write' can call `malloc', which might
2134 cause relocation of the buffer whose address we get in ADDR.
2135 Here is a version of `write' that avoids calling `malloc',
2136 to serve us until such time as the library is fixed.
2137 Actually, what we define here is called `__write', because
2138 `write' is a stub that just jmp's to `__write' (to be
2139 POSIXLY-correct with respect to the global name-space). */
2140
2141#include <io.h> /* for _write */
2142#include <libc/dosio.h> /* for __file_handle_modes[] */
2143
2144static char xbuf[64 * 1024]; /* DOS cannot write more in one chunk */
2145
2146#define XBUF_END (xbuf + sizeof (xbuf) - 1)
2147
2148int
2149__write (int handle, const void *buffer, size_t count)
2150{
2151 if (count == 0)
2152 return 0;
2153
2154 if(__file_handle_modes[handle] & O_BINARY)
2155 return _write (handle, buffer, count);
2156 else
2157 {
2158 char *xbp = xbuf;
2159 const char *bp = buffer;
2160 int total_written = 0;
2161 int nmoved = 0, ncr = 0;
2162
2163 while (count)
2164 {
2165 /* The next test makes sure there's space for at least 2 more
2166 characters in xbuf[], so both CR and LF can be put there. */
2167 if (xbp < XBUF_END)
2168 {
2169 if (*bp == '\n')
2170 {
2171 ncr++;
2172 *xbp++ = '\r';
2173 }
2174 *xbp++ = *bp++;
2175 nmoved++;
2176 count--;
2177 }
2178 if (xbp >= XBUF_END || !count)
2179 {
2180 size_t to_write = nmoved + ncr;
2181 int written = _write (handle, xbuf, to_write);
2182
2183 if (written == -1)
2184 return -1;
2185 else
2186 total_written += nmoved; /* CRs aren't counted in ret value */
2187
2188 /* If some, but not all were written (disk full?), return
2189 an estimate of the total written bytes not counting CRs. */
2190 if (written < to_write)
2191 return total_written - (to_write - written) * nmoved/to_write;
2192
2193 nmoved = 0;
2194 ncr = 0;
2195 xbp = xbuf;
2196 }
2197 }
2198 return total_written;
2199 }
2200}
2201
2202#endif /* __DJGPP__ == 2 && __DJGPP_MINOR__ == 0 */
2203
2204
2128 2205
2129/* The Emacs root directory as determined by init_environment. */ 2206/* The Emacs root directory as determined by init_environment. */
2130 2207
@@ -2651,6 +2728,8 @@ check_timer (t)
2651 2728
2652 2729
2653/* Only event queue is checked. */ 2730/* Only event queue is checked. */
2731/* We don't have to call timer_check here
2732 because wait_reading_process_input takes care of that. */
2654int 2733int
2655sys_select (nfds, rfds, wfds, efds, timeout) 2734sys_select (nfds, rfds, wfds, efds, timeout)
2656 int nfds; 2735 int nfds;
@@ -2797,6 +2876,11 @@ abort ()
2797 dos_ttcooked (); 2876 dos_ttcooked ();
2798 ScreenSetCursor (10, 0); 2877 ScreenSetCursor (10, 0);
2799 cputs ("\r\n\nEmacs aborted!\r\n"); 2878 cputs ("\r\n\nEmacs aborted!\r\n");
2879#if __DJGPP__ > 1
2880 /* Generate traceback, so we could tell whodunit. */
2881 signal (SIGINT, SIG_DFL);
2882 __asm__ __volatile__ ("movb $0x1b,%al;call ___djgpp_hw_exception");
2883#endif
2800 exit (2); 2884 exit (2);
2801} 2885}
2802#endif 2886#endif