summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2010-05-21 13:07:05 +0100
committerRichard Jones <rjones@redhat.com>2010-05-21 14:51:53 +0100
commit5e1aff7856f721bf5737815a5b65c0de23ab0b0c (patch)
treeddd3d988143b13ad341cd4fb246e34b84875742b /src
parent48a216a06d6fdab3c8292c383a37cd990c0bf939 (diff)
downloadlibguestfs-5e1aff7856f721bf5737815a5b65c0de23ab0b0c.tar.gz
libguestfs-5e1aff7856f721bf5737815a5b65c0de23ab0b0c.tar.xz
libguestfs-5e1aff7856f721bf5737815a5b65c0de23ab0b0c.zip
fish: Allow suffixes on number parameters (eg. 1M)
This small change uses the gnulib xstrtoll functionality to enable suffixes on integer parameters in guestfish. For example: truncate-size /file 1G (previously you would have had to given the full number). This also applies to the 'alloc' and 'sparse' commands (and indirectly to the -N option). The specification for these commands has changed slightly, in that 'alloc foo 1MB' would now use SI units, allocating 1000000 bytes instead of a true megabyte. All existing uses would use 'alloc foo 1M' which still allocates true megabytes.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/generator.ml5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/generator.ml b/src/generator.ml
index d4ef81a4..aca56a87 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -7456,6 +7456,9 @@ and generate_fish_cmds () =
pr "#include \"xstrtol.h\"\n";
pr "#include \"fish.h\"\n";
pr "\n";
+ pr "/* Valid suffixes allowed for numbers. See Gnulib xstrtol function. */\n";
+ pr "static const char *xstrtol_suffixes = \"0kKMGTPEZY\";\n";
+ pr "\n";
(* list_commands function, which implements guestfish -h *)
pr "void list_commands (void)\n";
@@ -7674,7 +7677,7 @@ and generate_fish_cmds () =
pr " strtol_error xerr;\n";
pr " %s r;\n" fntyp;
pr "\n";
- pr " xerr = %s (argv[%d], NULL, 0, &r, \"\");\n" fn i;
+ pr " xerr = %s (argv[%d], NULL, 0, &r, xstrtol_suffixes);\n" fn i;
pr " if (xerr != LONGINT_OK) {\n";
pr " fprintf (stderr,\n";
pr " _(\"%%s: %%s: invalid integer parameter (%%s returned %%d)\\n\"),\n";