aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2000-06-04 05:08:29 +0000
committerEric Andersen <andersen@codepoet.org>2000-06-04 05:08:29 +0000
commitef4268efa7474ba84dc02ffc29030ad6407fedcb (patch)
treea7e405d939dc014ccb08867eb6a26ebc28c3ad74
parent832000f7f3e368bb00d02bf4b54cb531affdaf1b (diff)
downloadbusybox-ef4268efa7474ba84dc02ffc29030ad6407fedcb.tar.gz
This patch
- eliminates the need to have a buffer and strcpy to it - makes freeramdisk complain if it's given more than one argument Regards, Pavel Roskin
-rw-r--r--Changelog1
-rw-r--r--freeramdisk.c12
-rw-r--r--util-linux/freeramdisk.c12
3 files changed, 9 insertions, 16 deletions
diff --git a/Changelog b/Changelog
index 829232911..004bca46c 100644
--- a/Changelog
+++ b/Changelog
@@ -49,6 +49,7 @@
to Pavel Roskin.
* Fixed all fatalError() calls lacking a "\n", thanks to Pavel Roskin.
* Fixed a segfault in yes when no args were given -- Pavel Roskin.
+ * Simplified freeramdisk and added argument checking -- Pavel Roskin.
* More doc updates
diff --git a/freeramdisk.c b/freeramdisk.c
index 4106cf144..cabe5660b 100644
--- a/freeramdisk.c
+++ b/freeramdisk.c
@@ -43,21 +43,17 @@ static const char freeramdisk_usage[] =
extern int
freeramdisk_main(int argc, char **argv)
{
- char rname[256] = "/dev/ram";
int f;
- if (argc < 2 || ( argv[1] && *argv[1] == '-')) {
+ if (argc != 2 || *argv[1] == '-') {
usage(freeramdisk_usage);
}
- if (argc >1)
- strcpy(rname, argv[1]);
-
- if ((f = open(rname, O_RDWR)) == -1) {
- fatalError( "freeramdisk: cannot open %s: %s\n", rname, strerror(errno));
+ if ((f = open(argv[1], O_RDWR)) == -1) {
+ fatalError( "freeramdisk: cannot open %s: %s\n", argv[1], strerror(errno));
}
if (ioctl(f, BLKFLSBUF) < 0) {
- fatalError( "freeramdisk: failed ioctl on %s: %s\n", rname, strerror(errno));
+ fatalError( "freeramdisk: failed ioctl on %s: %s\n", argv[1], strerror(errno));
}
/* Don't bother closing. Exit does
* that, so we can save a few bytes */
diff --git a/util-linux/freeramdisk.c b/util-linux/freeramdisk.c
index 4106cf144..cabe5660b 100644
--- a/util-linux/freeramdisk.c
+++ b/util-linux/freeramdisk.c
@@ -43,21 +43,17 @@ static const char freeramdisk_usage[] =
extern int
freeramdisk_main(int argc, char **argv)
{
- char rname[256] = "/dev/ram";
int f;
- if (argc < 2 || ( argv[1] && *argv[1] == '-')) {
+ if (argc != 2 || *argv[1] == '-') {
usage(freeramdisk_usage);
}
- if (argc >1)
- strcpy(rname, argv[1]);
-
- if ((f = open(rname, O_RDWR)) == -1) {
- fatalError( "freeramdisk: cannot open %s: %s\n", rname, strerror(errno));
+ if ((f = open(argv[1], O_RDWR)) == -1) {
+ fatalError( "freeramdisk: cannot open %s: %s\n", argv[1], strerror(errno));
}
if (ioctl(f, BLKFLSBUF) < 0) {
- fatalError( "freeramdisk: failed ioctl on %s: %s\n", rname, strerror(errno));
+ fatalError( "freeramdisk: failed ioctl on %s: %s\n", argv[1], strerror(errno));
}
/* Don't bother closing. Exit does
* that, so we can save a few bytes */