summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Wagner <david.wagner@free-electrons.com>2012-01-13 13:27:37 +0000
committerAnatolij Gustschin <agust@denx.de>2012-03-27 10:05:05 +0200
commit48995b5a96c99ba6243906ecab733e4269fbafe5 (patch)
tree6234fa785e9483d9b2a1a1719e116557ca4d7b55
parent3d0f9bd0349712223d5be40aa69f4ca1a1965a3e (diff)
downloadu-boot-imx-48995b5a96c99ba6243906ecab733e4269fbafe5.zip
u-boot-imx-48995b5a96c99ba6243906ecab733e4269fbafe5.tar.gz
u-boot-imx-48995b5a96c99ba6243906ecab733e4269fbafe5.tar.bz2
mkenvimage: Read/Write from/to stdin/out by default or if the filename is "-"
Signed-off-by: David Wagner <david.wagner@free-electrons.com> Acked-by: Mike Frysinger <vapier@gentoo.org>
-rw-r--r--tools/mkenvimage.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/tools/mkenvimage.c b/tools/mkenvimage.c
index b6879bc..032dc83 100644
--- a/tools/mkenvimage.c
+++ b/tools/mkenvimage.c
@@ -171,15 +171,9 @@ int main(int argc, char **argv)
memset(envptr, padbyte, envsize);
/* Open the input file ... */
- if (optind >= argc) {
- fprintf(stderr, "Please specify an input filename\n");
- return EXIT_FAILURE;
- }
-
- txt_filename = argv[optind];
- if (strcmp(txt_filename, "-") == 0) {
+ if (optind >= argc || strcmp(argv[optind], "-") == 0) {
int readbytes = 0;
- int readlen = sizeof(*envptr) * 2048;
+ int readlen = sizeof(*envptr) * 4096;
txt_fd = STDIN_FILENO;
do {
@@ -198,6 +192,7 @@ int main(int argc, char **argv)
} while (readbytes == readlen);
} else {
+ txt_filename = argv[optind];
txt_fd = open(txt_filename, O_RDONLY);
if (txt_fd == -1) {
fprintf(stderr, "Can't open \"%s\": %s\n",
@@ -287,11 +282,16 @@ int main(int argc, char **argv)
memcpy(dataptr, &targetendian_crc, sizeof(uint32_t));
- bin_fd = creat(bin_filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
- if (bin_fd == -1) {
- fprintf(stderr, "Can't open output file \"%s\": %s\n",
- bin_filename, strerror(errno));
- return EXIT_FAILURE;
+ if (!bin_filename || strcmp(bin_filename, "-") == 0) {
+ bin_fd = STDOUT_FILENO;
+ } else {
+ bin_fd = creat(bin_filename, S_IRUSR | S_IWUSR | S_IRGRP |
+ S_IWGRP);
+ if (bin_fd == -1) {
+ fprintf(stderr, "Can't open output file \"%s\": %s\n",
+ bin_filename, strerror(errno));
+ return EXIT_FAILURE;
+ }
}
if (write(bin_fd, dataptr, sizeof(*dataptr) * datasize) !=