mirror of
https://github.com/Stichting-MINIX-Research-Foundation/u-boot.git
synced 2025-09-10 04:26:19 -04:00
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>
This commit is contained in:
parent
3d0f9bd034
commit
48995b5a96
@ -171,15 +171,9 @@ int main(int argc, char **argv)
|
|||||||
memset(envptr, padbyte, envsize);
|
memset(envptr, padbyte, envsize);
|
||||||
|
|
||||||
/* Open the input file ... */
|
/* Open the input file ... */
|
||||||
if (optind >= argc) {
|
if (optind >= argc || strcmp(argv[optind], "-") == 0) {
|
||||||
fprintf(stderr, "Please specify an input filename\n");
|
|
||||||
return EXIT_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
txt_filename = argv[optind];
|
|
||||||
if (strcmp(txt_filename, "-") == 0) {
|
|
||||||
int readbytes = 0;
|
int readbytes = 0;
|
||||||
int readlen = sizeof(*envptr) * 2048;
|
int readlen = sizeof(*envptr) * 4096;
|
||||||
txt_fd = STDIN_FILENO;
|
txt_fd = STDIN_FILENO;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
@ -198,6 +192,7 @@ int main(int argc, char **argv)
|
|||||||
} while (readbytes == readlen);
|
} while (readbytes == readlen);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
txt_filename = argv[optind];
|
||||||
txt_fd = open(txt_filename, O_RDONLY);
|
txt_fd = open(txt_filename, O_RDONLY);
|
||||||
if (txt_fd == -1) {
|
if (txt_fd == -1) {
|
||||||
fprintf(stderr, "Can't open \"%s\": %s\n",
|
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));
|
memcpy(dataptr, &targetendian_crc, sizeof(uint32_t));
|
||||||
|
|
||||||
bin_fd = creat(bin_filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
|
if (!bin_filename || strcmp(bin_filename, "-") == 0) {
|
||||||
if (bin_fd == -1) {
|
bin_fd = STDOUT_FILENO;
|
||||||
fprintf(stderr, "Can't open output file \"%s\": %s\n",
|
} else {
|
||||||
bin_filename, strerror(errno));
|
bin_fd = creat(bin_filename, S_IRUSR | S_IWUSR | S_IRGRP |
|
||||||
return EXIT_FAILURE;
|
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) !=
|
if (write(bin_fd, dataptr, sizeof(*dataptr) * datasize) !=
|
||||||
|
Loading…
x
Reference in New Issue
Block a user