12345678910111213141516171819202122232425262728293031323334 |
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- #include <errno.h>
- static int usage()
- {
- fprintf(stderr,"ln [-s] <target> <name>\n");
- return -1;
- }
- int main(int argc, char *argv[])
- {
- int symbolic = 0;
- int ret;
- if(argc < 2) return usage();
-
- if(!strcmp(argv[1],"-s")) {
- symbolic = 1;
- argc--;
- argv++;
- }
- if(argc < 3) return usage();
- if(symbolic) {
- ret = symlink(argv[1], argv[2]);
- } else {
- ret = link(argv[1], argv[2]);
- }
- if(ret < 0)
- fprintf(stderr, "link failed %s\n", strerror(errno));
- return ret;
- }
|