aboutsummaryrefslogtreecommitdiff
path: root/src/os_unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/os_unix.c')
-rw-r--r--src/os_unix.c280
1 files changed, 18 insertions, 262 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index 8dbd512726..856191ea95 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -28,11 +28,27 @@
# define select select_declared_wrong
#include "vim.h"
-
+#include "os_unix.h"
+#include "buffer.h"
+#include "charset.h"
+#include "eval.h"
+#include "ex_cmds.h"
+#include "fileio.h"
+#include "getchar.h"
+#include "main.h"
+#include "mbyte.h"
+#include "memline.h"
+#include "message.h"
+#include "misc1.h"
+#include "misc2.h"
+#include "screen.h"
+#include "syntax.h"
+#include "term.h"
+#include "ui.h"
+#include "os/os.h"
#include "os_unixx.h" /* unix includes for os_unix.c only */
-
#ifdef HAVE_SELINUX
# include <selinux/selinux.h>
static int selinux_enabled = -1;
@@ -221,16 +237,6 @@ static struct signalinfo {
{-1, "Unknown!", FALSE}
};
-int mch_chdir(char *path)
-{
- if (p_verbose >= 5) {
- verbose_enter();
- smsg((char_u *)"chdir(%s)", path);
- verbose_leave();
- }
- return chdir(path);
-}
-
/*
* Write s[len] to the screen.
*/
@@ -332,101 +338,6 @@ int mch_char_avail() {
return WaitForChar(0L);
}
-#if defined(HAVE_TOTAL_MEM) || defined(PROTO)
-# ifdef HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-# endif
-# if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTL)
-# include <sys/sysctl.h>
-# endif
-# if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)
-# include <sys/sysinfo.h>
-# endif
-
-/*
- * Return total amount of memory available in Kbyte.
- * Doesn't change when memory has been allocated.
- */
-long_u mch_total_mem(int special)
-{
- long_u mem = 0;
- long_u shiftright = 10; /* how much to shift "mem" right for Kbyte */
-
-# ifdef HAVE_SYSCTL
- int mib[2], physmem;
- size_t len;
-
- /* BSD way of getting the amount of RAM available. */
- mib[0] = CTL_HW;
- mib[1] = HW_USERMEM;
- len = sizeof(physmem);
- if (sysctl(mib, 2, &physmem, &len, NULL, 0) == 0)
- mem = (long_u)physmem;
-# endif
-
-# if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)
- if (mem == 0) {
- struct sysinfo sinfo;
-
- /* Linux way of getting amount of RAM available */
- if (sysinfo(&sinfo) == 0) {
-# ifdef HAVE_SYSINFO_MEM_UNIT
- /* avoid overflow as much as possible */
- while (shiftright > 0 && (sinfo.mem_unit & 1) == 0) {
- sinfo.mem_unit = sinfo.mem_unit >> 1;
- --shiftright;
- }
- mem = sinfo.totalram * sinfo.mem_unit;
-# else
- mem = sinfo.totalram;
-# endif
- }
- }
-# endif
-
-# ifdef HAVE_SYSCONF
- if (mem == 0) {
- long pagesize, pagecount;
-
- /* Solaris way of getting amount of RAM available */
- pagesize = sysconf(_SC_PAGESIZE);
- pagecount = sysconf(_SC_PHYS_PAGES);
- if (pagesize > 0 && pagecount > 0) {
- /* avoid overflow as much as possible */
- while (shiftright > 0 && (pagesize & 1) == 0) {
- pagesize = (long_u)pagesize >> 1;
- --shiftright;
- }
- mem = (long_u)pagesize * pagecount;
- }
- }
-# endif
-
- /* Return the minimum of the physical memory and the user limit, because
- * using more than the user limit may cause Vim to be terminated. */
-# if defined(HAVE_SYS_RESOURCE_H) && defined(HAVE_GETRLIMIT)
- {
- struct rlimit rlp;
-
- if (getrlimit(RLIMIT_DATA, &rlp) == 0
- && rlp.rlim_cur < ((rlim_t)1 << (sizeof(long_u) * 8 - 1))
-# ifdef RLIM_INFINITY
- && rlp.rlim_cur != RLIM_INFINITY
-# endif
- && ((long_u)rlp.rlim_cur >> 10) < (mem >> shiftright)
- ) {
- mem = (long_u)rlp.rlim_cur;
- shiftright = 10;
- }
- }
-# endif
-
- if (mem > 0)
- return mem >> shiftright;
- return (long_u)0x1fffff;
-}
-#endif
-
void mch_delay(long msec, int ignoreinput)
{
int old_tmode;
@@ -1333,161 +1244,6 @@ long mch_get_pid() {
return (long)getpid();
}
-#if !defined(HAVE_STRERROR) && defined(USE_GETCWD)
-static char *strerror __ARGS((int));
-
-static char * strerror(int err)
-{
- extern int sys_nerr;
- extern char *sys_errlist[];
- static char er[20];
-
- if (err > 0 && err < sys_nerr)
- return sys_errlist[err];
- sprintf(er, "Error %d", err);
- return er;
-}
-#endif
-
-/*
- * Get name of current directory into buffer 'buf' of length 'len' bytes.
- * Return OK for success, FAIL for failure.
- */
-int mch_dirname(char_u *buf, int len)
-{
-#if defined(USE_GETCWD)
- if (getcwd((char *)buf, len) == NULL) {
- STRCPY(buf, strerror(errno));
- return FAIL;
- }
- return OK;
-#else
- return getwd((char *)buf) != NULL ? OK : FAIL;
-#endif
-}
-
-
-/*
- * Get absolute file name into "buf[len]".
- *
- * return FAIL for failure, OK for success
- */
-int mch_FullName(
- char_u *fname,
- char_u *buf,
- int len,
- int force /* also expand when already absolute path */
- )
-{
- int l;
-#ifdef HAVE_FCHDIR
- int fd = -1;
- static int dont_fchdir = FALSE; /* TRUE when fchdir() doesn't work */
-#endif
- char_u olddir[MAXPATHL];
- char_u *p;
- int retval = OK;
-
-
-
- /* expand it if forced or not an absolute path */
- if (force || !mch_isFullName(fname)) {
- /*
- * If the file name has a path, change to that directory for a moment,
- * and then do the getwd() (and get back to where we were).
- * This will get the correct path name with "../" things.
- */
- if ((p = vim_strrchr(fname, '/')) != NULL) {
-#ifdef HAVE_FCHDIR
- /*
- * Use fchdir() if possible, it's said to be faster and more
- * reliable. But on SunOS 4 it might not work. Check this by
- * doing a fchdir() right now.
- */
- if (!dont_fchdir) {
- fd = open(".", O_RDONLY | O_EXTRA, 0);
- if (fd >= 0 && fchdir(fd) < 0) {
- close(fd);
- fd = -1;
- dont_fchdir = TRUE; /* don't try again */
- }
- }
-#endif
-
- /* Only change directory when we are sure we can return to where
- * we are now. After doing "su" chdir(".") might not work. */
- if (
-#ifdef HAVE_FCHDIR
- fd < 0 &&
-#endif
- (mch_dirname(olddir, MAXPATHL) == FAIL
- || mch_chdir((char *)olddir) != 0)) {
- p = NULL; /* can't get current dir: don't chdir */
- retval = FAIL;
- } else {
- /* The directory is copied into buf[], to be able to remove
- * the file name without changing it (could be a string in
- * read-only memory) */
- if (p - fname >= len)
- retval = FAIL;
- else {
- vim_strncpy(buf, fname, p - fname);
- if (mch_chdir((char *)buf))
- retval = FAIL;
- else
- fname = p + 1;
- *buf = NUL;
- }
- }
- }
- if (mch_dirname(buf, len) == FAIL) {
- retval = FAIL;
- *buf = NUL;
- }
- if (p != NULL) {
-#ifdef HAVE_FCHDIR
- if (fd >= 0) {
- if (p_verbose >= 5) {
- verbose_enter();
- MSG("fchdir() to previous dir");
- verbose_leave();
- }
- l = fchdir(fd);
- close(fd);
- } else
-#endif
- l = mch_chdir((char *)olddir);
- if (l != 0)
- EMSG(_(e_prev_dir));
- }
-
- l = STRLEN(buf);
- if (l >= len - 1)
- retval = FAIL; /* no space for trailing "/" */
- else if (l > 0 && buf[l - 1] != '/' && *fname != NUL
- && STRCMP(fname, ".") != 0)
- STRCAT(buf, "/");
- }
-
- /* Catch file names which are too long. */
- if (retval == FAIL || (int)(STRLEN(buf) + STRLEN(fname)) >= len)
- return FAIL;
-
- /* Do not append ".", "/dir/." is equal to "/dir". */
- if (STRCMP(fname, ".") != 0)
- STRCAT(buf, fname);
-
- return OK;
-}
-
-/*
- * Return TRUE if "fname" does not depend on the current directory.
- */
-int mch_isFullName(char_u *fname)
-{
- return *fname == '/' || *fname == '~';
-}
-
#if defined(USE_FNAME_CASE) || defined(PROTO)
/*
* Set the case of the file name, if it already exists. This will cause the