2 * This file is part of the libjaylink project.
4 * Copyright (C) 2016 Marc Schink <jaylink-dev@marcschink.de>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "libjaylink.h"
29 * String utility functions.
33 * Convert a string representation of a serial number to an integer.
35 * The string representation of the serial number must be in decimal form.
37 * @param[in] str String representation to convert.
38 * @param[out] serial_number Serial number on success, and undefined on
41 * @retval JAYLINK_OK Success.
42 * @retval JAYLINK_ERR_ARG Invalid arguments.
43 * @retval JAYLINK_ERR Conversion error. Serial number is invalid or string
44 * representation contains invalid character(s).
48 JAYLINK_API
int jaylink_parse_serial_number(const char *str
,
49 uint32_t *serial_number
)
52 unsigned long long tmp
;
54 if (!str
|| !serial_number
)
55 return JAYLINK_ERR_ARG
;
58 tmp
= strtoull(str
, &end_ptr
, 10);
60 if (*end_ptr
!= '\0' || errno
!= 0 || tmp
> UINT32_MAX
)