A few minor updates. ;-)

Seriously though, read the Changelog for busybox 0.42,
which this is about to become...
 -Erik
This commit is contained in:
Erik Andersen
2000-02-07 05:29:42 +00:00
parent 50bc101b7d
commit fac10d7c59
76 changed files with 1849 additions and 1023 deletions

View File

@@ -1,127 +0,0 @@
/*
* Mini cp implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
"\n"
"\t-a\tsame as -dpR\n"
"\t-d\tpreserve links\n"
"\t-p\tpreserve file attributes if possible\n"
"\t-R\tcopy directories recursively\n";
static int recursiveFlag = FALSE;
static int followLinks = FALSE;
static int preserveFlag = FALSE;
static const char *srcName;
static const char *destName;
static int destDirFlag = FALSE;
static int srcDirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
char* newsrcName = NULL;
strcpy(newdestName, destName);
if ( srcDirFlag == TRUE ) {
if (recursiveFlag!=TRUE ) {
fprintf(stderr, "cp: %s: omitting directory\n", srcName);
return( TRUE);
}
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
}
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
if (newdestName[strlen(newdestName)-1] != '/' ) {
strcat(newdestName, "/");
}
newsrcName = strrchr(srcName, '/');
if (newsrcName && *newsrcName != '\0')
strcat(newdestName, newsrcName);
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
}
extern int cp_main(int argc, char **argv)
{
if (argc < 3) {
usage (cp_usage);
}
argc--;
argv++;
/* Parse any options */
while (**argv == '-') {
while (*++(*argv))
switch (**argv) {
case 'a':
followLinks = TRUE;
preserveFlag = TRUE;
recursiveFlag = TRUE;
break;
case 'd':
followLinks = TRUE;
break;
case 'p':
preserveFlag = TRUE;
break;
case 'R':
recursiveFlag = TRUE;
break;
default:
usage (cp_usage);
}
argc--;
argv++;
}
destName = argv[argc - 1];
destDirFlag = isDirectory(destName);
if ((argc > 3) && destDirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- > 1) {
srcName = *(argv++);
srcDirFlag = isDirectory(srcName);
if (recursiveAction(srcName, recursiveFlag, followLinks, FALSE,
fileAction, fileAction) == FALSE) {
exit( FALSE);
}
}
exit( TRUE);
}

View File

@@ -20,6 +20,10 @@
*/
#include "internal.h"
#define BB_DECLARE_EXTERN
#define bb_need_invalid_date
#define bb_need_memory_exhausted
#include "messages.c"
#include <stdlib.h>
#include <errno.h>
#include <sys/time.h>
@@ -59,7 +63,7 @@ date_conv_time(struct tm *tm_time, const char *t_string) {
&(tm_time->tm_year));
if(nr < 4 || nr > 5) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
fprintf(stderr, invalid_date, "date", t_string);
exit( FALSE);
}
@@ -152,7 +156,7 @@ date_conv_ftime(struct tm *tm_time, const char *t_string) {
}
fprintf(stderr, "date: invalid date `%s'\n", t_string);
fprintf(stderr, invalid_date, "date", t_string);
exit( FALSE);
@@ -190,7 +194,7 @@ date_main(int argc, char * * argv)
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
fprintf(stderr, memory_exhausted, "date");
exit( FALSE);
}
/* Look ma, no break. Don't fix it either. */
@@ -204,10 +208,10 @@ date_main(int argc, char * * argv)
}
} else {
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
date_fmt = *argv;
date_fmt=*argv;
else if (date_str == NULL) {
set_time = 1;
date_str = *argv;
date_str=*argv;
} else {
usage ( date_usage);
}
@@ -241,7 +245,7 @@ date_main(int argc, char * * argv)
/* Correct any day of week and day of year etc fields */
tm = mktime(&tm_time);
if (tm < 0 ) {
fprintf(stderr, "date: invalid date `%s'\n", date_str);
fprintf(stderr, invalid_date, "date", date_str);
exit( FALSE);
}
@@ -284,4 +288,3 @@ date_main(int argc, char * * argv)
exit( TRUE);
}

