home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / mc454src.zip / mc-4.5.4.src / mc-4.5.4 / src / filenot.c < prev    next >
C/C++ Source or Header  |  1999-01-04  |  2KB  |  109 lines

  1. /*
  2.  * filenot.c:  wrapper for routines to notify the
  3.  * tree about the changes made to the directory
  4.  * structure.
  5.  *
  6.  * Author:
  7.  *    Janne Kukonlehto
  8.  *    Miguel de Icaza
  9.  */
  10.  
  11. #include <config.h>
  12. #include <string.h>
  13. #include <malloc.h>
  14. #include "util.h"
  15. #include <errno.h>
  16. #include "../vfs/vfs.h"
  17.  
  18. static char *get_absolute_name (char *file)
  19. {
  20.     char dir [MC_MAXPATHLEN];
  21.  
  22.     if (file [0] == PATH_SEP)
  23.     return strdup (file);
  24.     mc_get_current_wd (dir, MC_MAXPATHLEN);
  25.     return get_full_name (dir, file);
  26. }
  27.  
  28. static int
  29. my_mkdir_rec (char *s, mode_t mode)
  30. {
  31.     char *p, *q;
  32.     int result;
  33.     
  34.     if (!mc_mkdir (s, mode))
  35.         return 0;
  36.     else if (errno != ENOENT)
  37.     return -1;
  38.  
  39.     /* FIXME: should check instead if s is at the root of that filesystem */
  40.     if (!vfs_file_is_local (s))
  41.     return -1;
  42.  
  43.     if (!strcmp (s, PATH_SEP_STR)) {
  44.         errno = ENOTDIR;
  45.         return -1;
  46.     }
  47.  
  48.     p = concat_dir_and_file (s, "..");
  49.     q = vfs_canon (p);
  50.     free (p);
  51.  
  52.     if (!(result = my_mkdir_rec (q, mode))) 
  53.         result = mc_mkdir (s, mode);
  54.  
  55.     free (q);
  56.     return result;
  57. }
  58.  
  59. int
  60. my_mkdir (char *s, mode_t mode)
  61. {
  62.     int result;
  63.  
  64.     result = mc_mkdir (s, mode);
  65. #ifdef OS2_NT
  66.     /* .ado: it will be disabled in OS/2 and NT */
  67.     /* otherwise crash if directory already exists. */
  68.     return result;
  69. #endif
  70.     if (result) {
  71.         char *p = vfs_canon (s);
  72.         
  73.         result = my_mkdir_rec (p, mode);
  74.         free (p);
  75.     }
  76.     if (result == 0){
  77.     s = get_absolute_name (s);
  78.  
  79. #if FIXME
  80.     tree_add_entry (tree, s);
  81. #endif
  82.  
  83.     free (s);
  84.     }
  85.     return result;
  86. }
  87.  
  88. int my_rmdir (char *s)
  89. {
  90.     int result;
  91. #if FIXME    
  92.     WTree *tree = 0;
  93. #endif    
  94.  
  95.     /* FIXME: Should receive a Wtree! */
  96.     result = mc_rmdir (s);
  97.     if (result == 0){
  98.     s = get_absolute_name (s);
  99.  
  100. #if FIXME
  101.     tree_remove_entry (tree, s);
  102. #endif
  103.  
  104.     free (s);
  105.     }
  106.     return result;
  107. }
  108.  
  109.