Latest and greatest.

-Erik
This commit is contained in:
Eric Andersen 1999-10-12 15:42:48 +00:00
parent f811e07b07
commit 2ce1edcf54
19 changed files with 255 additions and 305 deletions

View File

@ -1,3 +1,6 @@
0.28
mini-netcat (mnc) rewritten.
0.27
Mount now supports -a, and -t auto.
Mount now updates mtab correctly for 'ro'.

View File

@ -189,7 +189,7 @@ int main(int argc, char **argv)
}
a++;
}
return (busybox_main(argc, argv));
exit (busybox_main(argc, argv));
}
@ -216,8 +216,7 @@ int busybox_main(int argc, char **argv)
fprintf(stderr, "\nCurrently defined functions:\n");
while (a->name != 0) {
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), a->name);
a++;
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
if (col>60) {
fprintf(stderr, ",\n");
col=0;

View File

@ -189,7 +189,7 @@ int main(int argc, char **argv)
}
a++;
}
return (busybox_main(argc, argv));
exit (busybox_main(argc, argv));
}
@ -216,8 +216,7 @@ int busybox_main(int argc, char **argv)
fprintf(stderr, "\nCurrently defined functions:\n");
while (a->name != 0) {
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), a->name);
a++;
col+=fprintf(stderr, "%s%s", ((col==0)? "\t":", "), (a++)->name);
if (col>60) {
fprintf(stderr, ",\n");
col=0;

View File

@ -35,7 +35,7 @@
//#define BB_MKDIR
//#define BB_MKNOD
////#define BB_MKSWAP
//#define BB_MNC
#define BB_MNC
//#define BB_MONADIC
#define BB_MORE
#define BB_MOUNT
@ -43,7 +43,7 @@
#define BB_MV
//#define BB_POSTPROCESS
//#define BB_PRINTF
//#define BB_PWD
#define BB_PWD
//#define BB_REBOOT
//#define BB_RM
//#define BB_RMDIR

8
cat.c
View File

@ -29,9 +29,9 @@ extern int cat_more_main(int argc, char **argv)
int c;
FILE *file = stdin;
if (argc < 2) {
if ( (argc < 2) || (**(argv+1) == '-') ) {
fprintf(stderr, "Usage: %s %s", *argv, cat_usage);
return(FALSE);
exit(FALSE);
}
argc--;
argv++;
@ -40,7 +40,7 @@ extern int cat_more_main(int argc, char **argv)
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
return(FALSE);
exit(FALSE);
}
while ((c = getc(file)) != EOF)
putc(c, stdout);
@ -50,5 +50,5 @@ extern int cat_more_main(int argc, char **argv)
argc--;
argv++;
}
return(TRUE);
exit(TRUE);
}

12
chown.c
View File

@ -66,7 +66,7 @@ int chown_main(int argc, char **argv)
if (argc < 2) {
fprintf(stderr, "Usage: %s %s", *argv,
(chownApp==TRUE)? chown_usage : chgrp_usage);
return( FALSE);
exit( FALSE);
}
invocationName=*argv;
argc--;
@ -80,7 +80,7 @@ int chown_main(int argc, char **argv)
break;
default:
fprintf(stderr, "Unknown option: %c\n", **argv);
return( FALSE);
exit( FALSE);
}
argc--;
argv++;
@ -95,7 +95,7 @@ int chown_main(int argc, char **argv)
grp = getgrnam(groupName);
if (grp == NULL) {
fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName);
return( FALSE);
exit( FALSE);
}
gid = grp->gr_gid;
@ -104,7 +104,7 @@ int chown_main(int argc, char **argv)
pwd = getpwnam(*argv);
if (pwd == NULL) {
fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv);
return( FALSE);
exit( FALSE);
}
uid = pwd->pw_uid;
}
@ -112,11 +112,11 @@ int chown_main(int argc, char **argv)
/* Ok, ready to do the deed now */
if (argc <= 1) {
fprintf(stderr, "%s: too few arguments", invocationName);
return( FALSE);
exit( FALSE);
}
while (argc-- > 1) {
argv++;
recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction);
}
return(TRUE);
exit(TRUE);
}

