monotone

monotone Mtn Source Tree

Root/idna/version.c

1/* version.cVersion handling.
2 * Copyright (C) 2002, 2003 Simon Josefsson
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 *
5 * This file is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This file is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this file; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21/* This file is based on src/global.c from Werner Koch's libgcrypt */
22
23#if HAVE_CONFIG_H
24# include "config.h"
25#endif
26
27#include <ctype.h>
28#include <string.h>
29
30#include "idna/stringprep.h"
31
32static const char *
33parse_version_number (const char *s, int *number)
34{
35 int val = 0;
36
37 if (*s == '0' && isdigit (s[1]))
38 return NULL;/* leading zeros are not allowed */
39 for (; isdigit (*s); s++)
40 {
41 val *= 10;
42 val += *s - '0';
43 }
44 *number = val;
45 return val < 0 ? NULL : s;
46}
47
48
49static const char *
50parse_version_string (const char *s, int *major, int *minor, int *micro)
51{
52 s = parse_version_number (s, major);
53 if (!s || *s != '.')
54 return NULL;
55 s++;
56 s = parse_version_number (s, minor);
57 if (!s || *s != '.')
58 return NULL;
59 s++;
60 s = parse_version_number (s, micro);
61 if (!s)
62 return NULL;
63 return s;/* patchlevel */
64}
65
66/**
67 * stringprep_check_version
68 * @req_version: Required version number, or NULL.
69 *
70 * Check that the the version of the library is at minimum the requested one
71 * and return the version string; return NULL if the condition is not
72 * satisfied. If a NULL is passed to this function, no check is done,
73 * but the version string is simply returned.
74 *
75 * See %STRINGPREP_VERSION for a suitable @req_version string.
76 *
77 * Return value: Version string of run-time library, or NULL if the
78 * run-time library does not meet the required version number.
79 */
80const char *
81stringprep_check_version (const char *req_version)
82{
83 const char *ver = STRINGPREP_VERSION;
84 int my_major, my_minor, my_micro;
85 int rq_major, rq_minor, rq_micro;
86 const char *my_plvl, *rq_plvl;
87
88 if (!req_version)
89 return ver;
90
91 my_plvl = parse_version_string (ver, &my_major, &my_minor, &my_micro);
92 if (!my_plvl)
93 return NULL;/* very strange our own version is bogus */
94 rq_plvl = parse_version_string (req_version, &rq_major, &rq_minor,
95 &rq_micro);
96 if (!rq_plvl)
97 return NULL;/* req version string is invalid */
98
99 if (my_major > rq_major
100 || (my_major == rq_major && my_minor > rq_minor)
101 || (my_major == rq_major && my_minor == rq_minor
102 && my_micro > rq_micro)
103 || (my_major == rq_major && my_minor == rq_minor
104 && my_micro == rq_micro && strcmp (my_plvl, rq_plvl) >= 0))
105 {
106 return ver;
107 }
108 return NULL;
109}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status