|
|
1.1 ! root 1: /* ! 2: * ln [ -f ] target [ new name ] ! 3: */ ! 4: ! 5: #include <sys/types.h> ! 6: #include <sys/stat.h> ! 7: #include "stdio.h" ! 8: char *rindex(); ! 9: ! 10: main(argc, argv) ! 11: char **argv; ! 12: { ! 13: struct stat statb; ! 14: register char *np; ! 15: int fflag = 0; ! 16: char nb[100], *name=nb, *arg2; ! 17: int statres; ! 18: ! 19: if (argc >1 && strcmp(argv[1], "-f")==0) { ! 20: argc--; ! 21: argv++; ! 22: fflag++; ! 23: } ! 24: if (argc<2 || argc>3) { ! 25: printf("Usage: ln target [ newname ]\n"); ! 26: exit(1); ! 27: } ! 28: np = rindex(argv[1], '/'); ! 29: if (np==0) ! 30: np = argv[1]; ! 31: else ! 32: np++; ! 33: if (argc==2) ! 34: arg2 = np; ! 35: else ! 36: arg2 = argv[2]; ! 37: statres = stat(argv[1], &statb); ! 38: if (statres<0) { ! 39: printf ("ln: %s does not exist\n", argv[1]); ! 40: exit(1); ! 41: } ! 42: if (fflag==0 && (statb.st_mode&S_IFMT) == S_IFDIR) { ! 43: printf("ln: %s is a directory\n", argv[1]); ! 44: exit(1); ! 45: } ! 46: statres = stat(arg2, &statb); ! 47: if (statres>=0 && (statb.st_mode&S_IFMT) == S_IFDIR) ! 48: sprintf(name, "%s/%s", arg2, np); ! 49: else ! 50: name = arg2; ! 51: if (link(argv[1], name)<0) { ! 52: perror("ln"); ! 53: exit(1); ! 54: } ! 55: exit(0); ! 56: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.