Add more missing includes for byte swap operations
[project/firmware-utils.git] / src / trx.c
index aa1f5be4b65b66ac9a1a48d7304d9bef131080e1..4b7f778e26acead3a83454aa1c03611ab407f0e9 100644 (file)
--- a/src/trx.c
+++ b/src/trx.c
@@ -1,19 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2004  Manuel Novoa III  <mjn3@codepoet.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  */
 
 /* July 29, 2004
@@ -43,6 +30,7 @@
  * Add option -2 to allow v2 header
  */
 
+#include <byteswap.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <stddef.h>
@@ -58,7 +46,7 @@
 #define STORE32_LE(X)          (X)
 #define LOAD32_LE(X)           (X)
 #else
-#error unkown endianness!
+#error unknown endianness!
 #endif
 
 uint32_t crc32buf(char *buf, size_t len);
@@ -100,7 +88,7 @@ int main(int argc, char **argv)
        int c, i, append = 0;
        size_t n;
        ssize_t n2;
-       uint32_t cur_len, fsmark=0;
+       uint32_t cur_len, fsmark=0, magic;
        unsigned long maxlen = TRX_MAX_LEN;
        struct trx_header *p;
        char trx_version = 1;
@@ -121,7 +109,7 @@ int main(int argc, char **argv)
        in = NULL;
        i = 0;
 
-       while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:")) != -1) {
+       while ((c = getopt(argc, argv, "-:2o:m:a:x:b:f:A:F:M:")) != -1) {
                switch (c) {
                        case '2':
                                /* take care that nothing was written to buf so far */
@@ -242,6 +230,15 @@ int main(int argc, char **argv)
                                        cur_len += n2;
                                }
 
+                               break;
+                       case 'M':
+                               errno = 0;
+                               magic = strtoul(optarg, &e, 0);
+                               if (errno || (e == optarg) || *e) {
+                                       fprintf(stderr, "illegal numeric string\n");
+                                       usage();
+                               }
+                               p->magic = STORE32_LE(magic);
                                break;
                        default:
                                usage();