implement -p option to pad output to a given size
This commit is contained in:
parent
bc1e507198
commit
631b71e69c
|
@ -56,17 +56,18 @@ void usage(char *prgname)
|
||||||
"\n"
|
"\n"
|
||||||
"options:\n"
|
"options:\n"
|
||||||
" -s save (directory -> environment sector)\n"
|
" -s save (directory -> environment sector)\n"
|
||||||
" -l load (environment sector -> directory)\n",
|
" -l load (environment sector -> directory)\n"
|
||||||
|
" -p <size> pad output file to given size\n",
|
||||||
prgname);
|
prgname);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
int save = 0, load = 0;
|
int save = 0, load = 0, pad = 0, fd;
|
||||||
char *filename = NULL, *dirname = NULL;
|
char *filename = NULL, *dirname = NULL;
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "sl")) != -1) {
|
while((opt = getopt(argc, argv, "slp:")) != -1) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 's':
|
case 's':
|
||||||
save = 1;
|
save = 1;
|
||||||
|
@ -74,6 +75,9 @@ int main(int argc, char *argv[])
|
||||||
case 'l':
|
case 'l':
|
||||||
load = 1;
|
load = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'p':
|
||||||
|
pad = strtoul(optarg, NULL, 0);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,6 +94,22 @@ int main(int argc, char *argv[])
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (save) {
|
||||||
|
fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY, 0644);
|
||||||
|
if (fd < 0) {
|
||||||
|
perror("open");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (save && pad) {
|
||||||
|
if (truncate(filename, pad)) {
|
||||||
|
perror("truncate");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (load) {
|
if (load) {
|
||||||
printf("loading env from file %s to %s\n", filename, dirname);
|
printf("loading env from file %s to %s\n", filename, dirname);
|
||||||
envfs_load(filename, dirname);
|
envfs_load(filename, dirname);
|
||||||
|
|
Loading…
Reference in New Issue