Sort includes and more cleanup and fixes in util/

This commit is contained in:
FRIGN
2014-11-13 19:54:28 +01:00
committed by sin
parent 0810c61154
commit 7d2683ddf2
48 changed files with 181 additions and 173 deletions

View File

@@ -37,20 +37,20 @@ cp(const char *s1, const char *s2)
DIR *dp;
int r;
if(cp_vflag)
if (cp_vflag)
printf("'%s' -> '%s'\n", s1, s2);
if(cp_dflag == true)
if (cp_dflag == true)
r = lstat(s1, &st);
else
r = stat(s1, &st);
if(r == 0) {
if(cp_dflag == true && S_ISLNK(st.st_mode)) {
if(readlink(s1, buf, sizeof(buf) - 1) >= 0) {
if(cp_fflag == true);
if (r == 0) {
if (cp_dflag == true && S_ISLNK(st.st_mode)) {
if (readlink(s1, buf, sizeof(buf) - 1) >= 0) {
if (cp_fflag == true);
unlink(s2);
if(symlink(buf, s2) != 0) {
if (symlink(buf, s2) != 0) {
weprintf("%s: can't create '%s'\n", argv0, s2);
cp_status = 1;
return 0;
@@ -58,11 +58,11 @@ cp(const char *s1, const char *s2)
}
goto preserve;
}
if(S_ISDIR(st.st_mode)) {
if (S_ISDIR(st.st_mode)) {
if (!cp_rflag)
eprintf("%s: is a directory\n", s1);
if(!(dp = opendir(s1)))
if (!(dp = opendir(s1)))
eprintf("opendir %s:", s1);
if (mkdir(s2, st.st_mode) == -1 && errno != EEXIST)
@@ -70,15 +70,15 @@ cp(const char *s1, const char *s2)
apathmax(&ns1, &size1);
apathmax(&ns2, &size2);
while((d = readdir(dp))) {
if(strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) {
while ((d = readdir(dp))) {
if (strcmp(d->d_name, ".") && strcmp(d->d_name, "..")) {
r = snprintf(ns1, size1, "%s/%s", s1, d->d_name);
if(r >= size1 || r < 0) {
if (r >= size1 || r < 0) {
eprintf("%s/%s: filename too long\n",
s1, d->d_name);
}
r = snprintf(ns2, size2, "%s/%s", s2, d->d_name);
if(r >= size2 || r < 0) {
if (r >= size2 || r < 0) {
eprintf("%s/%s: filename too long\n",
s2, d->d_name);
}
@@ -92,11 +92,11 @@ cp(const char *s1, const char *s2)
}
}
if(cp_aflag == true) {
if(S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode) ||
if (cp_aflag == true) {
if (S_ISBLK(st.st_mode) || S_ISCHR(st.st_mode) ||
S_ISSOCK(st.st_mode) || S_ISFIFO(st.st_mode)) {
unlink(s2);
if(mknod(s2, st.st_mode, st.st_rdev) < 0) {
if (mknod(s2, st.st_mode, st.st_rdev) < 0) {
weprintf("%s: can't create '%s':", argv0, s2);
cp_status = 1;
return 0;
@@ -105,16 +105,16 @@ cp(const char *s1, const char *s2)
}
}
if(!(f1 = fopen(s1, "r"))) {
if (!(f1 = fopen(s1, "r"))) {
weprintf("fopen %s:", s1);
cp_status = 1;
return 0;
}
if(!(f2 = fopen(s2, "w"))) {
if (!(f2 = fopen(s2, "w"))) {
if (cp_fflag == true) {
unlink(s2);
if(!(f2 = fopen(s2, "w"))) {
if (!(f2 = fopen(s2, "w"))) {
weprintf("fopen %s:", s2);
cp_status = 1;
return 0;
@@ -131,19 +131,19 @@ cp(const char *s1, const char *s2)
fclose(f1);
preserve:
if(cp_aflag == true || cp_pflag == true) {
if(!(S_ISLNK(st.st_mode))) {
if (cp_aflag == true || cp_pflag == true) {
if (!(S_ISLNK(st.st_mode))) {
/* timestamp */
ut.actime = st.st_atime;
ut.modtime = st.st_mtime;
utime(s2, &ut);
}
/* preserve owner ? */
if(S_ISLNK(st.st_mode))
if (S_ISLNK(st.st_mode))
r = lchown(s2, st.st_uid, st.st_gid);
else
r = chown(s2, st.st_uid, st.st_gid);
if(r == -1) {
if (r == -1) {
weprintf("cp: can't preserve ownership of '%s':", s2);
cp_status = 1;
}