[PATCH] xfsdump: make help printing a little smarter

Christoph Hellwig hch at infradead.org
Tue Nov 25 04:56:38 CST 2008


fprintf returns the number of characters printed, we can use this
for the offsetted lines.


Signed-off-by: Christoph Hellwig <hch at lst.de>

Index: xfs-cmds/xfsdump/common/main.c
===================================================================
--- xfs-cmds.orig/xfsdump/common/main.c	2008-11-13 18:39:06.000000000 +0100
+++ xfs-cmds/xfsdump/common/main.c	2008-11-13 18:40:43.000000000 +0100
@@ -960,20 +960,12 @@ main( int argc, char *argv[] )
 void
 usage( void )
 {
-	char linebuf[ 200 ];
 	int pfxsz;
-	int ps;
+	int ps = 0;
 	char *ns = "";
 
-	sprintf( linebuf,
-		 _("%s: usage: %s "),
-		 progname,
-		 basename( progname ));
-	pfxsz = strlen( linebuf );
-	ASSERT( pfxsz < sizeof( linebuf ));
-	ps = 0;
-
-	fprintf( stderr, linebuf );
+	pfxsz = fprintf(stderr, _("%s: usage: %s "),
+				progname, basename(progname));
 
 #ifdef DUMP
 	ULO(_("(dump DMF dualstate files as offline)"),	GETOPT_DUMPASOFFLINE );
Index: xfs-cmds/xfsdump/invutil/invutil.c
===================================================================
--- xfs-cmds.orig/xfsdump/invutil/invutil.c	2008-11-13 18:34:44.000000000 +0100
+++ xfs-cmds/xfsdump/invutil/invutil.c	2008-11-13 18:40:59.000000000 +0100
@@ -1082,18 +1082,12 @@ mmap_n_bytes(int fd, size_t count, bool_
 void
 usage (void)
 {
-    char linebuf[ 200 ];
     int pfxsz;
-    int ps;
+    int ps = 0;
     char *ns = "";
 
-    fprintf( stderr, "%s: %s\n", g_programName, g_programVersion );
-    snprintf( linebuf, sizeof(linebuf), "Usage: %s ", g_programName );
-    pfxsz = strlen( linebuf );
-    assert( pfxsz < sizeof( linebuf ));
-    ps = 0;
-
-    fprintf( stderr, linebuf );
+    fprintf(stderr, "%s: %s\n", g_programName, g_programVersion);
+    pfxsz = fprintf(stderr, "Usage: %s ", g_programName);
 
 #ifdef REVEAL
     ULO( "(output debug information)", GETOPT_DEBUG );



More information about the xfs mailing list