acrn-hypervisor/devicemodel/lib/dm_string.c
Jie Deng 7579678dd6 dm: add const declaration for dm_strto* APIs
These APIs are wrap of standard strto* APIs. The first parameters in
these APIs should be declared as "const" since they have never been
changed so that they can also be used when passing a variable declared
as const char *

Fixes: e1dab512c2 ("dm: add string convert API")
Tracked-on: #1496

Signed-off-by: Jie Deng <jie.deng@intel.com>
Reviewed-by: Conghui Chen <conghui.chen@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
2018-10-24 18:16:37 +08:00

70 lines
1.1 KiB
C

/*
* Copyright (C) 2018 Intel Corporation. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "dm_string.h"
int
dm_strtol(const char *s, char **end, unsigned int base, long *val)
{
if (!s)
goto err;
*val = strtol(s, end, base);
if (*end == s) {
printf("ERROR! nothing covert for: %s!\n", s);
goto err;
}
return 0;
err:
return -1;
}
int
dm_strtoi(const char *s, char **end, unsigned int base, int *val)
{
long l_val;
int ret;
l_val = 0;
ret = dm_strtol(s, end, base, &l_val);
*val = (int)l_val;
return ret;
}
int
dm_strtoul(const char *s, char **end, unsigned int base, unsigned long *val)
{
if (!s)
goto err;
*val = strtoul(s, end, base);
if (*end == s) {
printf("ERROR! nothing covert for: %s!\n", s);
goto err;
}
return 0;
err:
return -1;
}
int
dm_strtoui(const char *s, char **end, unsigned int base, unsigned int *val)
{
unsigned long l_val;
int ret;
l_val = 0;
ret = dm_strtoul(s, end, base, &l_val);
*val = (unsigned int)l_val;
return ret;
}