View File

@ -20,8 +20,9 @@
*/
#include "internal.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
@ -31,18 +32,17 @@ static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
int chroot_main(int argc, char **argv)
{
if (argc < 2) {
if ( (argc < 2) || (**(argv+1) == '-') ) {
fprintf(stderr, "Usage: %s %s", *argv, chroot_usage);
return( FALSE);
exit( FALSE);
}
argc--;
argv++;
fprintf(stderr, "new root: %s\n", *argv);
if (chroot (*argv) || (chdir ("/"))) {
perror("cannot chroot");
return( FALSE);
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}
argc--;
@ -56,10 +56,10 @@ int chroot_main(int argc, char **argv)
prog = getenv ("SHELL");
if (!prog)
prog = "/bin/sh";
fprintf(stderr, "no command. running: %s\n", prog);
execlp (prog, prog, NULL);
}
perror("cannot exec");
return(FALSE);
fprintf(stderr, "chroot: cannot execute %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}

View File

@ -27,5 +27,5 @@ extern int
clear_main(int argc, char** argv)
{
printf("\033[H\033[J");
return 0;
exit( TRUE);
}

View File

@ -27,5 +27,5 @@ extern int
clear_main(int argc, char** argv)
{
printf("\033[H\033[J");
return 0;
exit( TRUE);
}

View File

@ -29,9 +29,9 @@ extern int cat_more_main(int argc, char **argv)
int c;
FILE *file = stdin;
if (argc < 2) {
if ( (argc < 2) || (**(argv+1) == '-') ) {
fprintf(stderr, "Usage: %s %s", *argv, cat_usage);
return(FALSE);
exit(FALSE);
}
argc--;
argv++;
@ -40,7 +40,7 @@ extern int cat_more_main(int argc, char **argv)
file = fopen(*argv, "r");
if (file == NULL) {
perror(*argv);
return(FALSE);
exit(FALSE);
}
while ((c = getc(file)) != EOF)
putc(c, stdout);
@ -50,5 +50,5 @@ extern int cat_more_main(int argc, char **argv)
argc--;
argv++;
}
return(TRUE);
exit(TRUE);
}

View File

@ -66,7 +66,7 @@ int chown_main(int argc, char **argv)
if (argc < 2) {
fprintf(stderr, "Usage: %s %s", *argv,
(chownApp==TRUE)? chown_usage : chgrp_usage);
return( FALSE);
exit( FALSE);
}
invocationName=*argv;
argc--;
@ -80,7 +80,7 @@ int chown_main(int argc, char **argv)
break;
default:
fprintf(stderr, "Unknown option: %c\n", **argv);
return( FALSE);
exit( FALSE);
}
argc--;
argv++;
@ -95,7 +95,7 @@ int chown_main(int argc, char **argv)
grp = getgrnam(groupName);
if (grp == NULL) {
fprintf(stderr, "%s: Unknown group name: %s\n", invocationName, groupName);
return( FALSE);
exit( FALSE);
}
gid = grp->gr_gid;
@ -104,7 +104,7 @@ int chown_main(int argc, char **argv)
pwd = getpwnam(*argv);
if (pwd == NULL) {
fprintf(stderr, "%s: Unknown user name: %s\n", invocationName, *argv);
return( FALSE);
exit( FALSE);
}
uid = pwd->pw_uid;
}
@ -112,11 +112,11 @@ int chown_main(int argc, char **argv)
/* Ok, ready to do the deed now */
if (argc <= 1) {
fprintf(stderr, "%s: too few arguments", invocationName);
return( FALSE);
exit( FALSE);
}
while (argc-- > 1) {
argv++;
recursiveAction( *argv, recursiveFlag, TRUE, fileAction, fileAction);
}
return(TRUE);
exit(TRUE);
}

View File

