+// 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
* Add option -2 to allow v2 header
*/
+#include <byteswap.h>
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#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);
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;
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 */
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();