- if (set_modes == TRUE) {
- /* This is fine, since symlinks never get here */
- if (chown(dst_name, srcStatBuf.st_uid, srcStatBuf.st_gid) < 0)
- perror_msg("%s", dst_name);
- if (chmod(dst_name, srcStatBuf.st_mode) < 0)
- perror_msg("%s", dst_name);
- times.actime = srcStatBuf.st_atime;
- times.modtime = srcStatBuf.st_mtime;
- if (utime(dst_name, ×) < 0)
- perror_msg("%s", dst_name);
+ if (fclose(sfp) < 0) {
+ perror_msg("unable to close `%s'", source);
+ status = -1;
+ }
+ } else if (S_ISBLK(source_stat.st_mode) || S_ISCHR(source_stat.st_mode) ||
+ S_ISSOCK(source_stat.st_mode)) {
+ if (mknod(dest, source_stat.st_mode, source_stat.st_rdev) < 0) {
+ perror_msg("unable to create `%s'", dest);
+ return -1;
+ }
+ } else if (S_ISFIFO(source_stat.st_mode)) {
+ if (mkfifo(dest, source_stat.st_mode) < 0) {
+ perror_msg("cannot create fifo `%s'", dest);
+ return -1;
+ }
+ } else if (S_ISLNK(source_stat.st_mode)) {
+ char *lpath = xreadlink(source);
+ if (symlink(lpath, dest) < 0) {
+ perror_msg("cannot create symlink `%s'", dest);
+ return -1;
+ }
+ free(lpath);
+
+#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1)
+ if (flags & FILEUTILS_PRESERVE_STATUS)
+ if (lchown(dest, source_stat.st_uid, source_stat.st_gid) < 0)
+ perror_msg("unable to preserve ownership of `%s'", dest);
+#endif
+ return 0;
+ } else {
+ error_msg("internal error: unrecognized file type");
+ return -1;