Added cmp and readlink applets from Matt Kraai.

This commit is contained in:
Mark Whitley 2000-10-09 18:56:47 +00:00
parent 7a86e61a54
commit 872138de50
11 changed files with 286 additions and 2 deletions

View File

@ -14,6 +14,7 @@
#define BB_CHROOT
#define BB_CHVT
#define BB_CLEAR
#define BB_CMP
#define BB_CP_MV
#define BB_CUT
#define BB_DATE
@ -76,6 +77,7 @@
#define BB_PS
#define BB_PWD
#define BB_RDATE
#define BB_READLINK
#define BB_REBOOT
#define BB_RENICE
#define BB_RESET

View File

@ -40,6 +40,9 @@ const struct BB_applet applets[] = {
#ifdef BB_CHVT
{"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
#endif
#ifdef BB_CMP
{"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage},
#endif
#ifdef BB_CP_MV
{"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
#endif
@ -235,6 +238,9 @@ const struct BB_applet applets[] = {
#ifdef BB_RDATE
{"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
#endif
#ifdef BB_READLINK
{"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage},
#endif
#ifdef BB_REBOOT
{"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
#endif

View File

@ -93,6 +93,15 @@ const char clear_usage[] =
;
#endif
#if defined BB_CMP
const char cmp_usage[] =
"cmp FILE1 [FILE2]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCompare files.\n"
#endif
;
#endif
#if defined BB_CP_MV
const char cp_usage[] =
"cp [OPTION]... SOURCE DEST\n"
@ -959,6 +968,15 @@ const char rdate_usage[] =
;
#endif
#if defined BB_READLINK
const char readlink_usage[] =
"readlink\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRead a symbolic link.\n"
#endif
;
#endif
#if defined BB_REBOOT
const char reboot_usage[] =
"reboot\n"
@ -967,7 +985,6 @@ const char reboot_usage[] =
#endif
;
#endif
#if defined BB_RENICE
const char renice_usage[] =

View File

@ -40,6 +40,9 @@ const struct BB_applet applets[] = {
#ifdef BB_CHVT
{"chvt", chvt_main, _BB_DIR_USR_BIN, chvt_usage},
#endif
#ifdef BB_CMP
{"cmp", cmp_main, _BB_DIR_USR_BIN, cmp_usage},
#endif
#ifdef BB_CP_MV
{"cp", cp_mv_main, _BB_DIR_BIN, cp_usage},
#endif
@ -235,6 +238,9 @@ const struct BB_applet applets[] = {
#ifdef BB_RDATE
{"rdate", rdate_main, _BB_DIR_USR_BIN, rdate_usage},
#endif
#ifdef BB_READLINK
{"readlink", readlink_main, _BB_DIR_USR_BIN, readlink_usage},
#endif
#ifdef BB_REBOOT
{"reboot", reboot_main, _BB_DIR_SBIN, reboot_usage},
#endif

View File

@ -117,6 +117,7 @@ extern int chmod_chown_chgrp_main(int argc, char** argv);
extern int chroot_main(int argc, char** argv);
extern int chvt_main(int argc, char** argv);
extern int clear_main(int argc, char** argv);
extern int cmp_main(int argc, char** argv);
extern int cp_mv_main(int argc, char** argv);
extern int cut_main(int argc, char** argv);
extern int date_main(int argc, char** argv);
@ -181,6 +182,7 @@ extern int printf_main(int argc, char** argv);
extern int ps_main(int argc, char** argv);
extern int pwd_main(int argc, char** argv);
extern int rdate_main(int argc, char** argv);
extern int readlink_main(int argc, char** argv);
extern int reboot_main(int argc, char** argv);
extern int renice_main(int argc, char** argv);
extern int reset_main(int argc, char** argv);
@ -233,6 +235,7 @@ extern const char chown_usage[];
extern const char chroot_usage[];
extern const char chvt_usage[];
extern const char clear_usage[];
extern const char cmp_usage[];
extern const char cp_usage[];
extern const char cut_usage[];
extern const char date_usage[];
@ -294,6 +297,7 @@ extern const char printf_usage[];
extern const char ps_usage[];
extern const char pwd_usage[];
extern const char rdate_usage[];
extern const char readlink_usage[];
extern const char reboot_usage[];
extern const char renice_usage[];
extern const char reset_usage[];

65
cmp.c Normal file
View File

@ -0,0 +1,65 @@
/* vi: set sw=4 ts=4: */
/*
* Mini cmp implementation for busybox
*
*
* Copyright (C) 2000 by Lineo, inc.
* Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
*
* 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 "busybox.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
int cmp_main(int argc, char **argv)
{
FILE *fp1 = NULL, *fp2 = stdin;
char *filename1 = argv[1], *filename2 = "-";
int c1, c2, char_pos = 1, line_pos = 1;
/* parse argv[] */
if (argc < 2 || 3 < argc)
usage(cmp_usage);
fp1 = xfopen(argv[1], "r");
if (argv[2] != NULL) {
fp2 = xfopen(argv[2], "r");
filename2 = argv[2];
}
do {
c1 = fgetc(fp1);
c2 = fgetc(fp2);
if (c1 != c2) {
if (c1 == EOF)
printf("EOF on %s\n", filename1);
else if (c2 == EOF)
printf("EOF on %s\n", filename2);
else
printf("%s %s differ: char %d, line %d\n", filename1, filename2,
char_pos, line_pos);
return 1;
}
char_pos++;
if (c1 == '\n')
line_pos++;
} while (c1 != EOF);
return EXIT_SUCCESS;
}

65
coreutils/cmp.c Normal file
View File

@ -0,0 +1,65 @@
/* vi: set sw=4 ts=4: */
/*
* Mini cmp implementation for busybox
*
*
* Copyright (C) 2000 by Lineo, inc.
* Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
*
* 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 "busybox.h"
#include <stdio.h>
#include <string.h>
#include <errno.h>
int cmp_main(int argc, char **argv)
{
FILE *fp1 = NULL, *fp2 = stdin;
char *filename1 = argv[1], *filename2 = "-";
int c1, c2, char_pos = 1, line_pos = 1;
/* parse argv[] */
if (argc < 2 || 3 < argc)
usage(cmp_usage);
fp1 = xfopen(argv[1], "r");
if (argv[2] != NULL) {
fp2 = xfopen(argv[2], "r");
filename2 = argv[2];
}
do {
c1 = fgetc(fp1);
c2 = fgetc(fp2);
if (c1 != c2) {
if (c1 == EOF)
printf("EOF on %s\n", filename1);
else if (c2 == EOF)
printf("EOF on %s\n", filename2);
else
printf("%s %s differ: char %d, line %d\n", filename1, filename2,
char_pos, line_pos);
return 1;
}
char_pos++;
if (c1 == '\n')
line_pos++;
} while (c1 != EOF);
return EXIT_SUCCESS;
}

View File

@ -117,6 +117,7 @@ extern int chmod_chown_chgrp_main(int argc, char** argv);
extern int chroot_main(int argc, char** argv);
extern int chvt_main(int argc, char** argv);
extern int clear_main(int argc, char** argv);
extern int cmp_main(int argc, char** argv);
extern int cp_mv_main(int argc, char** argv);
extern int cut_main(int argc, char** argv);
extern int date_main(int argc, char** argv);
@ -181,6 +182,7 @@ extern int printf_main(int argc, char** argv);
extern int ps_main(int argc, char** argv);
extern int pwd_main(int argc, char** argv);
extern int rdate_main(int argc, char** argv);
extern int readlink_main(int argc, char** argv);
extern int reboot_main(int argc, char** argv);
extern int renice_main(int argc, char** argv);
extern int reset_main(int argc, char** argv);
@ -233,6 +235,7 @@ extern const char chown_usage[];
extern const char chroot_usage[];
extern const char chvt_usage[];
extern const char clear_usage[];
extern const char cmp_usage[];
extern const char cp_usage[];
extern const char cut_usage[];
extern const char date_usage[];
@ -294,6 +297,7 @@ extern const char printf_usage[];
extern const char ps_usage[];
extern const char pwd_usage[];
extern const char rdate_usage[];
extern const char readlink_usage[];
extern const char reboot_usage[];
extern const char renice_usage[];
extern const char reset_usage[];

49
miscutils/readlink.c Normal file
View File

@ -0,0 +1,49 @@
/* vi: set sw=4 ts=4: */
/*
* Mini readlink implementation for busybox
*
*
* Copyright (C) 2000 by Lineo, inc.
* Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
*
* 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 "busybox.h"
#include <errno.h>
#include <unistd.h>
int readlink_main(int argc, char **argv)
{
char *buf = NULL;
int bufsize = 128, size = 128;
if (argc != 2)
usage(readlink_usage);
while (bufsize < size + 1) {
bufsize *= 2;
buf = xrealloc(buf, bufsize);
size = readlink(argv[1], buf, bufsize);
if (size == -1)
fatalError("%s: %s\n", argv[1], strerror(errno));
}
buf[size] = '\0';
puts(buf);
return EXIT_SUCCESS;
}

49
readlink.c Normal file
View File

@ -0,0 +1,49 @@
/* vi: set sw=4 ts=4: */
/*
* Mini readlink implementation for busybox
*
*
* Copyright (C) 2000 by Lineo, inc.
* Written by Matt Kraai <kraai@alumni.carnegiemellon.edu>
*
* 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 "busybox.h"
#include <errno.h>
#include <unistd.h>
int readlink_main(int argc, char **argv)
{
char *buf = NULL;
int bufsize = 128, size = 128;
if (argc != 2)
usage(readlink_usage);
while (bufsize < size + 1) {
bufsize *= 2;
buf = xrealloc(buf, bufsize);
size = readlink(argv[1], buf, bufsize);
if (size == -1)
fatalError("%s: %s\n", argv[1], strerror(errno));
}
buf[size] = '\0';
puts(buf);
return EXIT_SUCCESS;
}

19
usage.c
View File

@ -93,6 +93,15 @@ const char clear_usage[] =
;
#endif
#if defined BB_CMP
const char cmp_usage[] =
"cmp FILE1 [FILE2]\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nCompare files.\n"
#endif
;
#endif
#if defined BB_CP_MV
const char cp_usage[] =
"cp [OPTION]... SOURCE DEST\n"
@ -959,6 +968,15 @@ const char rdate_usage[] =
;
#endif
#if defined BB_READLINK
const char readlink_usage[] =
"readlink\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
"\nRead a symbolic link.\n"
#endif
;
#endif
#if defined BB_REBOOT
const char reboot_usage[] =
"reboot\n"
@ -967,7 +985,6 @@ const char reboot_usage[] =
#endif
;
#endif
#if defined BB_RENICE
const char renice_usage[] =