doc: describe tcl port consistently.
[openocd.git] / src / flash / common.c
blobebd9396eb0720a299810616804dc742960c59d1a
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 /***************************************************************************
4 * Copyright (C) 2009 by Zachary T Welch <zw@superlucidity.net> *
5 ***************************************************************************/
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
11 #include "common.h"
12 #include <helper/log.h>
14 unsigned get_flash_name_index(const char *name)
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 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;
27 bool flash_driver_name_matches(const char *name, const char *expected)
29 unsigned blen = strlen(name);
30 /* only match up to the length of the driver name... */
31 if (strncmp(name, expected, blen) != 0)
32 return false;
34 /* ...then check that name terminates at this spot. */
35 return expected[blen] == '.' || expected[blen] == '\0';