- /* check source */
- if (stat(argv[0], &from_sb)) {
- fprintf(stderr, "install: fstat: %s: %s\n", argv[0], sys_errlist[errno]);
- exit(1);
- }
- if (!(from_sb.st_mode & S_IFREG)) {
- fprintf(stderr, "install: %s isn't a regular file.\n", argv[0]);
- exit(1);
- }
-
- /* build target path, find out if target is same as source */
- if (!stat(path = argv[1], &to_sb)) {
- if (to_sb.st_mode & S_IFDIR) {
- (void)sprintf(path = pbuf, "%s/%s", argv[1], argv[0]);
- if (stat(path, &to_sb))
- goto nocompare;
- if (to_sb.st_mode & S_IFDIR) {
- fprintf(stderr, "install: %s is a directory.\n", path);
- exit(1);
- }
- }
- if (to_sb.st_dev == from_sb.st_dev && to_sb.st_ino == from_sb.st_ino) {
- fprintf(stderr, "install: %s and %s are the same file.\n", argv[0], path);
- exit(1);
- }
- /* unlink now... avoid ETXTBSY errors later */
- (void)unlink(path);
- }
-
-nocompare: