Mercurial > vim
comparison src/os_unix.h @ 7:3fc0f57ecb91 v7.0001
updated for version 7.0001
author | vimboss |
---|---|
date | Sun, 13 Jun 2004 20:20:40 +0000 |
parents | |
children | c10855f07ab0 |
comparison
equal
deleted
inserted
replaced
6:c2daee826b8f | 7:3fc0f57ecb91 |
---|---|
1 /* vi:set ts=8 sts=4 sw=4: | |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 */ | |
8 | |
9 /* | |
10 * NextStep has a problem with configure, undefine a few things: | |
11 */ | |
12 #ifdef NeXT | |
13 # ifdef HAVE_UTIME | |
14 # undef HAVE_UTIME | |
15 # endif | |
16 # ifdef HAVE_SYS_UTSNAME_H | |
17 # undef HAVE_SYS_UTSNAME_H | |
18 # endif | |
19 #endif | |
20 | |
21 #include <stdio.h> | |
22 #include <ctype.h> | |
23 | |
24 #ifdef VAXC | |
25 # include <types.h> | |
26 # include <stat.h> | |
27 #else | |
28 # include <sys/types.h> | |
29 # include <sys/stat.h> | |
30 #endif | |
31 | |
32 #ifdef HAVE_STDLIB_H | |
33 # include <stdlib.h> | |
34 #endif | |
35 | |
36 #ifdef __EMX__ | |
37 # define HAVE_TOTAL_MEM | |
38 #endif | |
39 | |
40 #if defined(__CYGWIN__) || defined(__CYGWIN32__) | |
41 # define WIN32UNIX /* Compiling for Win32 using Unix files. */ | |
42 # define BINARY_FILE_IO | |
43 #endif | |
44 | |
45 /* On AIX 4.2 there is a conflicting prototype for ioctl() in stropts.h and | |
46 * unistd.h. This hack should fix that (suggested by Jeff George). | |
47 * But on AIX 4.3 it's alright (suggested by Jake Hamby). */ | |
48 #if defined(FEAT_GUI) && defined(_AIX) && !defined(_AIX43) && !defined(_NO_PROTO) | |
49 # define _NO_PROTO | |
50 #endif | |
51 | |
52 #ifdef HAVE_UNISTD_H | |
53 # include <unistd.h> | |
54 #endif | |
55 | |
56 #ifdef HAVE_LIBC_H | |
57 # include <libc.h> /* for NeXT */ | |
58 #endif | |
59 | |
60 #ifdef HAVE_SYS_PARAM_H | |
61 # include <sys/param.h> /* defines BSD, if it's a BSD system */ | |
62 #endif | |
63 | |
64 /* | |
65 * Sun defines FILE on SunOS 4.x.x, Solaris has a typedef for FILE | |
66 */ | |
67 #if defined(sun) && !defined(FILE) | |
68 # define SOLARIS | |
69 #endif | |
70 | |
71 /* | |
72 * Using getcwd() is preferred, because it checks for a buffer overflow. | |
73 * Don't use getcwd() on systems do use system("sh -c pwd"). There is an | |
74 * autoconf check for this. | |
75 * Use getcwd() anyway if getwd() isn't present. | |
76 */ | |
77 #if defined(HAVE_GETCWD) && !(defined(BAD_GETCWD) && defined(HAVE_GETWD)) | |
78 # define USE_GETCWD | |
79 #endif | |
80 | |
81 #ifndef __ARGS | |
82 /* The AIX VisualAge cc compiler defines __EXTENDED__ instead of __STDC__ | |
83 * because it includes pre-ansi features. */ | |
84 # if defined(__STDC__) || defined(__GNUC__) || defined(__EXTENDED__) | |
85 # define __ARGS(x) x | |
86 # else | |
87 # define __ARGS(x) () | |
88 # endif | |
89 #endif | |
90 | |
91 /* always use unlink() to remove files */ | |
92 #ifndef PROTO | |
93 # ifdef VMS | |
94 # define mch_remove(x) delete((char *)(x)) | |
95 # define vim_mkdir(x, y) mkdir((char *)(x), y) | |
96 # ifdef VAX | |
97 # else | |
98 # define mch_rmdir(x) rmdir((char *)(x)) | |
99 # endif | |
100 # else | |
101 # define vim_mkdir(x, y) mkdir((char *)(x), y) | |
102 # define mch_rmdir(x) rmdir((char *)(x)) | |
103 # define mch_remove(x) unlink((char *)(x)) | |
104 # endif | |
105 #endif | |
106 | |
107 /* The number of arguments to a signal handler is configured here. */ | |
108 /* It used to be a long list of almost all systems. Any system that doesn't | |
109 * have an argument??? */ | |
110 #define SIGHASARG | |
111 | |
112 /* List 3 arg systems here. I guess __sgi, please test and correct me. jw. */ | |
113 #if defined(__sgi) && defined(HAVE_SIGCONTEXT) | |
114 # define SIGHAS3ARGS | |
115 #endif | |
116 | |
117 #ifdef SIGHASARG | |
118 # ifdef SIGHAS3ARGS | |
119 # define SIGPROTOARG (int, int, struct sigcontext *) | |
120 # define SIGDEFARG(s) (s, sig2, scont) int s, sig2; struct sigcontext *scont; | |
121 # define SIGDUMMYARG 0, 0, (struct sigcontext *)0 | |
122 # else | |
123 # define SIGPROTOARG (int) | |
124 # define SIGDEFARG(s) (s) int s; | |
125 # define SIGDUMMYARG 0 | |
126 # endif | |
127 #else | |
128 # define SIGPROTOARG (void) | |
129 # define SIGDEFARG(s) () | |
130 # define SIGDUMMYARG | |
131 #endif | |
132 | |
133 #ifdef HAVE_DIRENT_H | |
134 # include <dirent.h> | |
135 # ifndef NAMLEN | |
136 # define NAMLEN(dirent) strlen((dirent)->d_name) | |
137 # endif | |
138 #else | |
139 # define dirent direct | |
140 # define NAMLEN(dirent) (dirent)->d_namlen | |
141 # if HAVE_SYS_NDIR_H | |
142 # include <sys/ndir.h> | |
143 # endif | |
144 # if HAVE_SYS_DIR_H | |
145 # include <sys/dir.h> | |
146 # endif | |
147 # if HAVE_NDIR_H | |
148 # include <ndir.h> | |
149 # endif | |
150 #endif | |
151 | |
152 #if !defined(HAVE_SYS_TIME_H) || defined(TIME_WITH_SYS_TIME) | |
153 # include <time.h> /* on some systems time.h should not be | |
154 included together with sys/time.h */ | |
155 #endif | |
156 #ifdef HAVE_SYS_TIME_H | |
157 # include <sys/time.h> | |
158 #endif | |
159 | |
160 #include <signal.h> | |
161 | |
162 #if defined(DIRSIZ) && !defined(MAXNAMLEN) | |
163 # define MAXNAMLEN DIRSIZ | |
164 #endif | |
165 | |
166 #if defined(UFS_MAXNAMLEN) && !defined(MAXNAMLEN) | |
167 # define MAXNAMLEN UFS_MAXNAMLEN /* for dynix/ptx */ | |
168 #endif | |
169 | |
170 #if defined(NAME_MAX) && !defined(MAXNAMLEN) | |
171 # define MAXNAMLEN NAME_MAX /* for Linux before .99p3 */ | |
172 #endif | |
173 | |
174 /* | |
175 * Note: if MAXNAMLEN has the wrong value, you will get error messages | |
176 * for not being able to open the swap file. | |
177 */ | |
178 #if !defined(MAXNAMLEN) | |
179 # define MAXNAMLEN 512 /* for all other Unix */ | |
180 #endif | |
181 | |
182 #define BASENAMELEN (MAXNAMLEN - 5) | |
183 | |
184 #ifdef HAVE_ERRNO_H | |
185 # include <errno.h> | |
186 #endif | |
187 | |
188 #ifdef HAVE_PWD_H | |
189 # include <pwd.h> | |
190 #endif | |
191 | |
192 #ifdef __COHERENT__ | |
193 # undef __ARGS | |
194 #endif | |
195 | |
196 #if (defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)) \ | |
197 || (defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)) \ | |
198 || defined(HAVE_SYSCTL) || defined(HAVE_SYSCONF) | |
199 # define HAVE_TOTAL_MEM | |
200 #endif | |
201 | |
202 #ifdef VMS | |
203 #include <unixio.h> | |
204 #include <unixlib.h> | |
205 #include <signal.h> | |
206 #include <file.h> | |
207 #include <ssdef.h> | |
208 #include <descrip.h> | |
209 #include <libclidef.h> | |
210 #include <lnmdef.h> | |
211 #include <psldef.h> | |
212 #include <prvdef.h> | |
213 #include <dvidef.h> | |
214 #include <dcdef.h> | |
215 #include <stsdef.h> | |
216 #include <iodef.h> | |
217 #include <ttdef.h> | |
218 #include <tt2def.h> | |
219 #include <jpidef.h> | |
220 #include <rms.h> | |
221 #include <trmdef.h> | |
222 #include <string.h> | |
223 #include <starlet.h> | |
224 #include <socket.h> | |
225 #include <lib$routines.h> | |
226 | |
227 typedef struct dsc$descriptor DESC; | |
228 #endif | |
229 | |
230 /* | |
231 * Unix system-dependent file names | |
232 */ | |
233 #ifndef SYS_VIMRC_FILE | |
234 # define SYS_VIMRC_FILE "$VIM/vimrc" | |
235 #endif | |
236 #ifndef SYS_GVIMRC_FILE | |
237 # define SYS_GVIMRC_FILE "$VIM/gvimrc" | |
238 #endif | |
239 #ifndef DFLT_HELPFILE | |
240 # define DFLT_HELPFILE "$VIMRUNTIME/doc/help.txt" | |
241 #endif | |
242 #ifndef FILETYPE_FILE | |
243 # define FILETYPE_FILE "filetype.vim" | |
244 #endif | |
245 #ifndef FTPLUGIN_FILE | |
246 # define FTPLUGIN_FILE "ftplugin.vim" | |
247 #endif | |
248 #ifndef INDENT_FILE | |
249 # define INDENT_FILE "indent.vim" | |
250 #endif | |
251 #ifndef FTOFF_FILE | |
252 # define FTOFF_FILE "ftoff.vim" | |
253 #endif | |
254 #ifndef FTPLUGOF_FILE | |
255 # define FTPLUGOF_FILE "ftplugof.vim" | |
256 #endif | |
257 #ifndef INDOFF_FILE | |
258 # define INDOFF_FILE "indoff.vim" | |
259 #endif | |
260 #ifndef SYS_MENU_FILE | |
261 # define SYS_MENU_FILE "$VIMRUNTIME/menu.vim" | |
262 #endif | |
263 | |
264 #ifndef USR_EXRC_FILE | |
265 # ifdef VMS | |
266 # define USR_EXRC_FILE "sys$login:.exrc" | |
267 # else | |
268 # define USR_EXRC_FILE "$HOME/.exrc" | |
269 # endif | |
270 #endif | |
271 | |
272 #if !defined(USR_EXRC_FILE2) && defined(OS2) | |
273 # define USR_EXRC_FILE2 "$VIM/.exrc" | |
274 #endif | |
275 #if !defined(USR_EXRC_FILE2) && defined(VMS) | |
276 # define USR_EXRC_FILE2 "sys$login:_exrc" | |
277 #endif | |
278 | |
279 #ifndef USR_VIMRC_FILE | |
280 # ifdef VMS | |
281 # define USR_VIMRC_FILE "sys$login:.vimrc" | |
282 # else | |
283 # define USR_VIMRC_FILE "$HOME/.vimrc" | |
284 # endif | |
285 #endif | |
286 | |
287 #if !defined(USR_VIMRC_FILE2) && defined(OS2) | |
288 # define USR_VIMRC_FILE2 "$VIM/.vimrc" | |
289 #endif | |
290 #if !defined(USR_VIMRC_FILE2) && defined(VMS) | |
291 # define USR_VIMRC_FILE2 "sys$login:_vimrc" | |
292 #endif | |
293 | |
294 #ifndef USR_GVIMRC_FILE | |
295 # ifdef VMS | |
296 # define USR_GVIMRC_FILE "sys$login:.gvimrc" | |
297 # else | |
298 # define USR_GVIMRC_FILE "$HOME/.gvimrc" | |
299 # endif | |
300 #endif | |
301 | |
302 #ifdef VMS | |
303 # ifndef USR_GVIMRC_FILE2 | |
304 # define USR_GVIMRC_FILE2 "sys$login:_gvimrc" | |
305 # endif | |
306 #endif | |
307 | |
308 #ifndef EVIM_FILE | |
309 # define EVIM_FILE "$VIMRUNTIME/evim.vim" | |
310 #endif | |
311 | |
312 #ifdef FEAT_VIMINFO | |
313 # ifndef VIMINFO_FILE | |
314 # ifdef VMS | |
315 # define VIMINFO_FILE "sys$login:.viminfo" | |
316 # else | |
317 # define VIMINFO_FILE "$HOME/.viminfo" | |
318 # endif | |
319 # endif | |
320 # if !defined(VIMINFO_FILE2) && defined(OS2) | |
321 # define VIMINFO_FILE2 "$VIM/.viminfo" | |
322 # endif | |
323 # if !defined(VIMINFO_FILE2) && defined(VMS) | |
324 # define VIMINFO_FILE2 "sys$login:_viminfo" | |
325 # endif | |
326 #endif | |
327 | |
328 #ifndef EXRC_FILE | |
329 # define EXRC_FILE ".exrc" | |
330 #endif | |
331 | |
332 #ifndef VIMRC_FILE | |
333 # define VIMRC_FILE ".vimrc" | |
334 #endif | |
335 | |
336 #ifdef FEAT_GUI | |
337 # ifndef GVIMRC_FILE | |
338 # define GVIMRC_FILE ".gvimrc" | |
339 # endif | |
340 #endif | |
341 | |
342 #ifndef SYNTAX_FNAME | |
343 # define SYNTAX_FNAME "$VIMRUNTIME/syntax/%s.vim" | |
344 #endif | |
345 | |
346 #ifndef DFLT_BDIR | |
347 # ifdef OS2 | |
348 # define DFLT_BDIR ".,c:/tmp,~/tmp,~/" | |
349 # else | |
350 # ifdef VMS | |
351 # define DFLT_BDIR "./,sys$login:,tmp:" | |
352 # else | |
353 # define DFLT_BDIR ".,~/tmp,~/" /* default for 'backupdir' */ | |
354 # endif | |
355 # endif | |
356 #endif | |
357 | |
358 #ifndef DFLT_DIR | |
359 # ifdef OS2 | |
360 # define DFLT_DIR ".,~/tmp,c:/tmp,/tmp" | |
361 # else | |
362 # ifdef VMS | |
363 # define DFLT_DIR "./,sys$login:,tmp:" | |
364 # else | |
365 # define DFLT_DIR ".,~/tmp,/var/tmp,/tmp" /* default for 'directory' */ | |
366 # endif | |
367 # endif | |
368 #endif | |
369 | |
370 #ifndef DFLT_VDIR | |
371 # ifdef OS2 | |
372 # define DFLT_VDIR "$VIM/vimfiles/view" | |
373 # else | |
374 # ifdef VMS | |
375 # define DFLT_VDIR "sys$login:vimfiles/view" | |
376 # else | |
377 # define DFLT_VDIR "$HOME/.vim/view" /* default for 'viewdir' */ | |
378 # endif | |
379 # endif | |
380 #endif | |
381 | |
382 #define DFLT_ERRORFILE "errors.err" | |
383 | |
384 #ifdef OS2 | |
385 # define DFLT_RUNTIMEPATH "$HOME/vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/vimfiles/after" | |
386 #else | |
387 # ifdef VMS | |
388 # define DFLT_RUNTIMEPATH "sys$login:vimfiles,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,sys$login:vimfiles/after" | |
389 # else | |
390 # ifdef RUNTIME_GLOBAL | |
391 # define DFLT_RUNTIMEPATH "~/.vim," RUNTIME_GLOBAL ",$VIMRUNTIME," RUNTIME_GLOBAL "/after,~/.vim/after" | |
392 # else | |
393 # define DFLT_RUNTIMEPATH "~/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,~/.vim/after" | |
394 # endif | |
395 # endif | |
396 #endif | |
397 | |
398 #ifdef OS2 | |
399 /* | |
400 * Try several directories to put the temp files. | |
401 */ | |
402 # define TEMPDIRNAMES "$TMP", "$TEMP", "c:\\TMP", "c:\\TEMP", "" | |
403 # define TEMPNAMELEN 128 | |
404 #else | |
405 # ifdef VMS | |
406 # ifndef VAX | |
407 # define VMS_TEMPNAM /* to fix default .LIS extension */ | |
408 # endif | |
409 # define TEMPNAME "TMP:v?XXXXXX.txt" | |
410 # define TEMPNAMELEN 28 | |
411 # else | |
412 # define TEMPDIRNAMES "$TMPDIR", "/tmp", ".", "$HOME" | |
413 # define TEMPNAMELEN 256 | |
414 # endif | |
415 #endif | |
416 | |
417 /* Special wildcards that need to be handled by the shell */ | |
418 #define SPECIAL_WILDCHAR "`'{" | |
419 | |
420 #ifndef HAVE_OPENDIR | |
421 # define NO_EXPANDPATH | |
422 #endif | |
423 | |
424 /* | |
425 * Unix has plenty of memory, use large buffers | |
426 */ | |
427 #define CMDBUFFSIZE 1024 /* size of the command processing buffer */ | |
428 #define MAXPATHL 1024 /* Unix has long paths and plenty of memory */ | |
429 | |
430 #define CHECK_INODE /* used when checking if a swap file already | |
431 exists for a file */ | |
432 #ifdef VMS /* Use less memory because of older systems */ | |
433 # ifndef DFLT_MAXMEM | |
434 # define DFLT_MAXMEM (2*1024) | |
435 # endif | |
436 # ifndef DFLT_MAXMEMTOT | |
437 # define DFLT_MAXMEMTOT (5*1024) | |
438 # endif | |
439 #else | |
440 # ifndef DFLT_MAXMEM | |
441 # define DFLT_MAXMEM (5*1024) /* use up to 5 Mbyte for a buffer */ | |
442 # endif | |
443 # ifndef DFLT_MAXMEMTOT | |
444 # define DFLT_MAXMEMTOT (10*1024) /* use up to 10 Mbyte for Vim */ | |
445 # endif | |
446 #endif | |
447 | |
448 /* memmove is not present on all systems, use memmove, bcopy, memcpy or our | |
449 * own version */ | |
450 /* Some systems have (void *) arguments, some (char *). If we use (char *) it | |
451 * works for all */ | |
452 #ifdef USEMEMMOVE | |
453 # define mch_memmove(to, from, len) memmove((char *)(to), (char *)(from), len) | |
454 #else | |
455 # ifdef USEBCOPY | |
456 # define mch_memmove(to, from, len) bcopy((char *)(from), (char *)(to), len) | |
457 # else | |
458 # ifdef USEMEMCPY | |
459 # define mch_memmove(to, from, len) memcpy((char *)(to), (char *)(from), len) | |
460 # else | |
461 # define VIM_MEMMOVE /* found in misc2.c */ | |
462 # endif | |
463 # endif | |
464 #endif | |
465 | |
466 #ifndef PROTO | |
467 # ifdef HAVE_RENAME | |
468 # define mch_rename(src, dst) rename(src, dst) | |
469 # else | |
470 int mch_rename __ARGS((const char *src, const char *dest)); | |
471 # endif | |
472 # ifdef VMS | |
473 # define mch_chdir(s) chdir(vms_fixfilename(s)) | |
474 # else | |
475 # define mch_chdir(s) chdir(s) | |
476 # endif | |
477 # ifndef VMS | |
478 # ifdef __MVS__ | |
479 /* on OS390 Unix getenv() doesn't return a pointer to persistant | |
480 * storage -> use __getenv() */ | |
481 # define mch_getenv(x) (char_u *)__getenv((char *)(x)) | |
482 # else | |
483 # define mch_getenv(x) (char_u *)getenv((char *)(x)) | |
484 # endif | |
485 # define mch_setenv(name, val, x) setenv(name, val, x) | |
486 # endif | |
487 #endif | |
488 | |
489 #if !defined(S_ISDIR) && defined(S_IFDIR) | |
490 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) | |
491 #endif | |
492 #if !defined(S_ISREG) && defined(S_IFREG) | |
493 # define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) | |
494 #endif | |
495 #if !defined(S_ISBLK) && defined(S_IFBLK) | |
496 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) | |
497 #endif | |
498 #if !defined(S_ISSOCK) && defined(S_IFSOCK) | |
499 # define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) | |
500 #endif | |
501 #if !defined(S_ISFIFO) && defined(S_IFIFO) | |
502 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) | |
503 #endif | |
504 | |
505 /* Note: Some systems need both string.h and strings.h (Savage). However, | |
506 * some systems can't handle both, only use string.h in that case. */ | |
507 #ifdef HAVE_STRING_H | |
508 # include <string.h> | |
509 #endif | |
510 #if defined(HAVE_STRINGS_H) && !defined(NO_STRINGS_WITH_STRING_H) | |
511 # include <strings.h> | |
512 #endif | |
513 | |
514 #if defined(HAVE_SETJMP_H) | |
515 # include <setjmp.h> | |
516 # ifdef HAVE_SIGSETJMP | |
517 # define JMP_BUF sigjmp_buf | |
518 # define SETJMP(x) sigsetjmp((x), 1) | |
519 # define LONGJMP siglongjmp | |
520 # else | |
521 # define JMP_BUF jmp_buf | |
522 # define SETJMP(x) setjmp(x) | |
523 # define LONGJMP longjmp | |
524 # endif | |
525 #endif | |
526 | |
527 #define HAVE_DUP /* have dup() */ | |
528 #define HAVE_ST_MODE /* have stat.st_mode */ | |
529 | |
530 /* We have three kinds of ACL support. */ | |
531 #define HAVE_ACL (HAVE_POSIX_ACL || HAVE_SOLARIS_ACL || HAVE_AIX_ACL) |