9
0
Fork 0

implement -p option to pad output to a given size

This commit is contained in:
Sascha Hauer 2007-07-05 21:36:32 +02:00
parent bc1e507198
commit 631b71e69c
1 changed files with 23 additions and 3 deletions

View File

@ -56,17 +56,18 @@ void usage(char *prgname)
"\n"
"options:\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);
}
int main(int argc, char *argv[])
{
int opt;
int save = 0, load = 0;
int save = 0, load = 0, pad = 0, fd;
char *filename = NULL, *dirname = NULL;
while((opt = getopt(argc, argv, "sl")) != -1) {
while((opt = getopt(argc, argv, "slp:")) != -1) {
switch (opt) {
case 's':
save = 1;
@ -74,6 +75,9 @@ int main(int argc, char *argv[])
case 'l':
load = 1;
break;
case 'p':
pad = strtoul(optarg, NULL, 0);
break;
}
}
@ -90,6 +94,22 @@ int main(int argc, char *argv[])
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) {
printf("loading env from file %s to %s\n", filename, dirname);
envfs_load(filename, dirname);