diff options
author | Kiyoshi Aman <kiyoshi.aman+adelie@gmail.com> | 2019-05-11 21:36:41 -0500 |
---|---|---|
committer | Kiyoshi Aman <kiyoshi.aman+adelie@gmail.com> | 2019-05-11 21:36:41 -0500 |
commit | 9d6d971d463053417e18e01095cc3c7bf722f892 (patch) | |
tree | efdc90a9ac38fb0a09295856a7a182b2a692a230 | |
parent | 6acee58ff11645500868d4b86e7470293c478f57 (diff) | |
download | userland-9d6d971d463053417e18e01095cc3c7bf722f892.tar.gz userland-9d6d971d463053417e18e01095cc3c7bf722f892.tar.bz2 userland-9d6d971d463053417e18e01095cc3c7bf722f892.tar.xz userland-9d6d971d463053417e18e01095cc3c7bf722f892.zip |
bin/cp: make buildable via libbsd
-rw-r--r-- | bin/cp/cp.c | 21 | ||||
-rw-r--r-- | bin/cp/extern.h | 7 | ||||
-rw-r--r-- | bin/cp/utils.c | 58 |
3 files changed, 33 insertions, 53 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 2f4fab1..4f5d960 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -32,21 +32,6 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -#ifndef lint -__COPYRIGHT( -"@(#) Copyright (c) 1988, 1993, 1994\ - The Regents of the University of California. All rights reserved."); -#endif /* not lint */ - -#ifndef lint -#if 0 -static char sccsid[] = "@(#)cp.c 8.5 (Berkeley) 4/29/95"; -#else -__RCSID("$NetBSD: cp.c,v 1.59 2016/03/05 19:48:55 uwe Exp $"); -#endif -#endif /* not lint */ - /* * Cp copies source files to target files. * @@ -72,9 +57,11 @@ __RCSID("$NetBSD: cp.c,v 1.59 2016/03/05 19:48:55 uwe Exp $"); #include <locale.h> #include <signal.h> #include <stdlib.h> +#include <bsd/stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> +#include <signal.h> #include "extern.h" @@ -96,7 +83,7 @@ enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE }; static int copy(char *[], enum op, int); static void -progress(int sig __unused) +progress(int sig) { pinfo++; @@ -218,7 +205,7 @@ main(int argc, char *argv[]) /* Set end of argument list for fts(3). */ argv[argc] = NULL; - (void)signal(SIGINFO, progress); + (void)signal(SIGHUP, progress); /* * Cp has two distinct cases: diff --git a/bin/cp/extern.h b/bin/cp/extern.h index e393844..8d848f8 100644 --- a/bin/cp/extern.h +++ b/bin/cp/extern.h @@ -34,6 +34,9 @@ #ifndef _EXTERN_H_ #define _EXTERN_H_ +#define MAXBSIZE (64 * 1024) +#define _POSIX_C_SOURCE 200809L + typedef struct { char *p_end; /* pointer to NULL at end of path */ char *target_end; /* pointer to end of target base */ @@ -46,9 +49,6 @@ extern int Rflag, rflag, Hflag, Lflag, Pflag, fflag, iflag, lflag, pflag, Nflag; extern mode_t myumask; extern sig_atomic_t pinfo; -#include <sys/cdefs.h> - -__BEGIN_DECLS int copy_fifo(struct stat *, int); int copy_file(FTSENT *, int); int copy_link(FTSENT *, int); @@ -56,6 +56,5 @@ int copy_special(struct stat *, int); int set_utimes(const char *, struct stat *); int setfile(struct stat *, int); void usage(void) __attribute__((__noreturn__)); -__END_DECLS #endif /* !_EXTERN_H_ */ diff --git a/bin/cp/utils.c b/bin/cp/utils.c index 6275fc6..8685408 100644 --- a/bin/cp/utils.c +++ b/bin/cp/utils.c @@ -29,20 +29,12 @@ * SUCH DAMAGE. */ -#include <sys/cdefs.h> -#ifndef lint -#if 0 -static char sccsid[] = "@(#)utils.c 8.3 (Berkeley) 4/1/94"; -#else -__RCSID("$NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $"); -#endif -#endif /* not lint */ - #include <sys/mman.h> #include <sys/param.h> #include <sys/stat.h> #include <sys/time.h> -#include <sys/extattr.h> +#include <linux/fs.h> +#include <sys/ioctl.h> #include <err.h> #include <errno.h> @@ -51,24 +43,44 @@ __RCSID("$NetBSD: utils.c,v 1.46 2018/07/17 13:04:58 darcy Exp $"); #include <stdbool.h> #include <stdio.h> #include <stdlib.h> +#include <bsd/stdlib.h> #include <string.h> #include <unistd.h> +#include <signal.h> #include "extern.h" #define MMAP_MAX_SIZE (8 * 1048576) #define MMAP_MAX_WRITE (64 * 1024) +#ifndef HAVE_FCPXATTR +int +fcpxattr(int from_fd, int to_fd) +{ + int attr, from_ret, to_ret; + + from_ret = ioctl(from_fd, FS_IOC_GETFLAGS, &attr); + if (from_ret != 0) { + return from_ret; + } + to_ret = ioctl(to_ret, FS_IOC_SETFLAGS, &attr); + if (to_ret != 0) { + return to_ret; + } + return 0; +} +#endif + int set_utimes(const char *file, struct stat *fs) { struct timespec ts[2]; - ts[0] = fs->st_atimespec; - ts[1] = fs->st_mtimespec; + ts[0] = fs->st_atim; + ts[1] = fs->st_mtim; - if (lutimens(file, ts)) { - warn("lutimens: %s", file); + if (utimensat(AT_FDCWD, file, ts, AT_SYMLINK_NOFOLLOW)) { + warn("utimensat: %s", file); return (1); } return (0); @@ -383,24 +395,6 @@ setfile(struct stat *fs, int fd) rval = 1; } - if (!islink && !Nflag) { - unsigned long fflags = fs->st_flags; - /* - * XXX - * NFS doesn't support chflags; ignore errors unless - * there's reason to believe we're losing bits. - * (Note, this still won't be right if the server - * supports flags and we were trying to *remove* flags - * on a file that we copied, i.e., that we didn't create.) - */ - errno = 0; - if ((fd ? fchflags(fd, fflags) : - chflags(to.p_path, fflags)) == -1) - if (errno != EOPNOTSUPP || fs->st_flags != 0) { - warn("chflags: %s", to.p_path); - rval = 1; - } - } /* if fd is non-zero, caller must call set_utimes() after close() */ if (fd == 0 && set_utimes(to.p_path, fs)) rval = 1; |