/[cvs]/ccvs/src/filesubr.c
ViewVC logotype

Diff of /ccvs/src/filesubr.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.105.4.3 by dprice, Thu Dec 1 01:48:59 2005 UTC revision 1.105.4.4 by dprice, Thu Dec 1 15:58:44 2005 UTC
# Line 34  Line 34 
34    
35  static int deep_remove_dir (const char *path);  static int deep_remove_dir (const char *path);
36    
37    
38    
39  /*  /*
40   * Copies "from" to "to".   * Copies FROM to TO.  Ignores NOEXEC.
41   */   */
42  void  void
43  copy_file (const char *from, const char *to)  force_copy_file (const char *from, const char *to)
44  {  {
45      struct stat sb;      struct stat sb;
46      struct utimbuf t;      struct utimbuf t;
47      int fdin, fdout;      int fdin, fdout;
48      ssize_t rsize;      ssize_t rsize;
49    
     TRACE (TRACE_FUNCTION, "copy(%s,%s)", from, to);  
   
     if (noexec)  
         return;  
   
50      /* If the file to be copied is a link or a device, then just create      /* If the file to be copied is a link or a device, then just create
51         the new link or device appropriately. */         the new link or device appropriately. */
52      if ((rsize = islink (from)) > 0)      if ((rsize = islink (from)) > 0)
# Line 119  copy_file (const char *from, const char Line 116  copy_file (const char *from, const char
116    
117    
118    
119    /*
120     * Copies FROM to TO.  Honors NOEXEC.
121     */
122    void
123    copy_file (const char *from, const char *to)
124    {
125        TRACE (TRACE_FUNCTION, "copy (%s, %s)", from, to);
126        if (noexec) return;
127        force_copy_file (from, to);
128    }
129    
130    
131    
132  /* FIXME-krp: these functions would benefit from caching the char * &  /* FIXME-krp: these functions would benefit from caching the char * &
133     stat buf.  */     stat buf.  */
134    
# Line 339  mkdir_if_needed (const char *name) Line 349  mkdir_if_needed (const char *name)
349      return 0;      return 0;
350  }  }
351    
352    
353    
354  /*  /*
355   * Change the mode of a file, either adding write permissions, or removing   * Change the mode of a file, either adding write permissions, or removing
356   * all write permissions.  Either change honors the current umask setting.   * all write permissions.  Either change honors the current umask setting.
# Line 346  mkdir_if_needed (const char *name) Line 358  mkdir_if_needed (const char *name)
358   * Don't do anything if PreservePermissions is set to `yes'.  This may   * Don't do anything if PreservePermissions is set to `yes'.  This may
359   * have unexpected consequences for some uses of xchmod.   * have unexpected consequences for some uses of xchmod.
360   */   */
361  void  static void
362  xchmod (const char *fname, int writable)  ixchmod (const char *fname, bool writable, bool noexec)
363  {  {
364      struct stat sb;      struct stat sb;
365      mode_t mode, oumask;      mode_t mode, oumask;
# Line 366  xchmod (const char *fname, int writable) Line 378  xchmod (const char *fname, int writable)
378      oumask = umask (0);      oumask = umask (0);
379      (void) umask (oumask);      (void) umask (oumask);
380      if (writable)      if (writable)
     {  
381          mode = sb.st_mode | (~oumask          mode = sb.st_mode | (~oumask
382                               & (((sb.st_mode & S_IRUSR) ? S_IWUSR : 0)                               & (((sb.st_mode & S_IRUSR) ? S_IWUSR : 0)
383                                  | ((sb.st_mode & S_IRGRP) ? S_IWGRP : 0)                                  | ((sb.st_mode & S_IRGRP) ? S_IWGRP : 0)
384                                  | ((sb.st_mode & S_IROTH) ? S_IWOTH : 0)));                                  | ((sb.st_mode & S_IROTH) ? S_IWOTH : 0)));
     }  
385      else      else
     {  
386          mode = sb.st_mode & ~(S_IWRITE | S_IWGRP | S_IWOTH) & ~oumask;          mode = sb.st_mode & ~(S_IWRITE | S_IWGRP | S_IWOTH) & ~oumask;
     }  
387    
388      TRACE (TRACE_FUNCTION, "chmod(%s,%o)", fname, (unsigned int) mode);      TRACE (TRACE_FUNCTION, "chmod(%s,%o)", fname, (unsigned int) mode);
389    
# Line 386  xchmod (const char *fname, int writable) Line 394  xchmod (const char *fname, int writable)
394          error (0, errno, "cannot change mode of file %s", fname);          error (0, errno, "cannot change mode of file %s", fname);
395  }  }
396    
397    
398    
399    /* See description for ixchmod.  Ignores NOEXEC.  */
400    void
401    force_xchmod (const char *fname, bool writable)
402    {
403        ixchmod (fname, writable, false);
404    }
405    
406    
407    
408    /* See description for ixchmod.  Honors NOEXEC.  */
409    void
410    xchmod (const char *fname, bool writable)
411    {
412        ixchmod (fname, writable, noexec);
413    }
414    
415    
416    
417  /*  /*
418   * Rename a file and die if it fails   * Rename a file and die if it fails
419   */   */

Legend:
Removed from v.1.105.4.3  
changed lines
  Added in v.1.105.4.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26