@ -20,8 +20,9 @@
*/
#include "internal.h"
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
@ -31,18 +32,17 @@ static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
int chroot_main(int argc, char **argv)
{
if (argc < 2) {
if ( (argc < 2) || (**(argv+1) == '-') ) {
fprintf(stderr, "Usage: %s %s", *argv, chroot_usage);
return( FALSE);
exit( FALSE);
}
argc--;
argv++;
fprintf(stderr, "new root: %s\n", *argv);
if (chroot (*argv) || (chdir ("/"))) {
perror("cannot chroot");
return( FALSE);
fprintf(stderr, "chroot: cannot change root directory to %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}
argc--;
@ -56,10 +56,10 @@ int chroot_main(int argc, char **argv)
prog = getenv ("SHELL");
if (!prog)
prog = "/bin/sh";
fprintf(stderr, "no command. running: %s\n", prog);
execlp (prog, prog, NULL);
}
perror("cannot exec");
return(FALSE);
fprintf(stderr, "chroot: cannot execute %s: %s\n",
*argv, strerror(errno));
exit( FALSE);
}

View File

@ -91,7 +91,7 @@ extern int cp_main(int argc, char **argv)
if (argc < 3) {
fprintf(stderr, "Usage: %s", cp_usage);
return (FALSE);
exit (FALSE);
}
argc--;
argv++;
@ -129,13 +129,13 @@ extern int cp_main(int argc, char **argv)
if ((argc > 3) && !dirFlag) {
fprintf(stderr, "%s: not a directory\n", destName);
return (FALSE);
exit (FALSE);
}
while (argc-- >= 2) {
srcName = *(argv++);
return recursiveAction(srcName, recursiveFlag, followLinks,
fileAction, fileAction);
exit( recursiveAction(srcName, recursiveFlag, followLinks,
fileAction, fileAction));
}
return( TRUE);
exit( TRUE);
}

View File

@ -1,3 +1,24 @@
/*
* Mini date implementation for busybox
*
* Copyright (C) 1999 by Erik Andersen <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 <stdlib.h>
#include <errno.h>
@ -5,7 +26,6 @@
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <getopt.h>
/* This 'date' command supports only 2 time setting formats,
@ -14,25 +34,12 @@
an RFC 822 complient date output for shell scripting
mail commands */
const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n"
"| [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]";
//static const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n"
//"or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
//"Display the current time in the given FORMAT, or set the system date.\n";
static struct option const long_options[] =
{
{"date", required_argument, NULL, 'd'},
/* {"rfc-822", no_argument, NULL, 'R'},
{"set", required_argument, NULL, 's'},
{"uct", no_argument, NULL, 'u'},
{"utc", no_argument, NULL, 'u'},
{"universal", no_argument, NULL, 'u'}, */
{NULL, 0, NULL, 0}
};
const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n"
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
"Display the current time in the given FORMAT, or set the system date.\n"
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
"\t-s\t\tset time described by STRING\n"
"\t-u\t\tprint or set Coordinated Universal Time\n";
/* Input parsing code is always bulky - used heavy duty libc stuff as
@ -53,7 +60,7 @@ date_conv_time(struct tm *tm_time, const char *t_string) {
if(nr < 4 || nr > 5) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit(1);
exit( FALSE);
}
/* correct for century - minor Y2K problem here? */
@ -147,15 +154,15 @@ date_conv_ftime(struct tm *tm_time, const char *t_string) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit(1);
exit( FALSE);
}
void
date_err(void) {
fprintf(stderr, "date: only one date argument can be given at a time.\n");
exit(1);
fprintf (stderr, "%s\n", date_usage);
exit( FALSE);
}
int
@ -164,82 +171,56 @@ date_main(int argc, char * * argv)
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
int i;
int set_time = 0;
int rfc822 = 0;
int utc = 0;
int use_arg = 0;
int n_args;
time_t tm;
struct tm tm_time;
char optc;
/* Interpret command line args */
while ((optc = getopt_long (argc, argv, "d:Rs:u", long_options, NULL))
!= EOF) {
switch (optc) {
case 0:
break;
case 'R':
rfc822 = 1;
break;
case 's':
set_time = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
return(1);
}
#if LOCALTIME_CACHE
tzset ();
#endif break;
case 'd':
use_arg = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
default:
fprintf(stderr, "Usage: %s", date_usage);
break;
i = --argc;
argv++;
while (i > 0 && **argv) {
if (**argv == '-') {
while (i>0 && *++(*argv)) switch (**argv) {
case 'R':
rfc822 = 1;
break;
case 's':
set_time = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
exit( FALSE);
}
/* Look ma, no break. Don't fix it either. */
case 'd':
use_arg = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
case '-':
date_err();
}
} else {
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
date_fmt=*argv;
else if (date_str == NULL) {
set_time = 1;
date_str=*argv;
} else {
date_err();
}
}
i--;
argv++;
}
}
n_args = argc - optind;
while (n_args--){
switch(argv[optind][0]) {
case '+':
/* Date format strings */
if(date_fmt != NULL) {
fprintf(stderr, "date: only one date format can be given.\n");
return(1);
}
date_fmt = &argv[optind][1];
break;
case '\0':
break;
default:
/* Anything left over must be a date string to set the time */
set_time = 1;
if(date_str != NULL) date_err();
date_str = argv[optind];
break;
}
optind++;
}
/* Now we have parsed all the information except the date format
@ -267,14 +248,14 @@ date_main(int argc, char * * argv)
tm = mktime(&tm_time);
if (tm < 0 ) {
fprintf(stderr, "date: invalid date `%s'\n", date_str);
exit(1);
exit( FALSE);
}
/* if setting time, set it */
if(set_time) {
if( stime(&tm) < 0) {
fprintf(stderr, "date: can't set date.\n");
exit(1);
exit( FALSE);
}
}
}
@ -292,7 +273,7 @@ date_main(int argc, char * * argv)
} else if ( *date_fmt == '\0' ) {
/* Imitate what GNU 'date' does with NO format string! */
printf ("\n");
return(0);
exit( TRUE);
}
/* Handle special conversions */
@ -306,6 +287,7 @@ date_main(int argc, char * * argv)
strftime(t_buff, 200, date_fmt, &tm_time);
printf("%s\n", t_buff);
return(0);
exit( TRUE);
}

