view target-utils/libcommon/hexarg.c @ 607:d5abcbbf7432

scripts/gtm900[bp]-ffs-clean: remove some more wrong files An earlier version of GTM900-B firmware has been found in the wild that still has MFW&BMI layers included (producing files under /mmi), as well as enlarged /pcm/L[DMR]N files. These files are wrong for FreeCalypso fw and thus need to be cleaned out.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 11 Feb 2020 21:27:40 +0000
parents e7502631a0f9
children
line wrap: on
line source

/*
 * Many commands take hex arguments.  This module contains the parse_hexarg()
 * function, which is a wrapper around strtoul that performs some additional
 * checks.
 */

#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>

parse_hexarg(arg, maxdigits, valp)
	char *arg;
	int maxdigits;
	u_long *valp;
{
	char *cp = arg, *bp;
	int len;

	if (cp[0] == '0' && (cp[1] == 'x' || cp[1] == 'X'))
		cp += 2;
	for (bp = cp; *cp; cp++)
		if (!isxdigit(*cp))
			return(-1);
	len = cp - bp;
	if (len < 1 || len > maxdigits)
		return(-1);
	*valp = strtoul(arg, 0, 16);
	return(0);
}