OpenOCD
strutil.c
Go to the documentation of this file.
1 /*
2  * This file is part of the libjaylink project.
3  *
4  * Copyright (C) 2016 Marc Schink <jaylink-dev@marcschink.de>
5  *
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.
10  *
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.
15  *
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/>.
18  */
19 
20 #include <stdlib.h>
21 #include <stdint.h>
22 #include <errno.h>
23 
24 #include "libjaylink.h"
25 
49  uint32_t *serial_number)
50 {
51  char *end_ptr;
52  unsigned long long tmp;
53 
54  if (!str || !serial_number)
55  return JAYLINK_ERR_ARG;
56 
57  errno = 0;
58  tmp = strtoull(str, &end_ptr, 10);
59 
60  if (*end_ptr != '\0' || errno != 0 || tmp > UINT32_MAX)
61  return JAYLINK_ERR;
62 
63  *serial_number = tmp;
64 
65  return JAYLINK_OK;
66 }
JAYLINK_API int jaylink_parse_serial_number(const char *str, uint32_t *serial_number)
Convert a string representation of a serial number to an integer.
Definition: strutil.c:48