View File

@ -4,15 +4,15 @@
const char pwd_usage[] = "Print the current directory.\n";
extern int
pwd_main(struct FileInfo * i, int argc, char * * argv)
pwd_main(int argc, char * * argv)
{
char buf[1024];
if ( getcwd(buf, sizeof(buf)) == NULL ) {
name_and_error("get working directory");
return 1;
perror("get working directory");
exit( FALSE);
}
printf("%s\n", buf);
return 0;
exit( TRUE);
}

10
cp.c
View File

@ -91,7 +91,7 @@ extern int cp_main(int argc, char **argv)
if (argc < 3) {
fprintf(stderr, "Usage: %s", cp_usage);
return (FALSE);
exit (FALSE);
}
argc--;
argv++;
@ -129,13 +129,13 @@ extern int cp_main(int argc, char **argv)
if ((argc > 3) && !dirFlag) {
fprintf(stderr, "%s: not a directory\n", destName);
return (FALSE);
exit (FALSE);
}
while (argc-- >= 2) {
srcName = *(argv++);
return recursiveAction(srcName, recursiveFlag, followLinks,
fileAction, fileAction);
exit( recursiveAction(srcName, recursiveFlag, followLinks,
fileAction, fileAction));
}
return( TRUE);
exit( TRUE);
}

172
date.c
View File