View File

@@ -40,15 +40,16 @@ typedef unsigned long long int uintmax_t;
#endif
static const char dd_usage[] =
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
"dd [if=name] [of=name] [bs=n] [count=n] [skip=n] [seek=n]\n\n"
"Copy a file, converting and formatting according to options\n\n"
"\tif=FILE\tread from FILE instead of stdin\n"
"\tof=FILE\twrite to FILE instead of stout\n"
"\tbs=n\tread and write N BYTES at a time\n"
"\tof=FILE\twrite to FILE instead of stdout\n"
"\tbs=n\tread and write n bytes at a time\n"
"\tcount=n\tcopy only n input blocks\n"
//"\tskip=n\tskip n input blocks\n"
"\tskip=n\tskip n input blocks\n"
"\tseek=n\tskip n output blocks\n"
"\n"
"BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n";
"Numbers may be suffixed by w (x2), k (x1024), b (x512), or M (x1024^2)\n";
@@ -61,8 +62,9 @@ extern int dd_main (int argc, char **argv)
int outFd;
int inCc = 0;
int outCc;
size_t blockSize = 512;
//uintmax_t skipBlocks = 0;
long blockSize = 512;
uintmax_t skipBlocks = 0;
uintmax_t seekBlocks = 0;
uintmax_t count = (uintmax_t)-1;
uintmax_t intotal;
uintmax_t outTotal;
@@ -91,16 +93,22 @@ extern int dd_main (int argc, char **argv)
goto usage;
}
}
#if 0
else if (strncmp(*argv, "skip", 4) == 0) {
skipBlocks = atoi( *argv);
skipBlocks = getNum ((strchr(*argv, '='))+1);
if (skipBlocks <= 0) {
fprintf (stderr, "Bad skip value %d\n", skipBlocks);
fprintf (stderr, "Bad skip value %s\n", *argv);
goto usage;
}
}
else if (strncmp(*argv, "seek", 4) == 0) {
seekBlocks = getNum ((strchr(*argv, '='))+1);
if (seekBlocks <= 0) {
fprintf (stderr, "Bad seek value %s\n", *argv);
goto usage;
}
}
#endif
else {
goto usage;
}
@@ -131,7 +139,7 @@ extern int dd_main (int argc, char **argv)
if (outFile == NULL)
outFd = fileno(stdout);
else
outFd = creat (outFile, 0666);
outFd = open(outFile, O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (outFd < 0) {
perror (outFile);
@@ -140,10 +148,11 @@ extern int dd_main (int argc, char **argv)
exit( FALSE);
}
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
lseek(inFd, skipBlocks*blockSize, SEEK_SET);
lseek(outFd, seekBlocks*blockSize, SEEK_SET);
//
//TODO: Convert to using fullRead & fullWrite
// from utilitity.c
// from utility.c
// -Erik
while (outTotal < count * blockSize) {
inCc = read (inFd, buf, blockSize);

View File

@@ -22,17 +22,18 @@
*/
#include "internal.h"
#define BB_DECLARE_EXTERN
#define bb_need_name_too_long
#include "messages.c"
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#if 0
#include <unistd.h>
#include <sys/stat.h>
#endif
#include <sys/param.h> /* for PATH_MAX */
typedef void (Display)(size_t, char *);
typedef void (Display)(long, char *);
static const char du_usage[] =
"du [OPTION]... [FILE]...\n\n"
@@ -44,13 +45,13 @@ static int du_depth = 0;
static Display *print;
static void
print_normal(size_t size, char *filename)
print_normal(long size, char *filename)
{
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
fprintf(stdout, "%-7ld %s\n", size, filename);
}
static void
print_summary(size_t size, char *filename)
print_summary(long size, char *filename)
{
if (du_depth == 1) {
print_normal(size, filename);
@@ -59,11 +60,11 @@ print_summary(size_t size, char *filename)
/* tiny recursive du */
static size_t
static long
du(char *filename)
{
struct stat statbuf;
size_t sum;
long sum;
if ((lstat(filename, &statbuf)) != 0) {
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
@@ -80,14 +81,19 @@ du(char *filename)
dir = opendir(filename);
if (!dir) { return 0; }
while ((entry = readdir(dir))) {
char newfile[512];
char newfile[PATH_MAX + 1];
char *name = entry->d_name;
if ( (strcmp(name, "..") == 0)
|| (strcmp(name, ".") == 0))
{ continue; }
if (strlen(filename) + strlen(name) + 1 > PATH_MAX) {
fprintf(stderr, name_too_long, "du");
return 0;
}
sprintf(newfile, "%s/%s", filename, name);
sum += du(newfile);
}
closedir(dir);
@@ -130,14 +136,14 @@ du_main(int argc, char **argv)
if (i >= argc) {
du(".");
} else {
int sum;
long sum;
for ( ; i < argc; i++) {
sum = du(argv[i]);
if ((sum) && (isDirectory(argv[i]))) { print_normal(sum, argv[i]); }
if ((sum) && (isDirectory(argv[i], FALSE))) { print_normal(sum, argv[i]); }
}
}
exit(0);
}
/* $Id: du.c,v 1.9 2000/01/23 18:19:02 erik Exp $ */
/* $Id: du.c,v 1.10 2000/02/07 05:29:42 erik Exp $ */

View File

@@ -105,4 +105,4 @@ head_main(int argc, char **argv)
exit(0);
}
/* $Id: head.c,v 1.6 2000/01/25 18:13:53 erik Exp $ */
/* $Id: head.c,v 1.7 2000/02/07 05:29:42 erik Exp $ */

View File

@@ -6,7 +6,7 @@
extern int
length_main(int argc, char * * argv)
{
if ( **(argv+1) == '-' ) {
if ( argc != 2 || **(argv+1) == '-' ) {
usage("length string\n");
}
printf("%d\n", strlen(argv[1]));

View File

@@ -22,26 +22,32 @@
*/
#include "internal.h"
#define BB_DECLARE_EXTERN
#define bb_need_name_too_long
#define bb_need_not_a_directory
#include "messages.c"
#include <stdio.h>
#include <dirent.h>
#include <errno.h>
#include <sys/param.h> /* for PATH_MAX */
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"Options:\n"
"\t-s\tmake symbolic links instead of hard links\n"
"\t-f\tremove existing destination files\n";
static const char ln_usage[] =
"ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
"Options:\n"
"\t-s\tmake symbolic links instead of hard links\n"
"\t-f\tremove existing destination files\n"
"\t-n\tno dereference symlinks - treat like normal file\n";
static int symlinkFlag = FALSE;
static int removeoldFlag = FALSE;
static int followLinks = TRUE;
extern int ln_main(int argc, char **argv)
{
int status;
static char* linkName;
char *linkName;
int linkIntoDirFlag;
if (argc < 3) {
usage (ln_usage);
@@ -59,6 +65,9 @@ extern int ln_main(int argc, char **argv)
case 'f':
removeoldFlag = TRUE;
break;
case 'n':
followLinks = FALSE;
break;
default:
usage (ln_usage);
}
@@ -66,30 +75,54 @@ extern int ln_main(int argc, char **argv)
argv++;
}
linkName = argv[argc - 1];
if ((argc > 3) && !(isDirectory(linkName))) {
fprintf(stderr, "%s: not a directory\n", linkName);
exit (FALSE);
if (strlen(linkName) > PATH_MAX) {
fprintf(stderr, name_too_long, "ln");
exit FALSE;
}
linkIntoDirFlag = isDirectory(linkName, TRUE);
if ((argc > 3) && !linkIntoDirFlag) {
fprintf(stderr, not_a_directory, "ln", linkName);
exit FALSE;
}
while (argc-- >= 2) {
if (removeoldFlag==TRUE ) {
char srcName[PATH_MAX + 1];
int nChars, status;
if (strlen(*argv) > PATH_MAX) {
fprintf(stderr, name_too_long, "ln");
exit FALSE;
}
if (followLinks == FALSE) {
strcpy(srcName, *argv);
} else {
/* Warning! This can silently truncate if > PATH_MAX, but
I don't think that there can be one > PATH_MAX anyway. */
nChars = readlink(*argv, srcName, PATH_MAX);
srcName[nChars] = '\0';
}
if (removeoldFlag == TRUE) {
status = ( unlink(linkName) && errno != ENOENT );
if ( status != 0 ) {
if (status != 0) {
perror(linkName);
exit( FALSE);
exit FALSE;
}
}
if ( symlinkFlag==TRUE)
status = symlink(*argv, linkName);
if (symlinkFlag == TRUE)
status = symlink(*argv, linkName);
else
status = link(*argv, linkName);
if ( status != 0 ) {
status = link(*argv, linkName);
if (status != 0) {
perror(linkName);
exit( FALSE);
exit FALSE;
}
}
exit( TRUE);
exit TRUE;
}

View File

@@ -178,7 +178,7 @@ static char append_char(mode_t mode)
static void list_single(const char *name, struct stat *info, const char *fullname)
{
char scratch[PATH_MAX];
char scratch[PATH_MAX + 1];
short len = strlen(name);
#ifdef BB_FEATURE_LS_FILETYPES
char append = append_char(info->st_mode);

View File

@@ -22,9 +22,13 @@
*/
#include "internal.h"
#define bb_need_name_too_long
#define BB_DECLARE_EXTERN
#include "messages.c"
#include <stdio.h>
#include <errno.h>
#include <sys/param.h>
#include <sys/param.h> /* for PATH_MAX */
static const char mkdir_usage[] =
"mkdir [OPTION] DIRECTORY...\n\n"
@@ -40,27 +44,27 @@ static mode_t mode = 0777;
extern int mkdir_main(int argc, char **argv)
{
int i=FALSE;
int i = FALSE;
argc--;
argv++;
/* Parse any options */
while (argc > 0 && **argv == '-') {
while (i==FALSE && *++(*argv)) {
while (i == FALSE && *++(*argv)) {
switch (**argv) {
case 'm':
if (--argc == 0)
usage( mkdir_usage);
/* Find the specified modes */
mode = 0;
if ( parse_mode(*(++argv), &mode) == FALSE ) {
if (parse_mode(*(++argv), &mode) == FALSE ) {
fprintf(stderr, "Unknown mode: %s\n", *argv);
exit( FALSE);
exit FALSE;
}
/* Set the umask for this process so it doesn't
* screw up whatever the user just entered. */
umask(0);
i=TRUE;
i = TRUE;
break;
case 'p':
parentFlag = TRUE;
@@ -73,7 +77,6 @@ extern int mkdir_main(int argc, char **argv)
argv++;
}
if (argc < 1) {
usage( mkdir_usage);
}
@@ -81,13 +84,16 @@ extern int mkdir_main(int argc, char **argv)
while (argc > 0) {
int status;
struct stat statBuf;
char buf[NAME_MAX];
char buf[PATH_MAX + 1];
if (strlen(*argv) > PATH_MAX - 1) {
fprintf(stderr, name_too_long, "mkdir");
exit FALSE;
}
strcpy (buf, *argv);
status=stat(buf, &statBuf);
if (parentFlag == FALSE && status != -1 && status != ENOENT ) {
status = stat(buf, &statBuf);
if (parentFlag == FALSE && status != -1 && errno != ENOENT) {
fprintf(stderr, "%s: File exists\n", buf);
exit( FALSE);
exit FALSE;
}
if (parentFlag == TRUE) {
strcat( buf, "/");
@@ -96,13 +102,13 @@ extern int mkdir_main(int argc, char **argv)
else {
if (mkdir (buf, mode) != 0 && parentFlag == FALSE) {
perror(buf);
exit( FALSE);
exit FALSE;
}
}
argc--;
argv++;
}
exit( TRUE);
exit TRUE;
}

View File

@@ -1,112 +0,0 @@
/*
* Mini mv implementation for busybox
*
*
* Copyright (C) 1999 by Lineo, inc.
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include "internal.h"
#include <stdio.h>
#include <time.h>
#include <utime.h>
#include <dirent.h>
static const char mv_usage[] = "mv SOURCE DEST\n"
" or: mv SOURCE... DIRECTORY\n\n"
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
static const char *srcName;
static const char *destName;
static int destDirFlag = FALSE;
static int srcDirFlag = FALSE;
static int fileAction(const char *fileName, struct stat* statbuf)
{
char newdestName[NAME_MAX];
char* newsrcName = NULL;
strcpy(newdestName, destName);
if ( srcDirFlag == TRUE ) {
strcat(newdestName, strstr(fileName, srcName) + strlen(srcName));
}
if (destDirFlag==TRUE && srcDirFlag == FALSE) {
if (newdestName[strlen(newdestName)-1] != '/' ) {
strcat(newdestName, "/");
}
newsrcName = strrchr(srcName, '/');
if (newsrcName && *newsrcName != '\0')
strcat(newdestName, newsrcName);
else
strcat(newdestName, srcName);
}
return (copyFile(fileName, newdestName, TRUE, TRUE));
}
static int rmfileAction(const char *fileName, struct stat* statbuf)
{
if (unlink( fileName) < 0 ) {
perror( fileName);
return ( FALSE);
}
return ( TRUE);
}
static int rmdirAction(const char *fileName, struct stat* statbuf)
{
if (rmdir( fileName) < 0 ) {
perror( fileName);
return ( FALSE);
}
return ( TRUE);
}
extern int mv_main(int argc, char **argv)
{
if (argc < 3) {
usage (mv_usage);
}
argc--;
argv++;
destName = argv[argc - 1];
destDirFlag = isDirectory(destName);
if ((argc > 3) && destDirFlag==FALSE) {
fprintf(stderr, "%s: not a directory\n", destName);
exit (FALSE);
}
while (argc-- > 1) {
srcName = *(argv++);
srcDirFlag = isDirectory(srcName);
if (recursiveAction(srcName, TRUE, TRUE, FALSE,
fileAction, fileAction) == FALSE) {
exit( FALSE);
}
if (recursiveAction(srcName, TRUE, TRUE, TRUE,
rmfileAction, rmdirAction) == FALSE) {
exit( FALSE);
}
}
exit( TRUE);
}

View File

@@ -143,7 +143,7 @@ printf_main(int argc, char** argv)
int args_used;
exit_status = 0;
if ( **(argv+1) == '-' ) {
if ( argc <= 1 || **(argv+1) == '-' ) {
usage (printf_usage);
}

View File

@@ -23,11 +23,12 @@
#include "internal.h"
#include <stdio.h>
#include <dirent.h>
#include <sys/param.h>
extern int
pwd_main(int argc, char * * argv)
{
char buf[NAME_MAX];
char buf[PATH_MAX + 1];
if ( getcwd(buf, sizeof(buf)) == NULL ) {
perror("get working directory");

View File

@@ -309,4 +309,4 @@ sort_main(int argc, char **argv)
exit(0);
}
/* $Id: sort.c,v 1.9 2000/01/23 18:19:02 erik Exp $ */
/* $Id: sort.c,v 1.10 2000/02/07 05:29:42 erik Exp $ */

View File

@@ -33,7 +33,7 @@
and generally busyboxed, Erik Andersen <andersen@lineo.com>
Removed superfluous options and associated code ("-c", "-n", "-q").
Removed "tail -f" suport for multiple files.
Removed "tail -f" support for multiple files.
Both changes by Friedrich Vedder <fwv@myrtle.lahn.de>.
*/

View File

@@ -123,4 +123,4 @@ tee_main(int argc, char **argv)
exit(0);
}
/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */
/* $Id: tee.c,v 1.5 2000/02/07 05:29:42 erik Exp $ */

View File

@@ -193,4 +193,4 @@ uniq_main(int argc, char **argv)
exit(0);
}
/* $Id: uniq.c,v 1.5 2000/01/23 18:19:02 erik Exp $ */
/* $Id: uniq.c,v 1.6 2000/02/07 05:29:42 erik Exp $ */