mirror of
https://github.com/sheumann/hush.git
synced 2024-12-22 14:30:31 +00:00
Patch from Vladimir to use last_char_is to simplify du.c
This commit is contained in:
parent
8f3e51b4ad
commit
04b0354d8e
@ -76,7 +76,6 @@ static long du(char *filename)
|
|||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
long sum;
|
long sum;
|
||||||
int len;
|
|
||||||
|
|
||||||
if ((lstat(filename, &statbuf)) != 0) {
|
if ((lstat(filename, &statbuf)) != 0) {
|
||||||
perror_msg("%s", filename);
|
perror_msg("%s", filename);
|
||||||
@ -95,6 +94,7 @@ static long du(char *filename)
|
|||||||
if (S_ISDIR(statbuf.st_mode)) {
|
if (S_ISDIR(statbuf.st_mode)) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
|
char *newfile;
|
||||||
|
|
||||||
dir = opendir(filename);
|
dir = opendir(filename);
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
@ -102,12 +102,11 @@ static long du(char *filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = strlen(filename);
|
newfile = last_char_is(filename, '/');
|
||||||
if (filename[len - 1] == '/')
|
if (newfile)
|
||||||
filename[--len] = '\0';
|
*newfile = '\0';
|
||||||
|
|
||||||
while ((entry = readdir(dir))) {
|
while ((entry = readdir(dir))) {
|
||||||
char *newfile;
|
|
||||||
char *name = entry->d_name;
|
char *name = entry->d_name;
|
||||||
|
|
||||||
if ((strcmp(name, "..") == 0)
|
if ((strcmp(name, "..") == 0)
|
||||||
@ -188,7 +187,7 @@ int du_main(int argc, char **argv)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: du.c,v 1.46 2001/05/03 04:45:40 kraai Exp $ */
|
/* $Id: du.c,v 1.47 2001/05/07 22:49:43 andersen Exp $ */
|
||||||
/*
|
/*
|
||||||
Local Variables:
|
Local Variables:
|
||||||
c-file-style: "linux"
|
c-file-style: "linux"
|
||||||
|
11
du.c
11
du.c
@ -76,7 +76,6 @@ static long du(char *filename)
|
|||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
long sum;
|
long sum;
|
||||||
int len;
|
|
||||||
|
|
||||||
if ((lstat(filename, &statbuf)) != 0) {
|
if ((lstat(filename, &statbuf)) != 0) {
|
||||||
perror_msg("%s", filename);
|
perror_msg("%s", filename);
|
||||||
@ -95,6 +94,7 @@ static long du(char *filename)
|
|||||||
if (S_ISDIR(statbuf.st_mode)) {
|
if (S_ISDIR(statbuf.st_mode)) {
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent *entry;
|
struct dirent *entry;
|
||||||
|
char *newfile;
|
||||||
|
|
||||||
dir = opendir(filename);
|
dir = opendir(filename);
|
||||||
if (!dir) {
|
if (!dir) {
|
||||||
@ -102,12 +102,11 @@ static long du(char *filename)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
len = strlen(filename);
|
newfile = last_char_is(filename, '/');
|
||||||
if (filename[len - 1] == '/')
|
if (newfile)
|
||||||
filename[--len] = '\0';
|
*newfile = '\0';
|
||||||
|
|
||||||
while ((entry = readdir(dir))) {
|
while ((entry = readdir(dir))) {
|
||||||
char *newfile;
|
|
||||||
char *name = entry->d_name;
|
char *name = entry->d_name;
|
||||||
|
|
||||||
if ((strcmp(name, "..") == 0)
|
if ((strcmp(name, "..") == 0)
|
||||||
@ -188,7 +187,7 @@ int du_main(int argc, char **argv)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: du.c,v 1.46 2001/05/03 04:45:40 kraai Exp $ */
|
/* $Id: du.c,v 1.47 2001/05/07 22:49:43 andersen Exp $ */
|
||||||
/*
|
/*
|
||||||
Local Variables:
|
Local Variables:
|
||||||
c-file-style: "linux"
|
c-file-style: "linux"
|
||||||
|
Loading…
Reference in New Issue
Block a user