1: /*
   2: ** make directory
   3: */
   4: 
   5: #include    <signal.h>
   6: #include    <stdio.h>
   7: 
   8: int Errors = 0;
   9: char    *strcat();
  10: char    *strcpy();
  11: 
  12: main(argc, argv)
  13: char *argv[];
  14: {
  15: 
  16:     signal(SIGHUP, SIG_IGN);
  17:     signal(SIGINT, SIG_IGN);
  18:     signal(SIGQUIT, SIG_IGN);
  19:     signal(SIGPIPE, SIG_IGN);
  20:     signal(SIGTERM, SIG_IGN);
  21: 
  22:     if(argc < 2) {
  23:         fprintf(stderr, "mkdir: arg count\n");
  24:         exit(1);
  25:     }
  26:     while(--argc)
  27:         mkdir(*++argv);
  28:     exit(Errors!=0);
  29: }
  30: 
  31: mkdir(d)
  32: char *d;
  33: {
  34:     char pname[128], dname[128];
  35:     register i, slash = 0;
  36: 
  37:     pname[0] = '\0';
  38:     for(i = 0; d[i]; ++i)
  39:         if(d[i] == '/')
  40:             slash = i + 1;
  41:     if(slash)
  42:         strncpy(pname, d, slash);
  43:     strcpy(pname+slash, ".");
  44:     if (access(pname, 02)) {
  45:         fprintf(stderr,"mkdir: cannot access %s\n", pname);
  46:         ++Errors;
  47:         return;
  48:     }
  49:     if ((mknod(d, 040777, 0)) < 0) {
  50:         fprintf(stderr,"mkdir: cannot make directory %s\n", d);
  51:         ++Errors;
  52:         return;
  53:     }
  54:     chown(d, getuid(), getgid());
  55:     strcpy(dname, d);
  56:     strcat(dname, "/.");
  57:     if((link(d, dname)) < 0) {
  58:         fprintf(stderr, "mkdir: cannot link %s\n", dname);
  59:         unlink(d);
  60:         ++Errors;
  61:         return;
  62:     }
  63:     strcat(dname, ".");
  64:     if((link(pname, dname)) < 0) {
  65:         fprintf(stderr, "mkdir: cannot link %s\n",dname);
  66:         dname[strlen(dname)] = '\0';
  67:         unlink(dname);
  68:         unlink(d);
  69:         ++Errors;
  70:     }
  71: }

Defined functions

main defined in line 12; never used
mkdir defined in line 31; used 1 times
  • in line 27

Defined variables

Errors defined in line 8; used 5 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 745
Valid CSS Valid XHTML 1.0 Strict