diff --git a/vfs/ChangeLog b/vfs/ChangeLog index d0a72f75e..856cd0e5c 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,5 +1,8 @@ 2003-06-05 Pavel Roskin <proski@gnu.org> + * vfs.c: Rename mc_return_cwd() to _vfs_get_cwd(). Move + related functions closer to each other, add comments. + * ftpfs.c (ftpfs_done): New function. Free ftpfs_proxy_host and ftpfs_anonymous_passwd. diff --git a/vfs/vfs.c b/vfs/vfs.c index 59343096f..c2f0c57f0 100644 --- a/vfs/vfs.c +++ b/vfs/vfs.c @@ -603,45 +603,68 @@ int mc_fstat (int handle, struct stat *buf) { } /* - * You must g_strdup whatever this function returns. + * Return current directory. If it's local, reread the current directory + * from the OS. You must g_strdup whatever this function returns. */ - static const char * -mc_return_cwd (void) +_vfs_get_cwd (void) { char *p; struct stat my_stat, my_stat2; - if (!vfs_rosplit (current_dir)){ + if (!vfs_rosplit (current_dir)) { p = g_get_current_dir (); - if (!p) /* One of the directories in the path is not readable */ + if (!p) /* One of the directories in the path is not readable */ return current_dir; /* Otherwise check if it is O.K. to use the current_dir */ - if (!cd_symlinks || - mc_stat (p, &my_stat) || - mc_stat (current_dir, &my_stat2) || - my_stat.st_ino != my_stat2.st_ino || - my_stat.st_dev != my_stat2.st_dev){ + if (!cd_symlinks || mc_stat (p, &my_stat) + || mc_stat (current_dir, &my_stat2) + || my_stat.st_ino != my_stat2.st_ino + || my_stat.st_dev != my_stat2.st_dev) { g_free (current_dir); current_dir = p; return p; - } /* Otherwise we return current_dir below */ + } /* Otherwise we return current_dir below */ g_free (p); - } + } return current_dir; } +static void +vfs_setup_wd (void) +{ + current_dir = g_strdup (PATH_SEP_STR); + if (!(vfs_flags & FL_NO_CWDSETUP)) + _vfs_get_cwd (); + + if (strlen (current_dir) > MC_MAXPATHLEN - 2) + vfs_die ("Current dir too long.\n"); +} + +/* + * Return current directory. If it's local, reread the current directory + * from the OS. Put directory to the provided buffer. + */ char * mc_get_current_wd (char *buffer, int size) { - const char *cwd = mc_return_cwd(); + const char *cwd = _vfs_get_cwd (); strncpy (buffer, cwd, size - 1); - buffer [size - 1] = 0; + buffer[size - 1] = 0; return buffer; } +/* + * Return current directory without any OS calls. + */ +char * +vfs_get_current_dir (void) +{ + return current_dir; +} + MC_NAMEOP (chmod, (char *path, int mode), (vfs, path, mode)) MC_NAMEOP (chown, (char *path, int owner, int group), (vfs, path, owner, group)) MC_NAMEOP (utime, (char *path, struct utimbuf *times), (vfs, path, times)) @@ -975,21 +998,6 @@ vfs_file_is_smb (char *filename) return 0; } -char *vfs_get_current_dir (void) -{ - return current_dir; -} - -static void vfs_setup_wd (void) -{ - current_dir = g_strdup (PATH_SEP_STR); - if (!(vfs_flags & FL_NO_CWDSETUP)) - mc_return_cwd(); - - if (strlen(current_dir)>MC_MAXPATHLEN-2) - vfs_die ("Current dir too long.\n"); -} - MC_NAMEOP (mkdir, (char *path, mode_t mode), (vfs, path, mode)) MC_NAMEOP (rmdir, (char *path), (vfs, path)) MC_NAMEOP (mknod, (char *path, int mode, int dev), (vfs, path, mode, dev))