OpenOCD
common.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 
3 /***************************************************************************
4  * Copyright (C) 2009 by Zachary T Welch <zw@superlucidity.net> *
5  ***************************************************************************/
6 
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10 
11 #include "common.h"
12 #include <helper/log.h>
13 
14 unsigned int get_flash_name_index(const char *name)
15 {
16  const char *name_index = strrchr(name, '.');
17  if (!name_index)
18  return 0;
19  if (name_index[1] < '0' || name_index[1] > '9')
20  return ~0U;
21  unsigned int requested;
22  int retval = parse_uint(name_index + 1, &requested);
23  /* detect parsing error by forcing past end of bank list */
24  return (retval == ERROR_OK) ? requested : ~0U;
25 }
26 
27 bool flash_driver_name_matches(const char *name, const char *expected)
28 {
29  unsigned int blen = strlen(name);
30  /* only match up to the length of the driver name... */
31  if (strncmp(name, expected, blen) != 0)
32  return false;
33 
34  /* ...then check that name terminates at this spot. */
35  return expected[blen] == '.' || expected[blen] == '\0';
36 }
const char * name
Definition: armv4_5.c:76
bool flash_driver_name_matches(const char *name, const char *expected)
Attempt to match the expected name with the name of a driver.
Definition: common.c:27
unsigned int get_flash_name_index(const char *name)
Parses the optional '.index' portion of a flash bank identifier.
Definition: common.c:14
#define ERROR_OK
Definition: log.h:164