Commit 48995b5a96c99ba6243906ecab733e4269fbafe5
Committed by
Anatolij Gustschin
1 parent
3d0f9bd034
Exists in
master
and in
54 other branches
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>
Showing 1 changed file with 13 additions and 13 deletions Side-by-side Diff
tools/mkenvimage.c
... | ... | @@ -171,15 +171,9 @@ |
171 | 171 | memset(envptr, padbyte, envsize); |
172 | 172 | |
173 | 173 | /* Open the input file ... */ |
174 | - if (optind >= argc) { | |
175 | - fprintf(stderr, "Please specify an input filename\n"); | |
176 | - return EXIT_FAILURE; | |
177 | - } | |
178 | - | |
179 | - txt_filename = argv[optind]; | |
180 | - if (strcmp(txt_filename, "-") == 0) { | |
174 | + if (optind >= argc || strcmp(argv[optind], "-") == 0) { | |
181 | 175 | int readbytes = 0; |
182 | - int readlen = sizeof(*envptr) * 2048; | |
176 | + int readlen = sizeof(*envptr) * 4096; | |
183 | 177 | txt_fd = STDIN_FILENO; |
184 | 178 | |
185 | 179 | do { |
... | ... | @@ -198,6 +192,7 @@ |
198 | 192 | } while (readbytes == readlen); |
199 | 193 | |
200 | 194 | } else { |
195 | + txt_filename = argv[optind]; | |
201 | 196 | txt_fd = open(txt_filename, O_RDONLY); |
202 | 197 | if (txt_fd == -1) { |
203 | 198 | fprintf(stderr, "Can't open \"%s\": %s\n", |
... | ... | @@ -287,11 +282,16 @@ |
287 | 282 | |
288 | 283 | memcpy(dataptr, &targetendian_crc, sizeof(uint32_t)); |
289 | 284 | |
290 | - bin_fd = creat(bin_filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); | |
291 | - if (bin_fd == -1) { | |
292 | - fprintf(stderr, "Can't open output file \"%s\": %s\n", | |
293 | - bin_filename, strerror(errno)); | |
294 | - return EXIT_FAILURE; | |
285 | + if (!bin_filename || strcmp(bin_filename, "-") == 0) { | |
286 | + bin_fd = STDOUT_FILENO; | |
287 | + } else { | |
288 | + bin_fd = creat(bin_filename, S_IRUSR | S_IWUSR | S_IRGRP | | |
289 | + S_IWGRP); | |
290 | + if (bin_fd == -1) { | |
291 | + fprintf(stderr, "Can't open output file \"%s\": %s\n", | |
292 | + bin_filename, strerror(errno)); | |
293 | + return EXIT_FAILURE; | |
294 | + } | |
295 | 295 | } |
296 | 296 | |
297 | 297 | if (write(bin_fd, dataptr, sizeof(*dataptr) * datasize) != |