diff --git a/vfs/ChangeLog b/vfs/ChangeLog index f10d5b5bd..b38d99f59 100644 --- a/vfs/ChangeLog +++ b/vfs/ChangeLog @@ -1,5 +1,11 @@ 2003-11-13 Pavel Roskin + * vfs.h: Constify chdir() and opendir() methods. Adjust all + dependencies. + * vfs.c (mc_chdir): Constify, eliminate protection against + broken implementations of chdir() method. + (mc_opendir): Constify. + * direntry.c (vfs_s_stamp_me): Generalize and move ... * gc.c (vfs_stamp_create): ... here. Use whenever possible. diff --git a/vfs/direntry.c b/vfs/direntry.c index 7304a10d6..e1323e599 100644 --- a/vfs/direntry.c +++ b/vfs/direntry.c @@ -561,7 +561,7 @@ struct dirhandle { }; static void * -vfs_s_opendir (struct vfs_class *me, char *dirname) +vfs_s_opendir (struct vfs_class *me, const char *dirname) { struct vfs_s_inode *dir; struct dirhandle *info; @@ -618,7 +618,7 @@ vfs_s_closedir (void *data) } static int -vfs_s_chdir (struct vfs_class *me, char *path) +vfs_s_chdir (struct vfs_class *me, const char *path) { void *data; if (!(data = vfs_s_opendir (me, path))) diff --git a/vfs/extfs.c b/vfs/extfs.c index 05e31bcff..2879622bc 100644 --- a/vfs/extfs.c +++ b/vfs/extfs.c @@ -854,7 +854,7 @@ static int extfs_errno (struct vfs_class *me) return my_errno; } -static void * extfs_opendir (struct vfs_class *me, char *dirname) +static void * extfs_opendir (struct vfs_class *me, const char *dirname) { struct archive *archive; char *q; @@ -1071,7 +1071,7 @@ static int extfs_rmdir (struct vfs_class *me, char *path) return 0; } -static int extfs_chdir (struct vfs_class *me, char *path) +static int extfs_chdir (struct vfs_class *me, const char *path) { struct archive *archive; char *q; diff --git a/vfs/local.c b/vfs/local.c index 8e55d65d0..7a7b5a9fc 100644 --- a/vfs/local.c +++ b/vfs/local.c @@ -74,7 +74,7 @@ local_errno (struct vfs_class *me) } static void * -local_opendir (struct vfs_class *me, char *dirname) +local_opendir (struct vfs_class *me, const char *dirname) { DIR **local_info; DIR *dir; @@ -193,7 +193,7 @@ local_rename (struct vfs_class *me, char *a, char *b) } static int -local_chdir (struct vfs_class *me, char *path) +local_chdir (struct vfs_class *me, const char *path) { return chdir (path); } diff --git a/vfs/mcfs.c b/vfs/mcfs.c index cb2be4592..5a445422a 100644 --- a/vfs/mcfs.c +++ b/vfs/mcfs.c @@ -629,7 +629,7 @@ typedef struct { } opendir_info; static void * -mcfs_opendir (struct vfs_class *me, char *dirname) +mcfs_opendir (struct vfs_class *me, const char *dirname) { opendir_info *mcfs_info; mcfs_connection *mc; @@ -1011,7 +1011,7 @@ mcfs_rename (struct vfs_class *me, char *a, char *b) } static int -mcfs_chdir (struct vfs_class *me, char *path) +mcfs_chdir (struct vfs_class *me, const char *path) { char *remote_dir; mcfs_connection *mc; diff --git a/vfs/smbfs.c b/vfs/smbfs.c index caf6d329a..f35334904 100644 --- a/vfs/smbfs.c +++ b/vfs/smbfs.c @@ -1187,7 +1187,7 @@ is_error (int result, int errno_num) #endif static void * -smbfs_opendir (struct vfs_class *me, char *dirname) +smbfs_opendir (struct vfs_class *me, const char *dirname) { opendir_info *smbfs_info; smbfs_connection *sc; @@ -1436,16 +1436,16 @@ smbfs_get_stat_info (smbfs_connection * sc, char *path, struct stat *buf) } static int -smbfs_chdir (struct vfs_class *me, char *path) +smbfs_chdir (struct vfs_class *me, const char *path) { - char *remote_dir; - smbfs_connection *sc; - - DEBUG(3, ("smbfs_chdir(path:%s)\n", path)); + char *remote_dir; + smbfs_connection *sc; + + DEBUG (3, ("smbfs_chdir(path:%s)\n", path)); if (!(remote_dir = smbfs_get_path (&sc, path))) - return -1; + return -1; g_free (remote_dir); - + return 0; } diff --git a/vfs/vfs.c b/vfs/vfs.c index c54a80063..e39eb64e0 100644 --- a/vfs/vfs.c +++ b/vfs/vfs.c @@ -453,17 +453,18 @@ mc_close (int handle) } DIR * -mc_opendir (char *dirname) +mc_opendir (const char *dirname) { int handle, *handlep; void *info; struct vfs_class *vfs; + char *dname; - dirname = vfs_canon (dirname); - vfs = vfs_get_class (dirname); + dname = vfs_canon (dirname); + vfs = vfs_get_class (dname); - info = vfs->opendir ? (*vfs->opendir)(vfs, dirname) : NULL; - g_free (dirname); + info = vfs->opendir ? (*vfs->opendir)(vfs, dname) : NULL; + g_free (dname); if (!info){ errno = vfs->opendir ? ferrno (vfs) : E_NOTSUPP; return NULL; @@ -663,9 +664,9 @@ vfs_canon (const char *path) * Return 0 on success, -1 on failure. */ int -mc_chdir (char *path) +mc_chdir (const char *path) { - char *new_dir, *new_dir_copy; + char *new_dir; struct vfs_class *old_vfs, *new_vfs; vfsid old_vfsid; struct vfs_stamping *parent; @@ -676,10 +677,7 @@ mc_chdir (char *path) if (!new_vfs->chdir) return -1; - /* new_vfs->chdir can write to the second argument, use a copy */ - new_dir_copy = g_strdup (new_dir); - result = (*new_vfs->chdir) (new_vfs, new_dir_copy); - g_free (new_dir_copy); + result = (*new_vfs->chdir) (new_vfs, new_dir); if (result == -1) { errno = ferrno (new_vfs); diff --git a/vfs/vfs.h b/vfs/vfs.h index 9b988647e..6be317e1c 100644 --- a/vfs/vfs.h +++ b/vfs/vfs.h @@ -33,7 +33,7 @@ struct vfs_class { int (*read) (void *vfs_info, char *buffer, int count); int (*write) (void *vfs_info, char *buf, int count); - void *(*opendir) (struct vfs_class *me, char *dirname); + void *(*opendir) (struct vfs_class *me, const char *dirname); void *(*readdir) (void *vfs_info); int (*closedir) (void *vfs_info); @@ -52,7 +52,7 @@ struct vfs_class { int (*link) (struct vfs_class *me, char *p1, char *p2); int (*unlink) (struct vfs_class *me, char *path); int (*rename) (struct vfs_class *me, char *p1, char *p2); - int (*chdir) (struct vfs_class *me, char *path); + int (*chdir) (struct vfs_class *me, const char *path); int (*ferrno) (struct vfs_class *me); int (*lseek) (void *vfs_info, off_t offset, int whence); int (*mknod) (struct vfs_class *me, char *path, int mode, int dev); @@ -138,9 +138,9 @@ int mc_close (int handle); int mc_read (int handle, char *buffer, int count); int mc_write (int handle, char *buffer, int count); off_t mc_lseek (int fd, off_t offset, int whence); -int mc_chdir (char *); +int mc_chdir (const char *path); -DIR *mc_opendir (char *dirname); +DIR *mc_opendir (const char *dirname); struct dirent *mc_readdir (DIR * dirp); int mc_closedir (DIR * dir);