home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V6 / usr / source / s1 / ln.c < prev    next >
Encoding:
C/C++ Source or Header  |  1975-05-13  |  686 b   |  49 lines

  1. #
  2. /*
  3.  * ln target [ new name ]
  4.  */
  5.  
  6. struct ibuf {
  7.     int    inum;
  8.     int    iflags;
  9.     char    inl;
  10.     char    iuid;
  11.     int    isize;
  12.     int    iaddr[8];
  13.     char    *ictime[2];
  14.     char    *imtime[2];
  15.     int    fill;
  16. };
  17.  
  18. #define    DIR    040000
  19. #define    FMT    060000
  20.  
  21. main(argc, argv)
  22. char **argv;
  23. {
  24.     static struct ibuf statb;
  25.     register char *np;
  26.  
  27.     if (argc<2) {
  28.         write(1, "Usage: ln target [ newname ]\n", 29);
  29.         exit(1);
  30.     }
  31.     if (argc==2) {
  32.         np = argv[1];
  33.         while(*np++);
  34.         while (*--np!='/' && np>argv[1]);
  35.         np++;
  36.         argv[2] = np;
  37.     }
  38.     stat(argv[1], &statb);
  39.     if ((statb.iflags&FMT) == DIR) {
  40.         write(1, "No directory link\n", 18);
  41.         exit(1);
  42.     }
  43.     if (link(argv[1], argv[2])<0) {
  44.         write(1, "Can't link\n", 11);
  45.         exit(1);
  46.     }
  47.     exit(0);
  48. }
  49.