1 /* ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
\r
3 Copyright (c) 2014-2015 Datalight, Inc.
\r
4 All Rights Reserved Worldwide.
\r
6 This program is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; use version 2 of the License.
\r
10 This program is distributed in the hope that it will be useful,
\r
11 but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
\r
12 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 GNU General Public License for more details.
\r
15 You should have received a copy of the GNU General Public License along
\r
16 with this program; if not, write to the Free Software Foundation, Inc.,
\r
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
19 /* Businesses and individuals that for commercial or other reasons cannot
\r
20 comply with the terms of the GPLv2 license may obtain a commercial license
\r
21 before incorporating Reliance Edge into proprietary software for
\r
22 distribution in any form. Visit http://www.datalight.com/reliance-edge for
\r
26 @brief Implements common-code utilities for tools and tests.
\r
34 #include <redcoreapi.h>
\r
35 #include <redvolume.h>
\r
36 #include <redtoolcmn.h>
\r
39 /** @brief Convert a string into a volume number.
\r
41 In a POSIX-like configuration, @p pszVolume can either be a volume number or
\r
42 a volume path prefix. In case of ambiguity, the volume number of a matching
\r
43 path prefix takes precedence.
\r
45 In an FSE configuration, @p pszVolume can be a volume number.
\r
47 @param pszVolume The volume string.
\r
49 @return On success, returns the volume number; on failure, returns
\r
50 #REDCONF_VOLUME_COUNT.
\r
52 uint8_t RedFindVolumeNumber(
\r
53 const char *pszVolume)
\r
55 unsigned long ulNumber;
\r
56 const char *pszEndPtr;
\r
57 uint8_t bVolNum = REDCONF_VOLUME_COUNT;
\r
58 #if REDCONF_API_POSIX == 1
\r
62 /* Determine if pszVolume can be interpreted as a volume number.
\r
65 ulNumber = strtoul(pszVolume, (char **)&pszEndPtr, 10);
\r
66 if((errno == 0) && (ulNumber != ULONG_MAX) && (pszEndPtr[0U] == '\0') && (ulNumber < REDCONF_VOLUME_COUNT))
\r
68 bVolNum = (uint8_t)ulNumber;
\r
71 #if REDCONF_API_POSIX == 1
\r
72 /* Determine if pszVolume is a valid path prefix.
\r
74 for(bIndex = 0U; bIndex < REDCONF_VOLUME_COUNT; bIndex++)
\r
76 if(strcmp(gaRedVolConf[bIndex].pszPathPrefix, pszVolume) == 0)
\r
82 if(bIndex < REDCONF_VOLUME_COUNT)
\r
84 /* Edge case: It is technically possible for pszVolume to be both a
\r
85 valid volume number and a valid volume prefix, for different
\r
86 volumes. For example, if pszVolume is "2", that would be recognized
\r
87 as volume number 2 above. But if "2" is the (poorly chosen) path
\r
88 prefix for volume number 4, that would also be matched. Since the
\r
89 POSIX-like API is primarily name based, and the ability to use
\r
90 volume numbers with this tool is just a convenience, the volume
\r
91 prefix takes precedence.
\r