A few updates (including the cp fix the Craig has been looking for)

-Erik
This commit is contained in:
Erik Andersen
2000-03-04 21:19:32 +00:00
parent 7c4b2f3fe5
commit 029011b9ee
34 changed files with 850 additions and 409 deletions

View File

@@ -59,3 +59,11 @@ extern int cat_main(int argc, char **argv)
}
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

View File

@@ -65,3 +65,12 @@ int chroot_main(int argc, char **argv)
*argv, strerror(errno));
exit(FALSE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

View File

@@ -108,3 +108,11 @@ extern int df_main(int argc, char **argv)
exit(TRUE);
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

View File

@@ -36,16 +36,6 @@
typedef void (Display) (long, char *);
typedef struct inode_type {
struct inode_type *next;
ino_t ino;
} INODETYPE;
#define HASH_SIZE 311 /* Should be prime */
#define hash_inode(i) ((i) % HASH_SIZE)
static INODETYPE *inode_hash_list[HASH_SIZE];
static const char du_usage[] =
"du [OPTION]... [FILE]...\n\n"
"Summarize disk space used for each FILE and/or directory.\n"
@@ -71,52 +61,6 @@ static void print_summary(long size, char *filename)
}
}
/* Return 1 if inode is in inode hash list, else return 0 */
static int is_in_list(const ino_t ino)
{
INODETYPE *inode;
inode = inode_hash_list[hash_inode(ino)];
while (inode != NULL) {
if (inode->ino == ino)
return 1;
inode = inode->next;
}
return 0;
}
/* Add inode to inode hash list */
static void add_inode(const ino_t ino)
{
int i;
INODETYPE *inode;
i = hash_inode(ino);
inode = malloc(sizeof(INODETYPE));
if (inode == NULL)
fatalError("du: Not enough memory.");
inode->ino = ino;
inode->next = inode_hash_list[i];
inode_hash_list[i] = inode;
}
/* Clear inode hash list */
static void reset_inode_list(void)
{
int i;
INODETYPE *inode;
for (i = 0; i < HASH_SIZE; i++) {
while (inode_hash_list[i] != NULL) {
inode = inode_hash_list[i]->next;
free(inode_hash_list[i]);
inode_hash_list[i] = inode;
}
}
}
/* tiny recursive du */
static long du(char *filename)
{
@@ -175,13 +119,13 @@ static long du(char *filename)
}
else if (statbuf.st_nlink > 1 && !count_hardlinks) {
/* Add files with hard links only once */
if (is_in_list(statbuf.st_ino)) {
if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
sum = 0L;
if (du_depth == 1)
print(sum, filename);
}
else {
add_inode(statbuf.st_ino);
add_to_ino_dev_hashtable(&statbuf, NULL);
}
}
du_depth--;
@@ -231,11 +175,18 @@ int du_main(int argc, char **argv)
if (sum && isDirectory(argv[i], FALSE, NULL)) {
print_normal(sum, argv[i]);
}
reset_inode_list();
reset_ino_dev_hashtable();
}
}
exit(0);
}
/* $Id: du.c,v 1.15 2000/02/21 17:27:17 erik Exp $ */
/* $Id: du.c,v 1.16 2000/03/04 21:19:32 erik Exp $ */
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

View File

@@ -128,3 +128,11 @@ extern int ln_main(int argc, char **argv)
}
exit TRUE;
}
/*
Local Variables:
c-file-style: "linux"
c-basic-offset: 4
tab-width: 4
End:
*/

View File

@@ -29,7 +29,18 @@
#include <stdio.h>
#include <errno.h>
static const char sort_usage[] = "sort [OPTION]... [FILE]...\n\n";
static const char sort_usage[] = "sort [-n]"
#ifdef BB_FEATURE_SORT_REVERSE
" [-r]"
#endif
" [FILE]...\n\n";
#ifdef BB_FEATURE_SORT_REVERSE
#define APPLY_REVERSE(x) (reverse ? -(x) : (x))
static int reverse = 0;
#else
#define APPLY_REVERSE(x) (x)
#endif
/* typedefs _______________________________________________________________ */
@@ -120,7 +131,7 @@ static int compare_ascii(const void *a, const void *b)
y = *doh;
// fprintf(stdout, "> %p: %s< %p: %s", x, x->data, y, y->data);
return strcmp(x->data, y->data);
return APPLY_REVERSE(strcmp(x->data, y->data));
}
/* numeric order */
@@ -138,7 +149,7 @@ static int compare_numeric(const void *a, const void *b)
xint = strtoul(x->data, NULL, 10);
yint = strtoul(y->data, NULL, 10);
return (xint - yint);
return APPLY_REVERSE(xint - yint);
}
@@ -254,20 +265,19 @@ int sort_main(int argc, char **argv)
if (argv[i][0] == '-') {
opt = argv[i][1];
switch (opt) {
case 'g':
/* what's the diff between -g && -n? */
compare = compare_numeric;
break;
case 'h':
usage(sort_usage);
break;
case 'n':
/* what's the diff between -g && -n? */
/* numeric comparison */
compare = compare_numeric;
break;
#ifdef BB_FEATURE_SORT_REVERSE
case 'r':
/* reverse */
reverse = 1;
break;
#endif
default:
fprintf(stderr, "sort: invalid option -- %c\n", opt);
usage(sort_usage);
@@ -310,4 +320,4 @@ int sort_main(int argc, char **argv)
exit(0);
}
/* $Id: sort.c,v 1.11 2000/02/08 19:58:47 erik Exp $ */
/* $Id: sort.c,v 1.12 2000/03/04 21:19:32 erik Exp $ */