version 1.50, 2020/05/06 18:15:40 |
version 1.51, 2022/06/26 09:29:59 |
Line 58 __RCSID("$NetBSD$"); |
|
Line 58 __RCSID("$NetBSD$"); |
|
#include <fcntl.h> |
#include <fcntl.h> |
#include <locale.h> |
#include <locale.h> |
#include <netdb.h> |
#include <netdb.h> |
|
#include <paths.h> |
#include <pwd.h> |
#include <pwd.h> |
#include <signal.h> |
#include <signal.h> |
#include <stdio.h> |
#include <stdio.h> |
Line 79 int pflag, iamremote, iamrecursive, targ |
|
Line 80 int pflag, iamremote, iamrecursive, targ |
|
int family = AF_UNSPEC; |
int family = AF_UNSPEC; |
static char dot[] = "."; |
static char dot[] = "."; |
|
|
|
static sig_atomic_t print_info = 0; |
|
|
#define CMDNEEDS 64 |
#define CMDNEEDS 64 |
char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */ |
char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */ |
|
|
Line 89 void source(int, char *[]); |
|
Line 92 void source(int, char *[]); |
|
void tolocal(int, char *[]); |
void tolocal(int, char *[]); |
void toremote(char *, int, char *[]); |
void toremote(char *, int, char *[]); |
void usage(void); |
void usage(void); |
|
static void got_siginfo(int); |
|
static void progress(const char *, uintmax_t, uintmax_t); |
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
Line 173 main(int argc, char *argv[]) |
|
Line 178 main(int argc, char *argv[]) |
|
targetshouldbedirectory ? " -d" : ""); |
targetshouldbedirectory ? " -d" : ""); |
|
|
(void)signal(SIGPIPE, lostconn); |
(void)signal(SIGPIPE, lostconn); |
|
(void)signal(SIGINFO, got_siginfo); |
|
|
if ((targ = colon(argv[argc - 1])) != NULL)/* Dest is remote host. */ |
if ((targ = colon(argv[argc - 1])) != NULL)/* Dest is remote host. */ |
toremote(targ, argc, argv); |
toremote(targ, argc, argv); |
Line 385 next: (void)close(fd); |
|
Line 391 next: (void)close(fd); |
|
/* Keep writing after an error so that we stay sync'd up. */ |
/* Keep writing after an error so that we stay sync'd up. */ |
haderr = 0; |
haderr = 0; |
for (i = 0; i < stb.st_size; i += bp->cnt) { |
for (i = 0; i < stb.st_size; i += bp->cnt) { |
|
if (print_info) |
|
progress(name, i, stb.st_size); |
amt = bp->cnt; |
amt = bp->cnt; |
if (i + amt > stb.st_size) |
if (i + amt > stb.st_size) |
amt = stb.st_size - i; |
amt = stb.st_size - i; |
Line 658 bad: run_err("%s: %s", np, strerror(er |
|
Line 666 bad: run_err("%s: %s", np, strerror(er |
|
|
|
count = 0; |
count = 0; |
for (i = 0; i < size; i += BUFSIZ) { |
for (i = 0; i < size; i += BUFSIZ) { |
|
if (print_info) |
|
progress(np, i, size); |
amt = BUFSIZ; |
amt = BUFSIZ; |
if (i + amt > size) |
if (i + amt > size) |
amt = size - i; |
amt = size - i; |
Line 809 run_err(const char *fmt, ...) |
|
Line 819 run_err(const char *fmt, ...) |
|
va_end(ap); |
va_end(ap); |
} |
} |
} |
} |
|
|
|
static void |
|
got_siginfo(int signo) |
|
{ |
|
|
|
print_info = 1; |
|
} |
|
|
|
static void |
|
progress(const char *file, uintmax_t done, uintmax_t total) |
|
{ |
|
static int ttyfd = -2; |
|
const double pcent = (100.0 * done) / total; |
|
char buf[2048]; |
|
int n; |
|
|
|
if (ttyfd == -2) |
|
ttyfd = open(_PATH_TTY, O_RDWR | O_CLOEXEC); |
|
|
|
if (ttyfd == -1) |
|
return; |
|
|
|
n = snprintf(buf, sizeof(buf), |
|
"%s: %s: %ju/%ju bytes %3.2f%% written\n", |
|
getprogname(), file, done, total, pcent); |
|
|
|
if (n < 0) |
|
return; |
|
|
|
write(ttyfd, buf, (size_t)n); |
|
|
|
print_info = 0; |
|
} |