input/CdioParanoia: parse_cdio_uri() returns CdioUri

The `bool` return value isn't used anymore, so we can just return the
parsed object instead of passing it as an output parameter.
This commit is contained in:
Max Kellermann 2018-10-29 14:21:09 +01:00
parent e33c08357a
commit 92523f8cf2
1 changed files with 18 additions and 18 deletions

View File

@ -127,43 +127,45 @@ struct CdioUri {
int track; int track;
}; };
static bool static CdioUri
parse_cdio_uri(CdioUri *dest, const char *src) parse_cdio_uri(const char *src)
{ {
CdioUri dest;
if (*src == 0) { if (*src == 0) {
/* play the whole CD in the default drive */ /* play the whole CD in the default drive */
dest->device[0] = 0; dest.device[0] = 0;
dest->track = -1; dest.track = -1;
return true; return dest;
} }
const char *slash = strrchr(src, '/'); const char *slash = strrchr(src, '/');
if (slash == nullptr) { if (slash == nullptr) {
/* play the whole CD in the specified drive */ /* play the whole CD in the specified drive */
CopyTruncateString(dest->device, src, sizeof(dest->device)); CopyTruncateString(dest.device, src, sizeof(dest.device));
dest->track = -1; dest.track = -1;
return true; return dest;
} }
size_t device_length = slash - src; size_t device_length = slash - src;
if (device_length >= sizeof(dest->device)) if (device_length >= sizeof(dest.device))
device_length = sizeof(dest->device) - 1; device_length = sizeof(dest.device) - 1;
memcpy(dest->device, src, device_length); memcpy(dest.device, src, device_length);
dest->device[device_length] = 0; dest.device[device_length] = 0;
const char *track = slash + 1; const char *track = slash + 1;
char *endptr; char *endptr;
dest->track = strtoul(track, &endptr, 10); dest.track = strtoul(track, &endptr, 10);
if (*endptr != 0) if (*endptr != 0)
throw std::runtime_error("Malformed track number"); throw std::runtime_error("Malformed track number");
if (endptr == track) if (endptr == track)
/* play the whole CD */ /* play the whole CD */
dest->track = -1; dest.track = -1;
return true; return dest;
} }
static AllocatedPath static AllocatedPath
@ -186,9 +188,7 @@ input_cdio_open(const char *uri,
uri = StringAfterPrefixIgnoreCase(uri, "cdda://"); uri = StringAfterPrefixIgnoreCase(uri, "cdda://");
assert(uri != nullptr); assert(uri != nullptr);
CdioUri parsed_uri; const auto parsed_uri = parse_cdio_uri(uri);
if (!parse_cdio_uri(&parsed_uri, uri))
return nullptr;
/* get list of CD's supporting CD-DA */ /* get list of CD's supporting CD-DA */
const AllocatedPath device = parsed_uri.device[0] != 0 const AllocatedPath device = parsed_uri.device[0] != 0