home *** CD-ROM | disk | FTP | other *** search
/ MacGames Sampler / PHT MacGames Bundle.iso / MacSource Folder / Samples from the CD / Editors / emacs / Emacs-1.14b1-sources / sources / utility-src / chmod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-04  |  1.3 KB  |  67 lines  |  [TEXT/EMAC]

  1. /*
  2.  * Copyright (C) 1993, 1994 Marc Parmet.
  3.  * This file is part of the Macintosh port of GNU Emacs.
  4.  *
  5.  * GNU Emacs is distributed in the hope that it will be useful,
  6.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  7.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  8.  * GNU General Public License for more details.
  9.  */
  10.  
  11. #include "stdio.h"
  12.  
  13. main(int argc,char **argv)
  14. {
  15.     char s[256];
  16.     int i,err,failures,newproperty;
  17.  
  18.     if (argc < 2) {
  19.         fprintf(stderr,"Usage: %s newvalue file1 [file2 ...]\n",argv[0]);
  20.         return 1;
  21.     }
  22.     
  23. #ifdef chgrp_project
  24.     strcpy(s,argv[1]);
  25.     strcat(s,"    ");
  26.     newproperty = *(long *)s;
  27. #else
  28. #ifdef chown_project
  29.     strcpy(s,argv[1]);
  30.     strcat(s,"    ");
  31.     newproperty = *(long *)s;
  32. #else
  33. #ifdef chmod_project
  34.     newproperty = 0;
  35.     for (i = 0; i<strlen(argv[1]); ++i)
  36.         newproperty = 8*newproperty + (argv[1][i] - '0');
  37. #else
  38. #error
  39. #endif
  40. #endif
  41. #endif
  42.  
  43.     failures = 0;
  44.     for (i = 2; i<argc; ++i) {
  45. #ifdef chgrp_project
  46.         err = chgrp(argv[i],newproperty);
  47. #else
  48. #ifdef chown_project
  49.         err = chown(argv[i],newproperty);
  50. #else
  51. #ifdef chmod_project
  52.         err = chmod(argv[i],newproperty);
  53. #else
  54. #error
  55. #endif
  56. #endif
  57. #endif
  58.  
  59.         if (err < 0) {
  60.             fprintf(stderr,"%s: Can't modify %s\n",argv[0],argv[i]);
  61.             failures = 1;
  62.         }
  63.     }
  64.  
  65.     return failures;
  66. }
  67.