summaryrefslogtreecommitdiff
path: root/build/misc.c
blob: 4e1676564d7027d738dca67403ef5758ea383af1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/** \ingroup rpmbuild
 * \file build/misc.c
 */
#include "system.h"

#include <rpm/rpmbuild.h>
#include "debug.h"

uint32_t parseUnsignedNum(const char * line, uint32_t * res)
{
    char * s1 = NULL;
    unsigned long rc;
    uint32_t result;

    if (line == NULL) return 1;

    while (isspace(*line)) line++;
    if (!isdigit(*line)) return 1;

    rc = strtoul(line, &s1, 10);

    if (*s1 || s1 == line || rc == ULONG_MAX || rc > UINT_MAX)
        return 1;

    result = (uint32_t)rc;
    if (res) *res = result;

    return 0;
}