Home | History | Annotate | Download | only in toolbox
      1 #include <stdio.h>
      2 #include <unistd.h>
      3 #include <string.h>
      4 #include <errno.h>
      5 
      6 static int usage()
      7 {
      8     fprintf(stderr,"ln [-s] <target> <name>\n");
      9     return -1;
     10 }
     11 
     12 int ln_main(int argc, char *argv[])
     13 {
     14     int symbolic = 0;
     15     int ret;
     16     if(argc < 2) return usage();
     17 
     18     if(!strcmp(argv[1],"-s")) {
     19         symbolic = 1;
     20         argc--;
     21         argv++;
     22     }
     23 
     24     if(argc < 3) return usage();
     25 
     26     if(symbolic) {
     27         ret = symlink(argv[1], argv[2]);
     28     } else {
     29         ret = link(argv[1], argv[2]);
     30     }
     31     if(ret < 0)
     32         fprintf(stderr, "link failed %s\n", strerror(errno));
     33     return ret;
     34 }
     35