Browse Source

Return values of following functions are constants now:

  * vfs_path_get_last_path_str()
  * vfs_path_get_last_path_vfs()
  * vfs_path_get_by_index()
  * vfs_class_find_by_handle()

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Slava Zanko 13 years ago
parent
commit
a8da7179d0
10 changed files with 64 additions and 50 deletions
  1. 11 9
      lib/vfs/direntry.c
  2. 3 3
      lib/vfs/gc.c
  3. 15 16
      lib/vfs/interface.c
  4. 21 10
      lib/vfs/path.c
  5. 3 3
      lib/vfs/path.h
  6. 6 4
      lib/vfs/vfs.c
  7. 1 1
      src/editor/edit.c
  8. 1 1
      src/editor/editcmd.c
  9. 1 1
      src/filemanager/dir.c
  10. 2 2
      src/filemanager/ext.c

+ 11 - 9
lib/vfs/direntry.c

@@ -375,7 +375,7 @@ vfs_s_inode_from_path (const vfs_path_t * vpath, int flags)
     struct vfs_s_super *super;
     struct vfs_s_inode *ino;
     const char *q;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     q = vfs_s_get_path (vpath, &super, 0);
     if (q == NULL)
@@ -402,7 +402,7 @@ vfs_s_opendir (const vfs_path_t * vpath)
 {
     struct vfs_s_inode *dir;
     struct dirhandle *info;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     path_element = vfs_path_get_by_index (vpath, -1);
 
@@ -528,7 +528,7 @@ vfs_s_readlink (const vfs_path_t * vpath, char *buf, size_t size)
 {
     struct vfs_s_inode *ino;
     size_t len;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     path_element = vfs_path_get_by_index (vpath, -1);
 
@@ -755,7 +755,7 @@ vfs_s_getlocalcopy (const vfs_path_t * vpath)
 
     if (fh != NULL)
     {
-        struct vfs_class *me;
+        const struct vfs_class *me;
 
         me = vfs_path_get_by_index (vpath, -1)->class;
         if ((MEDATA->flags & VFS_S_USETMP) != 0 && (fh->ino != NULL))
@@ -787,15 +787,17 @@ vfs_s_ungetlocalcopy (const vfs_path_t * vpath, const vfs_path_t * local, gboole
 static int
 vfs_s_setctl (const vfs_path_t * vpath, int ctlop, void *arg)
 {
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     path_element = vfs_path_get_by_index (vpath, -1);
+
     switch (ctlop)
     {
     case VFS_SETCTL_STALE_DATA:
         {
-            struct vfs_s_inode *ino = vfs_s_inode_from_path (vpath, 0);
+            struct vfs_s_inode *ino;
 
+            ino = vfs_s_inode_from_path (vpath, 0);
             if (ino == NULL)
                 return 0;
             if (arg)
@@ -1058,7 +1060,7 @@ vfs_s_get_path (const vfs_path_t * vpath, struct vfs_s_super **archive, int flag
     int result = -1;
     struct vfs_s_super *super;
     void *cookie = NULL;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
     vfs_path_t *vpath_archive;
     struct vfs_s_subclass *subclass;
 
@@ -1182,7 +1184,7 @@ vfs_s_open (const vfs_path_t * vpath, int flags, mode_t mode)
     struct vfs_s_super *super;
     const char *q;
     struct vfs_s_inode *ino;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     path_element = vfs_path_get_by_index (vpath, -1);
 
@@ -1419,7 +1421,7 @@ vfs_s_init_class (struct vfs_class *vclass, struct vfs_s_subclass *sub)
 vfsid
 vfs_getid (const vfs_path_t * vpath)
 {
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     path_element = vfs_path_get_by_index (vpath, -1);
     if (!vfs_path_element_valid (path_element) || path_element->class->getid == NULL)

+ 3 - 3
lib/vfs/gc.c

@@ -161,7 +161,7 @@ vfs_stamp_path (const char *path)
 {
     vfsid id;
     vfs_path_t *vpath;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     vpath = vfs_path_from_str (path);
     path_element = vfs_path_get_by_index (vpath, -1);
@@ -183,7 +183,7 @@ vfs_stamp_create (struct vfs_class *vclass, vfsid id)
 
     ev_vfs_stamp_create_t event_data = { vclass, id, FALSE };
     vfs_path_t *vpath;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     /* There are three directories we have to take care of: current_dir,
        current_panel->cwd and other_panel->cwd. Athough most of the time either
@@ -272,7 +272,7 @@ void
 vfs_release_path (const char *dir)
 {
     vfs_path_t *vpath;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     vpath = vfs_path_from_str (dir);
     path_element = vfs_path_get_by_index (vpath, -1);

+ 15 - 16
lib/vfs/interface.c

@@ -132,7 +132,7 @@ mc_def_ungetlocalcopy (const vfs_path_t * filename_vpath,
                        const vfs_path_t * local_vpath, gboolean has_changed)
 {
     int fdin = -1, fdout = -1;
-    char *local;
+    const char *local;
 
     local = vfs_path_get_last_path_str (local_vpath);
 
@@ -189,7 +189,7 @@ int
 mc_open (const vfs_path_t * vpath, int flags, ...)
 {
     int mode = 0, result = -1;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     if (vpath == NULL)
         return -1;
@@ -228,7 +228,7 @@ mc_open (const vfs_path_t * vpath, int flags, ...)
 int mc_##name inarg \
 { \
     int result; \
-    vfs_path_element_t *path_element; \
+    const vfs_path_element_t *path_element; \
 \
     if (vpath == NULL) \
         return -1; \
@@ -268,7 +268,7 @@ mc_symlink (const vfs_path_t * vpath1, const vfs_path_t * vpath2)
 
     if (vpath1 != NULL)
     {
-        vfs_path_element_t *path_element;
+        const vfs_path_element_t *path_element;
 
         path_element = vfs_path_get_by_index (vpath2, -1);
         if (vfs_path_element_valid (path_element))
@@ -315,7 +315,8 @@ MC_HANDLEOP (write, (int handle, const void *buf, size_t nbyte), (vfs_class_data
 int mc_##name (const vfs_path_t *vpath1, const vfs_path_t *vpath2) \
 { \
     int result; \
-    vfs_path_element_t *path_element1, *path_element2; \
+    const vfs_path_element_t *path_element1; \
+    const vfs_path_element_t *path_element2; \
 \
     if (vpath1 == NULL || vpath2 == NULL) \
         return -1; \
@@ -362,8 +363,7 @@ int
 mc_setctl (const vfs_path_t * vpath, int ctlop, void *arg)
 {
     int result = -1;
-
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     if (vpath == NULL)
         vfs_die ("You don't want to pass NULL to mc_setctl.");
@@ -417,7 +417,7 @@ mc_opendir (const vfs_path_t * vpath)
     if (vpath == NULL)
         return NULL;
 
-    path_element = vfs_path_get_by_index (vpath, -1);
+    path_element = (vfs_path_element_t *) vfs_path_get_by_index (vpath, -1);
 
     if (!vfs_path_element_valid (path_element))
     {
@@ -435,9 +435,8 @@ mc_opendir (const vfs_path_t * vpath)
 
     path_element->dir.info = info;
 
-    path_element->dir.converter =
-        (path_element->encoding !=
-         NULL) ? str_crt_conv_from (path_element->encoding) : str_cnv_from_term;
+    path_element->dir.converter = (path_element->encoding != NULL) ?
+                    str_crt_conv_from (path_element->encoding) : str_cnv_from_term;
     if (path_element->dir.converter == INVALID_CONV)
         path_element->dir.converter = str_cnv_from_term;
 
@@ -536,7 +535,7 @@ int
 mc_stat (const vfs_path_t * vpath, struct stat *buf)
 {
     int result = -1;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     if (vpath == NULL)
         return -1;
@@ -559,7 +558,7 @@ int
 mc_lstat (const vfs_path_t * vpath, struct stat *buf)
 {
     int result = -1;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     if (vpath == NULL)
         return -1;
@@ -603,7 +602,7 @@ vfs_path_t *
 mc_getlocalcopy (const vfs_path_t * pathname_vpath)
 {
     vfs_path_t *result = NULL;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     if (pathname_vpath == NULL)
         return NULL;
@@ -628,7 +627,7 @@ mc_ungetlocalcopy (const vfs_path_t * pathname_vpath, const vfs_path_t * local_v
                    gboolean has_changed)
 {
     int return_value = -1;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     if (pathname_vpath == NULL)
         return -1;
@@ -658,7 +657,7 @@ mc_chdir (const vfs_path_t * vpath)
     struct vfs_class *old_vfs;
     vfsid old_vfsid;
     int result;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     if (vpath == NULL)
         return -1;

+ 21 - 10
lib/vfs/path.c

@@ -499,7 +499,7 @@ vfs_path_from_str_uri_parser (char *path)
  */
 
 static void
-vfs_path_tokens_add_class_info (vfs_path_element_t * element, GString * ret_tokens,
+vfs_path_tokens_add_class_info (const vfs_path_element_t * element, GString * ret_tokens,
                                 GString * element_tokens)
 {
     if (((element->class->flags & VFSF_LOCAL) == 0 || ret_tokens->len > 0)
@@ -612,7 +612,9 @@ vfs_path_to_str_flags (const vfs_path_t * vpath, int elements_count, vfs_path_fl
 
     for (element_index = 0; element_index < elements_count; element_index++)
     {
-        vfs_path_element_t *element = vfs_path_get_by_index (vpath, element_index);
+        const vfs_path_element_t *element;
+
+        element = vfs_path_get_by_index (vpath, element_index);
 
         if (element->vfs_prefix != NULL)
         {
@@ -795,7 +797,7 @@ vfs_path_add_element (const vfs_path_t * vpath, const vfs_path_element_t * path_
  * @return path element.
  */
 
-vfs_path_element_t *
+const vfs_path_element_t *
 vfs_path_get_by_index (const vfs_path_t * vpath, int element_index)
 {
     if (element_index < 0)
@@ -914,7 +916,12 @@ vfs_path_free (vfs_path_t * vpath)
 
     for (vpath_element_index = 0; vpath_element_index < vfs_path_elements_count (vpath);
          vpath_element_index++)
-        vfs_path_element_free (vfs_path_get_by_index (vpath, vpath_element_index));
+    {
+        vfs_path_element_t *path_element;
+
+        path_element = (vfs_path_element_t *) vfs_path_get_by_index (vpath, vpath_element_index);
+        vfs_path_element_free (path_element);
+    }
 
     g_array_free (vpath->path, TRUE);
     g_free (vpath);
@@ -940,7 +947,7 @@ vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index)
     if (element_index < 0)
         element_index = vfs_path_elements_count (vpath) + element_index;
 
-    element = vfs_path_get_by_index (vpath, element_index);
+    element = (vfs_path_element_t *) vfs_path_get_by_index (vpath, element_index);
     vpath->path = g_array_remove_index (vpath->path, element_index);
     vfs_path_element_free (element);
 }
@@ -956,7 +963,9 @@ vfs_prefix_to_class (const char *prefix)
     /* Avoid first class (localfs) that would accept any prefix */
     for (i = 1; i < vfs__classes_list->len; i++)
     {
-        struct vfs_class *vfs = (struct vfs_class *) g_ptr_array_index (vfs__classes_list, i);
+        struct vfs_class *vfs;
+
+        vfs = (struct vfs_class *) g_ptr_array_index (vfs__classes_list, i);
         if (vfs->which != NULL)
         {
             if (vfs->which (vfs, prefix) == -1)
@@ -1011,9 +1020,11 @@ vfs_path_serialize (const vfs_path_t * vpath, GError ** error)
     }
     for (element_index = 0; element_index < vfs_path_elements_count (vpath); element_index++)
     {
-        char *groupname = g_strdup_printf ("path-element-%zd", element_index);
-        vfs_path_element_t *element = vfs_path_get_by_index (vpath, element_index);
+        char *groupname;
+        const vfs_path_element_t *element;
 
+        groupname = g_strdup_printf ("path-element-%zd", element_index);
+        element = vfs_path_get_by_index (vpath, element_index);
         /* convert one element to config group */
 
         mc_config_set_string_raw (cpath, groupname, "path", element->path);
@@ -1238,7 +1249,7 @@ vfs_path_tokens_count (const vfs_path_t * vpath)
 
     for (element_index = 0; element_index < vfs_path_elements_count (vpath); element_index++)
     {
-        vfs_path_element_t *element;
+        const vfs_path_element_t *element;
         char **path_tokens, **iterator;
 
         element = vfs_path_get_by_index (vpath, element_index);
@@ -1300,7 +1311,7 @@ vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t l
 
     for (element_index = 0; element_index < vfs_path_elements_count (vpath); element_index++)
     {
-        vfs_path_element_t *element;
+        const vfs_path_element_t *element;
         char **path_tokens, **iterator;
 
         g_string_assign (element_tokens, "");

+ 3 - 3
lib/vfs/path.h

@@ -70,7 +70,7 @@ char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, ssi
 vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, ssize_t length);
 
 void vfs_path_add_element (const vfs_path_t * vpath, const vfs_path_element_t * path_element);
-vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
+const vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
 vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
 void vfs_path_element_free (vfs_path_element_t * element);
 
@@ -96,7 +96,7 @@ vfs_path_element_valid (const vfs_path_element_t * element)
 
 /* --------------------------------------------------------------------------------------------- */
 
-static inline char *
+static inline const char *
 vfs_path_get_last_path_str (const vfs_path_t * vpath)
 {
     const vfs_path_element_t *element;
@@ -108,7 +108,7 @@ vfs_path_get_last_path_str (const vfs_path_t * vpath)
 
 /* --------------------------------------------------------------------------------------------- */
 
-static inline struct vfs_class *
+static inline const struct vfs_class *
 vfs_path_get_last_path_vfs (const vfs_path_t * vpath)
 {
     const vfs_path_element_t *element;

+ 6 - 4
lib/vfs/vfs.c

@@ -408,8 +408,9 @@ vfs_current_is_local (void)
 vfs_class_flags_t
 vfs_file_class_flags (const vfs_path_t * vpath)
 {
-    vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1);
+    const vfs_path_element_t *path_element;
 
+    path_element = vfs_path_get_by_index (vpath, -1);
     if (!vfs_path_element_valid (path_element))
         return VFSF_UNKNOWN;
 
@@ -436,7 +437,7 @@ vfs_init (void)
 void
 vfs_setup_work_dir (void)
 {
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     vfs_setup_cwd ();
 
@@ -525,7 +526,7 @@ vfs_print_message (const char *msg, ...)
 void
 vfs_setup_cwd (void)
 {
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     if (vfs_get_raw_current_dir () == NULL)
     {
@@ -589,8 +590,9 @@ _vfs_get_cwd (void)
 vfs_path_t *
 vfs_change_encoding (vfs_path_t * vpath, const char *encoding)
 {
-    vfs_path_element_t *path_element = vfs_path_get_by_index (vpath, -1);
+    vfs_path_element_t *path_element;
 
+    path_element = (vfs_path_element_t *) vfs_path_get_by_index (vpath, -1);
     /* don't add current encoding */
     if ((path_element->encoding != NULL) && (strcmp (encoding, path_element->encoding) == 0))
         return vpath;

+ 1 - 1
src/editor/edit.c

@@ -1984,7 +1984,7 @@ edit_get_write_filter (const vfs_path_t * write_name_vpath, const vfs_path_t * f
 {
     int i;
     char *p, *writename;
-    vfs_path_element_t *path_element;
+    const vfs_path_element_t *path_element;
 
     i = edit_find_filter (filename_vpath);
     if (i < 0)

+ 1 - 1
src/editor/editcmd.c

@@ -321,7 +321,7 @@ edit_save_file (WEdit * edit, const vfs_path_t * filename_vpath)
     else
     {                           /* change line breaks */
         FILE *file;
-        vfs_path_element_t *path_element;
+        const vfs_path_element_t *path_element;
 
         mc_close (fd);
 

+ 1 - 1
src/filemanager/dir.c

@@ -628,7 +628,7 @@ do_reload_dir (const vfs_path_t * vpath, dir_list * list, sortfn * sort, int cou
     struct stat st;
     int marked_cnt;
     GHashTable *marked_files;
-    char *tmp_path;
+    const char *tmp_path;
 
     dirp = mc_opendir (vpath);
     if (dirp == NULL)

+ 2 - 2
src/filemanager/ext.c

@@ -238,7 +238,7 @@ exec_extension (const char *filename, const char *lc_data, int *move_dir, int st
                                 }
                                 else
                                 {
-                                    vfs_path_element_t *path_element;
+                                    const vfs_path_element_t *path_element;
 
                                     path_element = vfs_path_get_by_index (vpath, -1);
                                     text = quote_func (path_element->path, 0);
@@ -512,7 +512,7 @@ regex_check_type (const vfs_path_t * filename_vpath, const char *ptr, int *have_
     if (*have_type == 0)
     {
         vfs_path_t *localfile_vpath;
-        char *realname;         /* name used with "file" */
+        const char *realname;         /* name used with "file" */
 
 #ifdef HAVE_CHARSET
         int got_encoding_data;

Some files were not shown because too many files changed in this diff