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.c173
1 files changed, 17 insertions, 156 deletions
diff --git a/src/os_unix.c b/src/os_unix.c
index f65b285ba7..856191ea95 100644
--- a/src/os_unix.c
+++ b/src/os_unix.c
@@ -28,9 +28,25 @@
# 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
@@ -1228,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