mtd/util nanddump.c,1.13,1.14
anoncvs
anoncvs at infradead.org
Mon Jun 28 06:27:51 EDT 2004
Update of /home/cvs/mtd/util
In directory phoenix.infradead.org:/tmp/cvs-serv3180
Modified Files:
nanddump.c
Log Message:
Enable writing to standard output by setting filename to '-'
Index: nanddump.c
===================================================================
RCS file: /home/cvs/mtd/util/nanddump.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- nanddump.c 5 May 2004 11:57:55 -0000 1.13
+++ nanddump.c 28 Jun 2004 10:27:48 -0000 1.14
@@ -21,6 +21,7 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/types.h>
@@ -48,7 +49,7 @@
/* Make sure enough arguments were passed */
if (argc < 3) {
- printf("usage: %s <mtdname> <dumpname> [start addr] [length]\n", argv[0]);
+ fprintf(stderr, "usage: %s <mtdname> <dumpname> [start addr] [length]\n", argv[0]);
exit(1);
}
@@ -68,13 +69,15 @@
/* Make sure device page sizes are valid */
if (!(meminfo.oobsize == 16 && meminfo.oobblock == 512) &&
!(meminfo.oobsize == 8 && meminfo.oobblock == 256)) {
- printf("Unknown flash (not normal NAND)\n");
+ fprintf(stderr, "Unknown flash (not normal NAND)\n");
close(fd);
exit(1);
}
- /* Open output file for writing */
- if ((ofd = open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, 0644)) == -1) {
+ /* Open output file for writing. If file name is "-", write to standard output. */
+ if (strcmp(argv[2], "-") == 0) {
+ ofd = STDOUT_FILENO;
+ } else if ((ofd = open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, 0644)) == -1) {
perror ("open outfile");
close(fd);
exit(1);
@@ -95,14 +98,14 @@
}
/* Ask user if they would like pretty output */
- printf("Would you like formatted output? ");
+ fprintf(stderr, "Would you like formatted output? ");
if (tolower(getc(stdin)) != 'y')
pretty_print = 0;
else
pretty_print = 1;
/* Print informative message */
- printf("Dumping data starting at 0x%08x and ending at 0x%08x...\n",
+ fprintf(stderr, "Dumping data starting at 0x%08x and ending at 0x%08x...\n",
start_addr, end_addr);
/* Dump the flash contents */
@@ -138,7 +141,7 @@
/* Read OOB data and exit on failure */
oob.start = ofs;
- printf("Dumping %lx\n", ofs);
+ fprintf(stderr, "Dumping %lx\n", ofs);
if (ioctl(fd, MEMREADOOB, &oob) != 0) {
perror("ioctl(MEMREADOOB)");
close(fd);
More information about the linux-mtd-cvs
mailing list