@ -1,3 +1,24 @@
/*
* Mini date implementation for busybox
*
* Copyright (C) 1999 by Erik Andersen <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 <stdlib.h>
#include <errno.h>
@ -5,7 +26,6 @@
#include <unistd.h>
#include <time.h>
#include <stdio.h>
#include <getopt.h>
/* This 'date' command supports only 2 time setting formats,
@ -14,25 +34,12 @@
an RFC 822 complient date output for shell scripting
mail commands */
const char date_usage[] = "date [-uR] [+FORMAT|+%f] [ [-s|-d] MMDDhhmm[[CC]YY]\n"
"| [[[[CCYY.]MM.DD-]hh:mm[:ss]]]] ]";
//static const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n"
//"or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
//"Display the current time in the given FORMAT, or set the system date.\n";
static struct option const long_options[] =
{
{"date", required_argument, NULL, 'd'},
/* {"rfc-822", no_argument, NULL, 'R'},
{"set", required_argument, NULL, 's'},
{"uct", no_argument, NULL, 'u'},
{"utc", no_argument, NULL, 'u'},
{"universal", no_argument, NULL, 'u'}, */
{NULL, 0, NULL, 0}
};
const char date_usage[] = "Usage: date [OPTION]... [+FORMAT]\n"
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
"Display the current time in the given FORMAT, or set the system date.\n"
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
"\t-s\t\tset time described by STRING\n"
"\t-u\t\tprint or set Coordinated Universal Time\n";
/* Input parsing code is always bulky - used heavy duty libc stuff as
@ -53,7 +60,7 @@ date_conv_time(struct tm *tm_time, const char *t_string) {
if(nr < 4 || nr > 5) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit(1);
exit( FALSE);
}
/* correct for century - minor Y2K problem here? */
@ -147,15 +154,15 @@ date_conv_ftime(struct tm *tm_time, const char *t_string) {
fprintf(stderr, "date: invalid date `%s'\n", t_string);
exit(1);
exit( FALSE);
}
void
date_err(void) {
fprintf(stderr, "date: only one date argument can be given at a time.\n");
exit(1);
fprintf (stderr, "%s\n", date_usage);
exit( FALSE);
}
int
@ -164,82 +171,56 @@ date_main(int argc, char * * argv)
char *date_str = NULL;
char *date_fmt = NULL;
char *t_buff;
int i;
int set_time = 0;
int rfc822 = 0;
int utc = 0;
int use_arg = 0;
int n_args;
time_t tm;
struct tm tm_time;
char optc;
/* Interpret command line args */
while ((optc = getopt_long (argc, argv, "d:Rs:u", long_options, NULL))
!= EOF) {
switch (optc) {
case 0:
break;
case 'R':
rfc822 = 1;
break;
case 's':
set_time = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
return(1);
}
#if LOCALTIME_CACHE
tzset ();
#endif break;
case 'd':
use_arg = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
default:
fprintf(stderr, "Usage: %s", date_usage);
break;
i = --argc;
argv++;
while (i > 0 && **argv) {
if (**argv == '-') {
while (i>0 && *++(*argv)) switch (**argv) {
case 'R':
rfc822 = 1;
break;
case 's':
set_time = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
case 'u':
utc = 1;
if (putenv ("TZ=UTC0") != 0) {
fprintf(stderr,"date: memory exhausted\n");
exit( FALSE);
}
/* Look ma, no break. Don't fix it either. */
case 'd':
use_arg = 1;
if(date_str != NULL) date_err();
date_str = optarg;
break;
case '-':
date_err();
}
} else {
if ( (date_fmt == NULL) && (strcmp(*argv, "+")==0) )
date_fmt=*argv;
else if (date_str == NULL) {
set_time = 1;
date_str=*argv;
} else {
date_err();
}
}
i--;
argv++;
}
}
n_args = argc - optind;
while (n_args--){
switch(argv[optind][0]) {
case '+':
/* Date format strings */
if(date_fmt != NULL) {
fprintf(stderr, "date: only one date format can be given.\n");
return(1);
}
date_fmt = &argv[optind][1];
break;
case '\0':
break;
default:
/* Anything left over must be a date string to set the time */
set_time = 1;
if(date_str != NULL) date_err();
date_str = argv[optind];
break;
}
optind++;
}
/* Now we have parsed all the information except the date format
@ -267,14 +248,14 @@ date_main(int argc, char * * argv)
tm = mktime(&tm_time);
if (tm < 0 ) {
fprintf(stderr, "date: invalid date `%s'\n", date_str);
exit(1);
exit( FALSE);
}
/* if setting time, set it */
if(set_time) {
if( stime(&tm) < 0) {
fprintf(stderr, "date: can't set date.\n");
exit(1);
exit( FALSE);
}
}
}
@ -292,7 +273,7 @@ date_main(int argc, char * * argv)
} else if ( *date_fmt == '\0' ) {
/* Imitate what GNU 'date' does with NO format string! */
printf ("\n");
return(0);
exit( TRUE);
}
/* Handle special conversions */
@ -306,6 +287,7 @@ date_main(int argc, char * * argv)
strftime(t_buff, 200, date_fmt, &tm_time);
printf("%s\n", t_buff);
return(0);
exit( TRUE);
}

