|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/uds-releases/jasper/kernelLinux/uds/stringLinuxKernel.c#1 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include <linux/mm.h>
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "errors.h"
|
|
Packit Service |
310c69 |
#include "logger.h"
|
|
Packit Service |
310c69 |
#include "stringUtils.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
int stringToSignedLong(const char *nptr, long *num)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
while (*nptr == ' ') {
|
|
Packit Service |
310c69 |
nptr++;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return kstrtol(nptr, 10, num) ? UDS_INVALID_ARGUMENT : UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
int stringToUnsignedLong(const char *nptr, unsigned long *num)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
while (*nptr == ' ') {
|
|
Packit Service |
310c69 |
nptr++;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
if (*nptr == '+') {
|
|
Packit Service |
310c69 |
nptr++;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
return kstrtoul(nptr, 10, num) ? UDS_INVALID_ARGUMENT : UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
char *nextToken(char *str, const char *delims, char **state)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
char *sp = str ? str : *state;
|
|
Packit Service |
310c69 |
while (*sp && strchr(delims, *sp)) {
|
|
Packit Service |
310c69 |
++sp;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
if (!*sp) {
|
|
Packit Service |
310c69 |
return NULL;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
char *ep = sp;
|
|
Packit Service |
310c69 |
while (*ep && !strchr(delims, *ep)) {
|
|
Packit Service |
310c69 |
++ep;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
if (*ep) {
|
|
Packit Service |
310c69 |
*ep++ = '\0';
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
*state = ep;
|
|
Packit Service |
310c69 |
return sp;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/*****************************************************************************/
|
|
Packit Service |
310c69 |
int parseUint64(const char *str, uint64_t *num)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
unsigned long value = *num;
|
|
Packit Service |
310c69 |
int result = stringToUnsignedLong(str, &value);
|
|
Packit Service |
310c69 |
*num = value;
|
|
Packit Service |
310c69 |
return result;
|
|
Packit Service |
310c69 |
}
|