summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2007-07-05 21:36:32 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2007-07-05 21:36:32 +0200
commit631b71e69c43dffbc3fc0c4ad92d87bdb1ccd9db (patch)
treef3a288bb5e5ef9b3e349e0cb3934676f0f5dab28 /scripts
parentbc1e507198ecadf12b4c40f4977487cd4d2df34b (diff)
downloadbarebox-631b71e69c43dffbc3fc0c4ad92d87bdb1ccd9db.tar.gz
barebox-631b71e69c43dffbc3fc0c4ad92d87bdb1ccd9db.tar.xz
implement -p option to pad output to a given size
Diffstat (limited to 'scripts')
-rw-r--r--scripts/ubootenv.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/scripts/ubootenv.c b/scripts/ubootenv.c
index af5efd0b54..eb62123faf 100644
--- a/scripts/ubootenv.c
+++ b/scripts/ubootenv.c
@@ -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);