79
mnc.c
View File

@ -3,9 +3,11 @@
0.0.1 6K It works.
0.0.2 5K Smaller and you can also check the exit condition if you wish.
0.0.3 Uses select()
19980918 Busy Boxed! Dave Cinege
19990512 Uses Select. Charles P. Wright
19990513 Fixes stdin stupidity and uses buffers. Charles P. Wright
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
@ -35,26 +37,24 @@
#include <sys/time.h>
#include <sys/ioctl.h>
#define BUFSIZE 100
const char mnc_usage[] =
"mini-netcat 0.0.1 -- Open pipe to IP:port\n"
"mini-netcat 0.0.3 -- Open pipe to IP:port\n"
"\tmnc [IP] [port]\n";
int
mnc_main(struct FileInfo * i, int argc, char **argv)
mnc_main(int argc, char **argv)
{
int sfd;
int result;
int len;
int pid;
char ch;
char ch[BUFSIZE];
struct sockaddr_in address;
struct hostent *hostinfo;
#ifdef SELECT
fd_set readfds, testfds;
#endif
sfd = socket(AF_INET, SOCK_STREAM, 0);
@ -78,7 +78,6 @@ mnc_main(struct FileInfo * i, int argc, char **argv)
exit(2);
}
#ifdef SELECT
FD_ZERO(&readfds);
FD_SET(sfd, &readfds);
FD_SET(fileno(stdin), &readfds);
@ -86,6 +85,7 @@ mnc_main(struct FileInfo * i, int argc, char **argv)
while(1)
{
int fd;
int ofd;
int nread;
testfds = readfds;
@ -101,48 +101,33 @@ mnc_main(struct FileInfo * i, int argc, char **argv)
{
if(FD_ISSET(fd,&testfds))
{
ioctl(fd, FIONREAD, &nread);
int trn = 0;
int rn;
if (nread == 0)
exit(0);
ioctl(fd, FIONREAD, &nread);
if(fd == sfd)
{
read(sfd, &ch, 1);
write(fileno(stdout), &ch, 1);
}
else
{
read(fileno(stdin), &ch, 1);
write(sfd, &ch, 1);
}
}
}
}
#else
pid = fork();
if (nread == 0)
exit(0);
ofd = fileno(stdout);
}
else
{
ofd = sfd;
}
if (!pid)
{
int retval;
retval = 1;
while(retval == 1)
{
retval = read(fileno(stdin), &ch, 1);
write(sfd, &ch, 1);
}
}
else
{
int retval;
retval = 1;
while(retval == 1)
{
retval = read(sfd, &ch, 1);
write(fileno(stdout), &ch, 1);
}
}
exit(0);
#endif
do
{
rn = (BUFSIZE < nread - trn) ? BUFSIZE : nread - trn;
trn += rn;
read(fd, ch, rn);
write(ofd, ch, rn);
}
while (trn < nread);
}
}
}
}

8
pwd.c
View File

@ -4,15 +4,15 @@
const char pwd_usage[] = "Print the current directory.\n";
extern int
pwd_main(struct FileInfo * i, int argc, char * * argv)
pwd_main(int argc, char * * argv)
{
char buf[1024];
if ( getcwd(buf, sizeof(buf)) == NULL ) {
name_and_error("get working directory");
return 1;
perror("get working directory");
exit( FALSE);
}
printf("%s\n", buf);
return 0;
exit( TRUE);
}