-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpkgmisc.c
105 lines (77 loc) · 2.33 KB
/
pkgmisc.c
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
Copyright (C) 2000 - 2008 Pawel A. Gajda <mis@pld-linux.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2 as
published by the Free Software Foundation (see file COPYING for 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.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "compiler.h"
#include "pkgmisc.h"
int poldek_util_parse_evr(char *evrstr, uint32_t *epoch, const char **version,
const char **release)
{
char *p;
while (isspace(*evrstr))
evrstr++;
if (*evrstr == '\0')
return 0;
if ((p = strchr(evrstr, ':')) == NULL) {
*epoch = 0;
} else {
*p = '\0';
if (*evrstr == '\0') {
*epoch = 0;
} else {
errno = 0;
*epoch = (uint32_t)strtol(evrstr, (char **)NULL, 10);
if (*epoch == 0 && (*evrstr != '0' || *(evrstr + 1) != '\0'))
return 0;
if (errno == EINVAL || errno == ERANGE)
return 0;
}
evrstr = p+1;
if (*evrstr == '\0') /* empty version strig */
return 0;
}
if ((p = strchr(evrstr, '-')) == NULL) {
*version = evrstr;
*release = NULL;
} else {
*p = '\0';
*version = evrstr;
*release = p+1;
if (**version == '\0' || **release == '\0')
return 0;
}
return 1;
}
int poldek_util_parse_nevr(char *nevrstr, const char **name, int32_t *epoch,
const char **version, const char **release)
{
char *p, *q;
while (isspace(*nevrstr))
nevrstr++;
if (*nevrstr == '\0')
return 0;
if ((p = strrchr(nevrstr, '-')) == NULL)
return 0;
q = p;
*q = '\0';
if ((p = strrchr(nevrstr, '-')) == NULL)
return 0;
*q = '-';
*p = '\0';
p++;
*name = nevrstr;
return poldek_util_parse_evr(p, epoch, version, release);
}