version 1.57, 2014/05/20 01:25:23 |
version 1.58, 2015/01/16 06:40:15 |
|
|
* SUCH DAMAGE. |
* SUCH DAMAGE. |
*/ |
*/ |
|
|
#include <sys/param.h> |
#include <sys/param.h> /* MAXBSIZE */ |
#include <sys/wait.h> |
#include <sys/wait.h> |
#include <sys/mman.h> |
#include <sys/mman.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
|
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
#include <limits.h> |
#include <sysexits.h> |
#include <sysexits.h> |
#include <utime.h> |
#include <utime.h> |
|
|
#include "pathnames.h" |
#include "pathnames.h" |
|
|
|
#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b)) |
|
|
#define DIRECTORY 0x01 /* Tell install it's a directory. */ |
#define DIRECTORY 0x01 /* Tell install it's a directory. */ |
#define SETFLAGS 0x02 /* Tell install to set flags. */ |
#define SETFLAGS 0x02 /* Tell install to set flags. */ |
#define NOCHANGEBITS (UF_IMMUTABLE | UF_APPEND | SF_IMMUTABLE | SF_APPEND) |
#define NOCHANGEBITS (UF_IMMUTABLE | UF_APPEND | SF_IMMUTABLE | SF_APPEND) |
|
|
struct group *gp; |
struct group *gp; |
int dobackup, docompare, dodir, dopreserve, dostrip, safecopy; |
int dobackup, docompare, dodir, dopreserve, dostrip, safecopy; |
int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; |
int mode = S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH; |
char pathbuf[MAXPATHLEN], tempfile[MAXPATHLEN]; |
char pathbuf[PATH_MAX], tempfile[PATH_MAX]; |
char *suffix = BACKUP_SUFFIX; |
char *suffix = BACKUP_SUFFIX; |
uid_t uid; |
uid_t uid; |
gid_t gid; |
gid_t gid; |
|
|
if (to_sb.st_flags & (NOCHANGEBITS)) |
if (to_sb.st_flags & (NOCHANGEBITS)) |
(void)chflags(to_name, to_sb.st_flags & ~(NOCHANGEBITS)); |
(void)chflags(to_name, to_sb.st_flags & ~(NOCHANGEBITS)); |
if (dobackup) { |
if (dobackup) { |
char backup[MAXPATHLEN]; |
char backup[PATH_MAX]; |
(void)snprintf(backup, MAXPATHLEN, "%s%s", to_name, |
(void)snprintf(backup, PATH_MAX, "%s%s", to_name, |
suffix); |
suffix); |
/* It is ok for the target file not to exist. */ |
/* It is ok for the target file not to exist. */ |
if (rename(to_name, backup) < 0 && errno != ENOENT) { |
if (rename(to_name, backup) < 0 && errno != ENOENT) { |
|
|
from_off = to_off = (off_t)0; |
from_off = to_off = (off_t)0; |
remainder = from_len; |
remainder = from_len; |
do { |
do { |
length = MIN(remainder, 8 * 1048576); |
length = MINIMUM(remainder, 8 * 1048576); |
remainder -= length; |
remainder -= length; |
|
|
if ((p1 = mmap(NULL, length, PROT_READ, MAP_PRIVATE, |
if ((p1 = mmap(NULL, length, PROT_READ, MAP_PRIVATE, |
|
|
int |
int |
create_newfile(char *path, struct stat *sbp) |
create_newfile(char *path, struct stat *sbp) |
{ |
{ |
char backup[MAXPATHLEN]; |
char backup[PATH_MAX]; |
|
|
/* |
/* |
* Unlink now... avoid ETXTBSY errors later. Try and turn |
* Unlink now... avoid ETXTBSY errors later. Try and turn |
|
|
(void)chflags(path, sbp->st_flags & ~(NOCHANGEBITS)); |
(void)chflags(path, sbp->st_flags & ~(NOCHANGEBITS)); |
|
|
if (dobackup) { |
if (dobackup) { |
(void)snprintf(backup, MAXPATHLEN, "%s%s", path, suffix); |
(void)snprintf(backup, PATH_MAX, "%s%s", path, suffix); |
/* It is ok for the target file not to exist. */ |
/* It is ok for the target file not to exist. */ |
if (rename(path, backup) < 0 && errno != ENOENT) |
if (rename(path, backup) < 0 && errno != ENOENT) |
err(EX_OSERR, "rename: %s to %s (errno %d)", path, backup, errno); |
err(EX_OSERR, "rename: %s to %s (errno %d)", path, backup, errno); |
|
|
* only examine up to the end of the current file block or |
* only examine up to the end of the current file block or |
* remaining characters to write, whatever is smaller |
* remaining characters to write, whatever is smaller |
*/ |
*/ |
wcnt = MIN(cnt, *rem); |
wcnt = MINIMUM(cnt, *rem); |
cnt -= wcnt; |
cnt -= wcnt; |
*rem -= wcnt; |
*rem -= wcnt; |
if (*isempt) { |
if (*isempt) { |