2 * Copyright © 2014 Intel Corporation.
4 * Contact: Imran Zaman <imran.zaman@linux.intel.com>
6 * Permission to use, copy, modify, distribute, and sell this software and
7 * its documentation for any purpose is hereby granted without fee, provided
8 * that the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of the copyright holders not be used in
11 * advertising or publicity pertaining to distribution of the software
12 * without specific, written prior permission. The copyright holders make
13 * no representations about the suitability of this software for any
14 * purpose. It is provided "as is" without express or implied warranty.
16 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
18 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
20 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
21 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
34 #include <wayland-util.h>
42 convert_strtol(const char *str, char **endptr, int base, long *val)
46 int prev_errno = errno;
54 v = strtol(str, endptr, base);
55 if (errno != 0 || *endptr == str || **endptr != '\0')
64 convert_strtoul (const char *str, char **endptr, int base, unsigned long *val)
69 int prev_errno = errno;
74 /* check for negative numbers */
76 if (!isspace(str[i])) {
89 v = strtoul(str, endptr, base);
90 if (errno != 0 || *endptr == str || **endptr != '\0')
99 weston_strtoi(const char *str, char **endptr, int base, int *val)
103 if (!convert_strtol(str, endptr, base, &v) || v > INT_MAX
112 weston_strtol(const char *str, char **endptr, int base, long *val)
114 return convert_strtol(str, endptr, base, val);
118 weston_strtoui(const char *str, char **endptr, int base, unsigned int *val)
122 if (!convert_strtoul(str, endptr, base, &v) || v > UINT_MAX)
125 *val = (unsigned int)v;
130 weston_strtoul(const char *str, char **endptr, int base, unsigned long *val)
132 return convert_strtoul(str, endptr, base, val);