mirror of
https://github.com/sheumann/hush.git
synced 2024-12-26 10:32:02 +00:00
* added (and documented) "-n" option for head -
contributed Friedrich Vedder <fwv@myrtle.lahn.de> * Cleanup for a number of usage messages -- also contributed Friedrich Vedder <fwv@myrtle.lahn.de> -Erik
This commit is contained in:
parent
9bc7e89fc1
commit
5509af7073
@ -15,6 +15,10 @@
|
|||||||
* Optional support contributed by Ben Collins <bcollins@debian.org>
|
* Optional support contributed by Ben Collins <bcollins@debian.org>
|
||||||
for the kernel init chroot patch by Werner Almesberger, which
|
for the kernel init chroot patch by Werner Almesberger, which
|
||||||
allows init to chroot to a new device, and umount the old one.
|
allows init to chroot to a new device, and umount the old one.
|
||||||
|
* added (and documented) "-n" option for head -
|
||||||
|
contributed Friedrich Vedder <fwv@myrtle.lahn.de>
|
||||||
|
* Cleanup for a number of usage messages -- also
|
||||||
|
contributed Friedrich Vedder <fwv@myrtle.lahn.de>
|
||||||
* Fixed bug that wouldn't let one chown a symlink -- it would
|
* Fixed bug that wouldn't let one chown a symlink -- it would
|
||||||
always dereference before. -beppu
|
always dereference before. -beppu
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ static const char tar_usage[] =
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
static const char tar_usage[] =
|
static const char tar_usage[] =
|
||||||
"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
|
"tar -[xtvOf] [tarFileName] [FILE] ...\n\n"
|
||||||
"Extract, or list files stored in a tar file. This\n"
|
"Extract, or list files stored in a tar file. This\n"
|
||||||
"version of tar does not support creation of tar files.\n\n"
|
"version of tar does not support creation of tar files.\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
typedef void (Display)(size_t, char *);
|
typedef void (Display)(size_t, char *);
|
||||||
|
|
||||||
static const char du_usage[] =
|
static const char du_usage[] =
|
||||||
"Usage: du [OPTION]... [FILE]...\n\n"
|
"du [OPTION]... [FILE]...\n\n"
|
||||||
"\t-s\tdisplay only a total for each argument\n"
|
"\t-s\tdisplay only a total for each argument\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -140,4 +140,4 @@ du_main(int argc, char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: du.c,v 1.8 1999/12/17 18:44:15 erik Exp $ */
|
/* $Id: du.c,v 1.9 2000/01/23 18:19:02 erik Exp $ */
|
||||||
|
@ -26,10 +26,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
const char head_usage[] =
|
const char head_usage[] =
|
||||||
"Usage: head [FILE]...\n\n"
|
"head [OPTION] [FILE]...\n\n"
|
||||||
"Print first 10 lines of each FILE to standard output.\n"
|
"Print first 10 lines of each FILE to standard output.\n"
|
||||||
"With more than one FILE, precede each with a header giving the\n"
|
"With more than one FILE, precede each with a header giving the\n"
|
||||||
"file name. With no FILE, or when FILE is -, read standard input.\n";
|
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
|
||||||
|
"Options:\n"
|
||||||
|
"\t-n NUM\t\tPrint first NUM lines instead of first 10\n";
|
||||||
|
|
||||||
int
|
int
|
||||||
head(int len, FILE *src)
|
head(int len, FILE *src)
|
||||||
@ -49,22 +51,22 @@ head(int len, FILE *src)
|
|||||||
int
|
int
|
||||||
head_main(int argc, char **argv)
|
head_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i = 1;
|
|
||||||
char opt;
|
char opt;
|
||||||
int len = 10;
|
int len = 10, tmplen, i;
|
||||||
|
|
||||||
/* 1st option is potentially special */
|
|
||||||
if ((argc > 1) && (argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
|
||||||
int tmplen = atoi(&argv[1][1]);
|
|
||||||
if (tmplen) { len = tmplen; }
|
|
||||||
i = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* parse argv[] */
|
/* parse argv[] */
|
||||||
for ( ; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (argv[i][0] == '-') {
|
if (argv[i][0] == '-') {
|
||||||
opt = argv[i][1];
|
opt = argv[i][1];
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
tmplen = 0;
|
||||||
|
if (i++ < argc)
|
||||||
|
tmplen = atoi(argv[i]);
|
||||||
|
if (tmplen < 1)
|
||||||
|
usage(head_usage);
|
||||||
|
len = tmplen;
|
||||||
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(head_usage);
|
usage(head_usage);
|
||||||
@ -103,4 +105,4 @@ head_main(int argc, char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: head.c,v 1.4 1999/12/17 18:52:06 erik Exp $ */
|
/* $Id: head.c,v 1.5 2000/01/23 18:19:02 erik Exp $ */
|
||||||
|
@ -26,7 +26,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\n"
|
static const char mkdir_usage[] =
|
||||||
|
"mkdir [OPTION] DIRECTORY...\n\n"
|
||||||
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static const char sort_usage[] =
|
static const char sort_usage[] =
|
||||||
"Usage: sort [OPTION]... [FILE]...\n\n"
|
"sort [OPTION]... [FILE]...\n\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
/* typedefs _______________________________________________________________ */
|
/* typedefs _______________________________________________________________ */
|
||||||
@ -309,4 +309,4 @@ sort_main(int argc, char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: sort.c,v 1.8 1999/12/23 22:46:10 beppu Exp $ */
|
/* $Id: sort.c,v 1.9 2000/01/23 18:19:02 erik Exp $ */
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static const char uniq_usage[] =
|
static const char uniq_usage[] =
|
||||||
"Usage: uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
"uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
||||||
"Discard all but one of successive identical lines from INPUT (or\n"
|
"Discard all but one of successive identical lines from INPUT (or\n"
|
||||||
"standard input), writing to OUTPUT (or standard output).\n"
|
"standard input), writing to OUTPUT (or standard output).\n"
|
||||||
"\n"
|
"\n"
|
||||||
@ -193,4 +193,4 @@ uniq_main(int argc, char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: uniq.c,v 1.4 2000/01/07 01:57:32 beppu Exp $ */
|
/* $Id: uniq.c,v 1.5 2000/01/23 18:19:02 erik Exp $ */
|
||||||
|
@ -28,7 +28,6 @@ static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
|
|||||||
"\t-c\tprint the byte counts\n"
|
"\t-c\tprint the byte counts\n"
|
||||||
"\t-l\tprint the newline counts\n"
|
"\t-l\tprint the newline counts\n"
|
||||||
"\t-L\tprint the length of the longest line\n"
|
"\t-L\tprint the length of the longest line\n"
|
||||||
"\t-L\tprint the length of the longest line\n"
|
|
||||||
"\t-w\tprint the word counts\n";
|
"\t-w\tprint the word counts\n";
|
||||||
|
|
||||||
static int total_lines, total_words, total_chars, max_length;
|
static int total_lines, total_words, total_chars, max_length;
|
||||||
|
4
du.c
4
du.c
@ -35,7 +35,7 @@
|
|||||||
typedef void (Display)(size_t, char *);
|
typedef void (Display)(size_t, char *);
|
||||||
|
|
||||||
static const char du_usage[] =
|
static const char du_usage[] =
|
||||||
"Usage: du [OPTION]... [FILE]...\n\n"
|
"du [OPTION]... [FILE]...\n\n"
|
||||||
"\t-s\tdisplay only a total for each argument\n"
|
"\t-s\tdisplay only a total for each argument\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -140,4 +140,4 @@ du_main(int argc, char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: du.c,v 1.8 1999/12/17 18:44:15 erik Exp $ */
|
/* $Id: du.c,v 1.9 2000/01/23 18:19:02 erik Exp $ */
|
||||||
|
28
head.c
28
head.c
@ -26,10 +26,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
const char head_usage[] =
|
const char head_usage[] =
|
||||||
"Usage: head [FILE]...\n\n"
|
"head [OPTION] [FILE]...\n\n"
|
||||||
"Print first 10 lines of each FILE to standard output.\n"
|
"Print first 10 lines of each FILE to standard output.\n"
|
||||||
"With more than one FILE, precede each with a header giving the\n"
|
"With more than one FILE, precede each with a header giving the\n"
|
||||||
"file name. With no FILE, or when FILE is -, read standard input.\n";
|
"file name. With no FILE, or when FILE is -, read standard input.\n\n"
|
||||||
|
"Options:\n"
|
||||||
|
"\t-n NUM\t\tPrint first NUM lines instead of first 10\n";
|
||||||
|
|
||||||
int
|
int
|
||||||
head(int len, FILE *src)
|
head(int len, FILE *src)
|
||||||
@ -49,22 +51,22 @@ head(int len, FILE *src)
|
|||||||
int
|
int
|
||||||
head_main(int argc, char **argv)
|
head_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i = 1;
|
|
||||||
char opt;
|
char opt;
|
||||||
int len = 10;
|
int len = 10, tmplen, i;
|
||||||
|
|
||||||
/* 1st option is potentially special */
|
|
||||||
if ((argc > 1) && (argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
|
||||||
int tmplen = atoi(&argv[1][1]);
|
|
||||||
if (tmplen) { len = tmplen; }
|
|
||||||
i = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* parse argv[] */
|
/* parse argv[] */
|
||||||
for ( ; i < argc; i++) {
|
for (i = 1; i < argc; i++) {
|
||||||
if (argv[i][0] == '-') {
|
if (argv[i][0] == '-') {
|
||||||
opt = argv[i][1];
|
opt = argv[i][1];
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
case 'n':
|
||||||
|
tmplen = 0;
|
||||||
|
if (i++ < argc)
|
||||||
|
tmplen = atoi(argv[i]);
|
||||||
|
if (tmplen < 1)
|
||||||
|
usage(head_usage);
|
||||||
|
len = tmplen;
|
||||||
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
case 'h':
|
case 'h':
|
||||||
usage(head_usage);
|
usage(head_usage);
|
||||||
@ -103,4 +105,4 @@ head_main(int argc, char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: head.c,v 1.4 1999/12/17 18:52:06 erik Exp $ */
|
/* $Id: head.c,v 1.5 2000/01/23 18:19:02 erik Exp $ */
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#include "busybox.def.h"
|
#include "busybox.def.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@ -174,7 +175,7 @@ extern int check_wildcard_match(const char* text, const char* pattern);
|
|||||||
extern long getNum (const char *cp);
|
extern long getNum (const char *cp);
|
||||||
extern pid_t findInitPid();
|
extern pid_t findInitPid();
|
||||||
|
|
||||||
#if (__GLIBC__ < 2) && defined BB_SYSLOGD
|
#if (__GLIBC__ < 2) && (defined BB_SYSLOGD || defined BB_INIT)
|
||||||
extern int vdprintf(int d, const char *format, va_list ap);
|
extern int vdprintf(int d, const char *format, va_list ap);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
3
mkdir.c
3
mkdir.c
@ -26,7 +26,8 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\n"
|
static const char mkdir_usage[] =
|
||||||
|
"mkdir [OPTION] DIRECTORY...\n\n"
|
||||||
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
"\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
||||||
|
28
mount.c
28
mount.c
@ -428,43 +428,41 @@ static int set_loop(const char *device, const char *file, int offset, int *loopr
|
|||||||
loopinfo.lo_encrypt_key_size = 0;
|
loopinfo.lo_encrypt_key_size = 0;
|
||||||
if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
|
if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
|
||||||
perror("ioctl: LOOP_SET_FD");
|
perror("ioctl: LOOP_SET_FD");
|
||||||
exit(1);
|
close(fd);
|
||||||
|
close(ffd);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
|
if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
|
||||||
(void) ioctl(fd, LOOP_CLR_FD, 0);
|
(void) ioctl(fd, LOOP_CLR_FD, 0);
|
||||||
perror("ioctl: LOOP_SET_STATUS");
|
perror("ioctl: LOOP_SET_STATUS");
|
||||||
exit(1);
|
close(fd);
|
||||||
|
close(ffd);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
close(ffd);
|
close(ffd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *find_unused_loop_device (void)
|
char *find_unused_loop_device (void)
|
||||||
{
|
{
|
||||||
char dev[20];
|
char dev[20];
|
||||||
int i, fd, somedev = 0, someloop = 0;
|
int i, fd;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
struct loop_info loopinfo;
|
struct loop_info loopinfo;
|
||||||
|
|
||||||
for(i = 0; i < 256; i++) {
|
for(i = 0; i <= 7; i++) {
|
||||||
sprintf(dev, "/dev/loop%d", i);
|
sprintf(dev, "/dev/loop%d", i);
|
||||||
if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
|
if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
|
||||||
somedev++;
|
if ((fd = open (dev, O_RDONLY)) >= 0) {
|
||||||
fd = open (dev, O_RDONLY);
|
if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == -1 &&
|
||||||
if (fd >= 0) {
|
errno == ENXIO) { /* probably free */
|
||||||
if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0)
|
|
||||||
someloop++; /* in use */
|
|
||||||
else if (errno == ENXIO) {
|
|
||||||
close (fd);
|
close (fd);
|
||||||
return strdup(dev); /* probably free */
|
return strdup(dev);
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (i >= 7)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
2
sfdisk.c
2
sfdisk.c
@ -55,7 +55,7 @@
|
|||||||
|
|
||||||
|
|
||||||
static const char sfdisk_usage[] =
|
static const char sfdisk_usage[] =
|
||||||
"Usage: sfdisk [options] device ...\n"
|
"sfdisk [options] device ...\n"
|
||||||
"device: something like /dev/hda or /dev/sda\n"
|
"device: something like /dev/hda or /dev/sda\n"
|
||||||
"useful options:\n"
|
"useful options:\n"
|
||||||
" -s [or --show-size]: list size of a partition\n"
|
" -s [or --show-size]: list size of a partition\n"
|
||||||
|
4
sort.c
4
sort.c
@ -29,7 +29,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static const char sort_usage[] =
|
static const char sort_usage[] =
|
||||||
"Usage: sort [OPTION]... [FILE]...\n\n"
|
"sort [OPTION]... [FILE]...\n\n"
|
||||||
;
|
;
|
||||||
|
|
||||||
/* typedefs _______________________________________________________________ */
|
/* typedefs _______________________________________________________________ */
|
||||||
@ -309,4 +309,4 @@ sort_main(int argc, char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: sort.c,v 1.8 1999/12/23 22:46:10 beppu Exp $ */
|
/* $Id: sort.c,v 1.9 2000/01/23 18:19:02 erik Exp $ */
|
||||||
|
2
tar.c
2
tar.c
@ -54,7 +54,7 @@ static const char tar_usage[] =
|
|||||||
#else
|
#else
|
||||||
|
|
||||||
static const char tar_usage[] =
|
static const char tar_usage[] =
|
||||||
"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
|
"tar -[xtvOf] [tarFileName] [FILE] ...\n\n"
|
||||||
"Extract, or list files stored in a tar file. This\n"
|
"Extract, or list files stored in a tar file. This\n"
|
||||||
"version of tar does not support creation of tar files.\n\n"
|
"version of tar does not support creation of tar files.\n\n"
|
||||||
"Options:\n"
|
"Options:\n"
|
||||||
|
2
umount.c
2
umount.c
@ -37,7 +37,7 @@ static int del_loop(const char *device);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char umount_usage[] =
|
static const char umount_usage[] =
|
||||||
"Usage: umount [flags] filesystem|directory\n\n"
|
"umount [flags] filesystem|directory\n\n"
|
||||||
"Flags:\n"
|
"Flags:\n"
|
||||||
"\t-a:\tUnmount all file systems"
|
"\t-a:\tUnmount all file systems"
|
||||||
#ifdef BB_MTAB
|
#ifdef BB_MTAB
|
||||||
|
4
uniq.c
4
uniq.c
@ -27,7 +27,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
static const char uniq_usage[] =
|
static const char uniq_usage[] =
|
||||||
"Usage: uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
"uniq [OPTION]... [INPUT [OUTPUT]]\n"
|
||||||
"Discard all but one of successive identical lines from INPUT (or\n"
|
"Discard all but one of successive identical lines from INPUT (or\n"
|
||||||
"standard input), writing to OUTPUT (or standard output).\n"
|
"standard input), writing to OUTPUT (or standard output).\n"
|
||||||
"\n"
|
"\n"
|
||||||
@ -193,4 +193,4 @@ uniq_main(int argc, char **argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $Id: uniq.c,v 1.4 2000/01/07 01:57:32 beppu Exp $ */
|
/* $Id: uniq.c,v 1.5 2000/01/23 18:19:02 erik Exp $ */
|
||||||
|
@ -428,43 +428,41 @@ static int set_loop(const char *device, const char *file, int offset, int *loopr
|
|||||||
loopinfo.lo_encrypt_key_size = 0;
|
loopinfo.lo_encrypt_key_size = 0;
|
||||||
if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
|
if (ioctl(fd, LOOP_SET_FD, ffd) < 0) {
|
||||||
perror("ioctl: LOOP_SET_FD");
|
perror("ioctl: LOOP_SET_FD");
|
||||||
exit(1);
|
close(fd);
|
||||||
|
close(ffd);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
|
if (ioctl(fd, LOOP_SET_STATUS, &loopinfo) < 0) {
|
||||||
(void) ioctl(fd, LOOP_CLR_FD, 0);
|
(void) ioctl(fd, LOOP_CLR_FD, 0);
|
||||||
perror("ioctl: LOOP_SET_STATUS");
|
perror("ioctl: LOOP_SET_STATUS");
|
||||||
exit(1);
|
close(fd);
|
||||||
|
close(ffd);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
close(ffd);
|
close(ffd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *find_unused_loop_device (void)
|
char *find_unused_loop_device (void)
|
||||||
{
|
{
|
||||||
char dev[20];
|
char dev[20];
|
||||||
int i, fd, somedev = 0, someloop = 0;
|
int i, fd;
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
struct loop_info loopinfo;
|
struct loop_info loopinfo;
|
||||||
|
|
||||||
for(i = 0; i < 256; i++) {
|
for(i = 0; i <= 7; i++) {
|
||||||
sprintf(dev, "/dev/loop%d", i);
|
sprintf(dev, "/dev/loop%d", i);
|
||||||
if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
|
if (stat (dev, &statbuf) == 0 && S_ISBLK(statbuf.st_mode)) {
|
||||||
somedev++;
|
if ((fd = open (dev, O_RDONLY)) >= 0) {
|
||||||
fd = open (dev, O_RDONLY);
|
if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == -1 &&
|
||||||
if (fd >= 0) {
|
errno == ENXIO) { /* probably free */
|
||||||
if(ioctl (fd, LOOP_GET_STATUS, &loopinfo) == 0)
|
|
||||||
someloop++; /* in use */
|
|
||||||
else if (errno == ENXIO) {
|
|
||||||
close (fd);
|
close (fd);
|
||||||
return strdup(dev); /* probably free */
|
return strdup(dev);
|
||||||
}
|
}
|
||||||
close (fd);
|
close (fd);
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
if (i >= 7)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ static int del_loop(const char *device);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char umount_usage[] =
|
static const char umount_usage[] =
|
||||||
"Usage: umount [flags] filesystem|directory\n\n"
|
"umount [flags] filesystem|directory\n\n"
|
||||||
"Flags:\n"
|
"Flags:\n"
|
||||||
"\t-a:\tUnmount all file systems"
|
"\t-a:\tUnmount all file systems"
|
||||||
#ifdef BB_MTAB
|
#ifdef BB_MTAB
|
||||||
|
1
wc.c
1
wc.c
@ -28,7 +28,6 @@ static const char wc_usage[] = "wc [OPTION]... [FILE]...\n\n"
|
|||||||
"\t-c\tprint the byte counts\n"
|
"\t-c\tprint the byte counts\n"
|
||||||
"\t-l\tprint the newline counts\n"
|
"\t-l\tprint the newline counts\n"
|
||||||
"\t-L\tprint the length of the longest line\n"
|
"\t-L\tprint the length of the longest line\n"
|
||||||
"\t-L\tprint the length of the longest line\n"
|
|
||||||
"\t-w\tprint the word counts\n";
|
"\t-w\tprint the word counts\n";
|
||||||
|
|
||||||
static int total_lines, total_words, total_chars, max_length;
|
static int total_lines, total_words, total_chars, max_length;
|
||||||
|
Loading…
Reference in New Issue
Block a user