123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #include <unistd.h>
- #include <stdlib.h>
- #include <string.h>
- #include <err.h>
- static
- void
- dosymlink(const char *text, const char *path)
- {
- if (symlink(text, path)) {
- err(1, "%s", path);
- }
- }
- static
- void
- dohardlink(const char *oldfile, const char *newfile)
- {
- if (link(oldfile, newfile)) {
- err(1, "%s or %s", oldfile, newfile);
- exit(1);
- }
- }
- int
- main(int argc, char *argv[])
- {
-
- if (argc==4 && !strcmp(argv[1], "-s")) {
- dosymlink(argv[2], argv[3]);
- }
- else if (argc==3) {
- dohardlink(argv[1], argv[2]);
- }
- else {
- warnx("Usage: ln oldfile newfile");
- errx(1, " ln -s symlinkcontents symlinkfile\n");
- }
- return 0;
- }
|