Mercurial > emacs
comparison src/msdos.c @ 14999:3bafb8029b86
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.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 12 Apr 1996 06:04:10 +0000 |
parents | b99490300747 |
children | 9e174c2b4ba6 |
comparison
equal
deleted
inserted
replaced
14998:ffbd85603f91 | 14999:3bafb8029b86 |
---|---|
50 /* #include <process.h> */ | 50 /* #include <process.h> */ |
51 /* Damn that local process.h! Instead we can define P_WAIT ourselves. */ | 51 /* Damn that local process.h! Instead we can define P_WAIT ourselves. */ |
52 #define P_WAIT 1 | 52 #define P_WAIT 1 |
53 | 53 |
54 #if __DJGPP__ > 1 | 54 #if __DJGPP__ > 1 |
55 | |
56 #include <signal.h> | |
55 | 57 |
56 #ifndef SYSTEM_MALLOC | 58 #ifndef SYSTEM_MALLOC |
57 | 59 |
58 #ifdef GNU_MALLOC | 60 #ifdef GNU_MALLOC |
59 | 61 |
2123 } | 2125 } |
2124 if (buf < endp) | 2126 if (buf < endp) |
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 | |
2144 static char xbuf[64 * 1024]; /* DOS cannot write more in one chunk */ | |
2145 | |
2146 #define XBUF_END (xbuf + sizeof (xbuf) - 1) | |
2147 | |
2148 int | |
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 |
2131 static char emacsroot[MAXPATHLEN]; | 2208 static char emacsroot[MAXPATHLEN]; |
2132 | 2209 |
2649 && (long)(time).tv_usec <= 0)) | 2726 && (long)(time).tv_usec <= 0)) |
2650 #endif | 2727 #endif |
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. */ | |
2654 int | 2733 int |
2655 sys_select (nfds, rfds, wfds, efds, timeout) | 2734 sys_select (nfds, rfds, wfds, efds, timeout) |
2656 int nfds; | 2735 int nfds; |
2657 SELECT_TYPE *rfds, *wfds, *efds; | 2736 SELECT_TYPE *rfds, *wfds, *efds; |
2658 EMACS_TIME *timeout; | 2737 EMACS_TIME *timeout; |
2795 abort () | 2874 abort () |
2796 { | 2875 { |
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 |
2803 | 2887 |
2804 syms_of_msdos () | 2888 syms_of_msdos () |