| 1 | #include <sys/types.h> |
| 2 | #include <sys/stat.h> |
| 3 | |
| 4 | /* lnall- |
| 5 | * son of mvall, son of cpall, son of ... |
| 6 | */ |
| 7 | |
| 8 | char buf[100]; |
| 9 | |
| 10 | main(argc, argv) |
| 11 | char **argv; |
| 12 | { |
| 13 | register char *c1, *c2, *cp; |
| 14 | int i; |
| 15 | |
| 16 | if(argc < 3) { |
| 17 | write(2, "arg count\n", 10); |
| 18 | exit(); |
| 19 | } |
| 20 | argc--; |
| 21 | if (!dir(argv[argc])) |
| 22 | { |
| 23 | printf("%s: not a directory\n", argv[argc]); |
| 24 | exit(1); |
| 25 | } |
| 26 | c1 = buf; |
| 27 | c2 = argv[argc]; |
| 28 | while(*c1++ = *c2++); |
| 29 | c1[-1] = '/'; |
| 30 | for(i=1; i<argc; i++) |
| 31 | { |
| 32 | c2 = c1; |
| 33 | cp = (char *) actual(argv[i]); |
| 34 | while (*c2++ = *cp++); |
| 35 | if (link(argv[i],buf)) perror(argv[i]); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | dir(n) |
| 40 | char *n; |
| 41 | { |
| 42 | struct stat statbuf; |
| 43 | if (stat(n,&statbuf)) return(0); |
| 44 | return((statbuf.st_mode & 060000) == 040000); |
| 45 | } |
| 46 | |
| 47 | actual(str) |
| 48 | char *str; |
| 49 | { |
| 50 | register char *f; |
| 51 | register slash; |
| 52 | f = str; |
| 53 | slash = 0; |
| 54 | while (*f) if (*f++ == '/') slash++; |
| 55 | if (!slash) return(str); |
| 56 | while (*f != '/') --f; |
| 57 | ++f; |
| 58 | return(f); |
| 59 | } |
| 60 | |
| 61 | |