summaryrefslogtreecommitdiff
path: root/wrudf/wrudf.c
diff options
context:
space:
mode:
Diffstat (limited to 'wrudf/wrudf.c')
-rw-r--r--wrudf/wrudf.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/wrudf/wrudf.c b/wrudf/wrudf.c
index 74dcdaf..27ba7a9 100644
--- a/wrudf/wrudf.c
+++ b/wrudf/wrudf.c
@@ -13,6 +13,10 @@
#include <locale.h>
#include <sys/resource.h>
+#ifdef USE_READLINE
+#include <readline/readline.h>
+#endif
+
#include "wrudf.h"
char *devicename; /* "/dev/cdrom" or disk image filename */
@@ -21,12 +25,12 @@ int devicetype;
enum MEDIUM medium;
int ignoreReadError; /* used while reading VRS which may be absent on open CDR */
-#ifdef _GNU_SOURCE
+#ifdef USE_READLINE
char *line;
#define GETLINE(prompt) readLine(prompt);
#else
char line[256];
-#define GETLINE(prompt) printf(prompt); fgets(line, 256, stdin); *strchr(line, '\n') = 0;
+#define GETLINE(prompt) do { printf("%s", prompt); if (fgets(line, 256, stdin)) *strchr(line, '\n') = 0; else line[0] = 0; } while (0)
#endif
@@ -74,12 +78,14 @@ struct sparingTable *st;
int spaceMapDirty, usdDirty, sparingTableDirty;
+#ifdef USE_READLINE
char* readLine(char* prompt) {
if( line ) {
free(line);
}
return line = readline(prompt);
}
+#endif
void
@@ -310,9 +316,14 @@ initialise(char *devicename)
fsdOut[0] = 0;
printf("You are going to update fileset '%s'\nProceed (y/N) : ", fsdOut);
- readLine(NULL);
+ GETLINE("");
+
+#ifdef USE_READLINE
+ if( !line )
+ fail("wrudf terminated\n");
+#endif
- if( !line || line[0] != 'y' )
+ if( line[0] != 'y' )
fail("wrudf terminated\n");
/* Read Logical Volume Integrity sequence */
@@ -632,7 +643,7 @@ parseCmnd(char* line)
int show_help()
{
char *msg =
- "Interactive tool to maintain an UDF filesystem.\n"
+ "Interactive tool to maintain a UDF filesystem.\n"
"Usage:\n"
"\twrudf [device]\n"
"Available commands:\n"