Commit e4dad42c authored by Rosen Penev's avatar Rosen Penev Committed by Max Kellermann

use std chr functions

The ones in std have overloads for const char/char. Signed-off-by: 's avatarRosen Penev <rosenp@gmail.com>
parent 99afe8e6
......@@ -27,12 +27,11 @@
#include "util/StringView.hxx"
#include <cassert>
#include <cstring>
#include <map>
#include <string>
#include <utility>
#include <string.h>
static constexpr char PERMISSION_PASSWORD_CHAR = '@';
static constexpr char PERMISSION_SEPARATOR = ',';
......@@ -89,7 +88,7 @@ initPermissions(const ConfigData &config)
permission_default = 0;
param.With([](const char *value){
const char *separator = strchr(value,
const char *separator = std::strchr(value,
PERMISSION_PASSWORD_CHAR);
if (separator == nullptr)
......
......@@ -25,7 +25,8 @@
#include "util/StringStrip.hxx"
#include "util/RuntimeError.hxx"
#include <string.h>
#include <cstring>
#include <stdlib.h>
void
......@@ -49,8 +50,8 @@ playlist_metadata_load(TextFile &file, PlaylistVector &pv, const char *name)
const char *value;
while ((line = file.ReadLine()) != nullptr &&
strcmp(line, "playlist_end") != 0) {
colon = strchr(line, ':');
std::strcmp(line, "playlist_end") != 0) {
colon = std::strchr(line, ':');
if (colon == nullptr || colon == line)
throw FormatRuntimeError("unknown line in db: %s",
line);
......@@ -58,7 +59,7 @@ playlist_metadata_load(TextFile &file, PlaylistVector &pv, const char *name)
*colon++ = 0;
value = StripLeft(colon);
if (strcmp(line, "mtime") == 0)
if (std::strcmp(line, "mtime") == 0)
pm.mtime = std::chrono::system_clock::from_time_t(strtol(value, nullptr, 10));
else
throw FormatRuntimeError("unknown line in db: %s",
......
......@@ -43,8 +43,7 @@
#include "util/UriExtract.hxx"
#include <cassert>
#include <string.h>
#include <cstring>
static const char PLAYLIST_COMMENT = '#';
......@@ -81,9 +80,9 @@ spl_valid_name(const char *name_utf8)
* filenames isn't going to happen, either.
*/
return strchr(name_utf8, '/') == nullptr &&
strchr(name_utf8, '\n') == nullptr &&
strchr(name_utf8, '\r') == nullptr;
return std::strchr(name_utf8, '/') == nullptr &&
std::strchr(name_utf8, '\n') == nullptr &&
std::strchr(name_utf8, '\r') == nullptr;
}
static const AllocatedPath &
......
......@@ -96,7 +96,7 @@ song_load(TextFile &file, const char *uri,
char *line;
while ((line = file.ReadLine()) != nullptr &&
!StringIsEqual(line, SONG_END)) {
char *colon = strchr(line, ':');
char *colon = std::strchr(line, ':');
if (colon == nullptr || colon == line) {
throw FormatRuntimeError("unknown line in db: %s", line);
}
......
......@@ -44,7 +44,7 @@ SongPtr
Song::LoadFile(Storage &storage, const char *path_utf8, Directory &parent)
{
assert(!uri_has_scheme(path_utf8));
assert(strchr(path_utf8, '\n') == nullptr);
assert(std::strchr(path_utf8, '\n') == nullptr);
auto song = std::make_unique<Song>(path_utf8, parent);
if (!song->UpdateFile(storage))
......@@ -95,7 +95,7 @@ Song::LoadFromArchive(ArchiveFile &archive, const char *name_utf8,
Directory &parent) noexcept
{
assert(!uri_has_scheme(name_utf8));
assert(strchr(name_utf8, '\n') == nullptr);
assert(std::strchr(name_utf8, '\n') == nullptr);
auto song = std::make_unique<Song>(name_utf8, parent);
if (!song->UpdateFileInArchive(archive))
......
......@@ -23,7 +23,7 @@
#include "Instance.hxx"
#include "util/StringStrip.hxx"
#include <string.h>
#include <cstring>
BufferedSocket::InputResult
Client::OnSocketInput(void *data, size_t length) noexcept
......@@ -32,7 +32,7 @@ Client::OnSocketInput(void *data, size_t length) noexcept
return InputResult::PAUSE;
char *p = (char *)data;
char *newline = (char *)memchr(p, '\n', length);
char *newline = (char *)std::memchr(p, '\n', length);
if (newline == nullptr)
return InputResult::MORE;
......
......@@ -44,7 +44,7 @@ gcc_pure
static bool
skip_path(const char *name_utf8) noexcept
{
return strchr(name_utf8, '\n') != nullptr;
return std::strchr(name_utf8, '\n') != nullptr;
}
#if defined(_WIN32) && GCC_CHECK_VERSION(4,6)
......@@ -185,7 +185,7 @@ handle_mount(Client &client, Request args, Response &r)
return CommandResult::ERROR;
}
if (strchr(local_uri, '/') != nullptr) {
if (std::strchr(local_uri, '/') != nullptr) {
/* allow only top-level mounts for now */
/* TODO: eliminate this limitation after ensuring that
UpdateQueue::Erase() really gets called for every
......
......@@ -103,7 +103,7 @@ ParsePath(const char *path)
++path;
} else {
const char *slash = strchr(path, '/');
const char *slash = std::strchr(path, '/');
const char *end = slash == nullptr
? path + strlen(path)
: slash;
......
......@@ -55,7 +55,7 @@ void
UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory,
const char *name) noexcept
{
const char *tmp = strchr(name, '/');
const char *tmp = std::strchr(name, '/');
if (tmp) {
const std::string_view child_name(name, tmp - name);
//add dir is not there already
......
......@@ -148,7 +148,7 @@ WatchDirectory::GetUriFS() const noexcept
static bool skip_path(const char *path)
{
return PathTraitsFS::IsSpecialFilename(path) ||
strchr(path, '\n') != nullptr;
std::strchr(path, '\n') != nullptr;
}
static void
......
......@@ -191,7 +191,7 @@ UpdateWalk::UpdateDirectoryChild(Directory &directory,
const ExcludeList &exclude_list,
const char *name, const StorageFileInfo &info) noexcept
try {
assert(strchr(name, '/') == nullptr);
assert(std::strchr(name, '/') == nullptr);
if (info.IsRegular()) {
UpdateRegularFile(directory, name, info);
......@@ -223,7 +223,7 @@ gcc_pure
static bool
skip_path(const char *name_utf8) noexcept
{
return strchr(name_utf8, '\n') != nullptr;
return std::strchr(name_utf8, '\n') != nullptr;
}
gcc_pure
......
......@@ -29,11 +29,10 @@
#include "util/Math.hxx"
#include "Log.hxx"
#include <neaacdec.h>
#include <cassert>
#include <cstring>
#include <string.h>
#include <neaacdec.h>
static const unsigned adts_sample_rates[] =
{ 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
......@@ -72,8 +71,7 @@ adts_find_frame(DecoderBuffer &buffer)
return 0;
/* find the 0xff marker */
const auto *p = (const uint8_t *)
memchr(data.data, 0xff, data.size);
auto p = (const uint8_t *)std::memchr(data.data, 0xff, data.size);
if (p == nullptr) {
/* no marker - discard the buffer */
buffer.Clear();
......
......@@ -164,7 +164,7 @@ ParseConfigLine(char *line, const char *dir_name, AllocatedPath &result_dir)
char *line_end;
// find end of the string
if (quoted) {
line_end = strrchr(line, '"');
line_end = std::strrchr(line, '"');
if (line_end == nullptr)
return true;
} else {
......
......@@ -196,7 +196,7 @@ struct PathTraitsUTF8 {
assert(p != nullptr);
#endif
return strrchr(p, SEPARATOR);
return std::strrchr(p, SEPARATOR);
}
#ifdef _WIN32
......
......@@ -133,7 +133,7 @@ parse_cdio_uri(const char *src)
return dest;
}
const char *slash = strrchr(src, '/');
const char *slash = std::strrchr(src, '/');
if (slash == nullptr) {
/* play the whole CD in the specified drive */
CopyTruncateString(dest.device, src, sizeof(dest.device));
......
......@@ -25,10 +25,10 @@
#include "util/ASCII.hxx"
#include <cassert>
#include <cstring>
#include <stdexcept>
#include <utility>
#include <string.h>
#include <fcntl.h>
NfsFileReader::NfsFileReader() noexcept
......@@ -97,7 +97,7 @@ NfsFileReader::Open(const char *uri)
uri += 6;
const char *slash = strchr(uri, '/');
const char *slash = std::strchr(uri, '/');
if (slash == nullptr)
throw std::runtime_error("Malformed nfs:// URI");
......@@ -112,7 +112,7 @@ NfsFileReader::Open(const char *uri)
new_path = "/";
path = new_path;
} else {
slash = strrchr(uri + 1, '/');
slash = std::strrchr(uri + 1, '/');
if (slash == nullptr || slash[1] == 0)
throw std::runtime_error("Malformed nfs:// URI");
......
......@@ -124,7 +124,7 @@ ExtractHost(const char *src) noexcept
/* "[hostname]:port" (IPv6?) */
hostname = ++src;
const char *end = strchr(hostname, ']');
const char *end = std::strchr(hostname, ']');
if (end == nullptr || end == hostname)
/* failed, return nullptr */
return result;
......
......@@ -65,7 +65,7 @@ ai_is_passive(const struct addrinfo *ai)
static void
FindAndResolveInterfaceName(char *host, size_t size)
{
char *percent = strchr(host, '%');
char *percent = std::strchr(host, '%');
if (percent == nullptr || percent + 64 > host + size)
return;
......
......@@ -84,7 +84,7 @@ SocketAddress::GetLocalPath() const noexcept
/* must be null-terminated */
raw.back() == 0 &&
/* there must not be any other null byte */
memchr(raw.data, 0, raw.size - 1) == nullptr
std::memchr(raw.data, 0, raw.size - 1) == nullptr
? raw.data
: nullptr;
}
......
......@@ -35,6 +35,7 @@
#include <algorithm>
#include <cassert>
#include <cstring>
#ifdef _WIN32
#include <ws2tcpip.h>
......@@ -49,8 +50,6 @@
#include <sys/un.h>
#endif
#include <string.h>
#ifdef HAVE_UN
static std::string
......@@ -104,7 +103,7 @@ ToString(SocketAddress address) noexcept
return "unknown";
#ifdef HAVE_IPV6
if (strchr(host, ':') != nullptr) {
if (std::strchr(host, ':') != nullptr) {
std::string result("[");
result.append(host);
result.append("]:");
......
......@@ -28,8 +28,8 @@
#include "Log.hxx"
#include <cassert>
#include <cstring>
#include <string.h>
#include <stdio.h>
HttpdClient::~HttpdClient() noexcept
......@@ -95,7 +95,7 @@ HttpdClient::HandleLine(const char *line) noexcept
should_reject = true;
}
line = strchr(line, ' ');
line = std::strchr(line, ' ');
if (line == nullptr || strncmp(line + 1, "HTTP/", 5) != 0) {
/* HTTP/0.9 without request headers */
......@@ -413,7 +413,7 @@ HttpdClient::OnSocketInput(void *data, size_t length) noexcept
}
char *line = (char *)data;
char *newline = (char *)memchr(line, '\n', length);
char *newline = (char *)std::memchr(line, '\n', length);
if (newline == nullptr)
return InputResult::MORE;
......
......@@ -78,7 +78,7 @@ playlist_check_translate_song(DetachedSong &song, std::string_view base_uri,
const char *uri = song.GetURI();
#ifdef _WIN32
if (!PathTraitsUTF8::IsAbsolute(uri) && strchr(uri, '\\') != nullptr) {
if (!PathTraitsUTF8::IsAbsolute(uri) && std::strchr(uri, '\\') != nullptr) {
/* Windows uses the backslash as path separator, but
the MPD protocol uses the (forward) slash by
definition; to allow backslashes in relative URIs
......
......@@ -24,8 +24,8 @@
#include "util/CharUtil.hxx"
#include <cassert>
#include <cstring>
#include <string.h>
#include <stdlib.h>
static const char *
......@@ -49,7 +49,7 @@ cue_next_quoted(char *p, char **pp)
assert(p >= *pp);
assert(p[-1] == '"');
char *end = strchr(p, '"');
char *end = std::strchr(p, '"');
if (end == nullptr) {
/* syntax error - ignore it silently */
*pp = p + strlen(p);
......
......@@ -175,7 +175,7 @@ static unsigned
ParseStatus(const char *s)
{
/* skip the "HTTP/1.1" prefix */
const char *space = strchr(s, ' ');
const char *space = std::strchr(s, ' ');
if (space == nullptr)
return 0;
......
......@@ -412,7 +412,7 @@ CreateNfsStorageURI(EventLoop &event_loop, const char *base)
if (p == nullptr)
return nullptr;
const char *mount = strchr(p, '/');
const char *mount = std::strchr(p, '/');
if (mount == nullptr)
throw std::runtime_error("Malformed nfs:// URI");
......
......@@ -357,7 +357,7 @@ CreateUdisksStorageURI(EventLoop &event_loop, const char *base_uri)
std::string id;
const char *relative_path = strchr(id_begin, '/');
const char *relative_path = std::strchr(id_begin, '/');
if (relative_path == nullptr) {
id = id_begin;
relative_path = "";
......
......@@ -24,10 +24,9 @@
#include <cassert>
#include <cstdint>
#include <cstring>
#include <memory>
#include <string.h>
struct ApeFooter {
unsigned char id[8];
uint32_t version;
......@@ -83,7 +82,7 @@ try {
/* get the key */
const char *key = p;
const char *key_end = (const char *)memchr(p, '\0', remaining);
const char *key_end = (const char *)std::memchr(p, '\0', remaining);
if (key_end == nullptr)
break;
......
......@@ -20,12 +20,12 @@
#include "DivideString.hxx"
#include "StringStrip.hxx"
#include <string.h>
#include <cstring>
DivideString::DivideString(const char *s, char separator, bool strip) noexcept
:first(nullptr)
{
const char *x = strchr(s, separator);
const char *x = std::strchr(s, separator);
if (x == nullptr)
return;
......
......@@ -20,12 +20,12 @@
#include "MimeType.hxx"
#include "SplitString.hxx"
#include <string.h>
#include <cstring>
std::string
GetMimeTypeBase(const char *s) noexcept
{
const char *semicolon = strchr(s, ';');
const char *semicolon = std::strchr(s, ';');
return semicolon != nullptr
? std::string(s, semicolon)
: std::string(s);
......
......@@ -32,7 +32,7 @@
#include "Compiler.h"
#include <string.h>
#include <cstring>
#ifdef _UNICODE
#include "WStringAPI.hxx"
......@@ -56,42 +56,42 @@ gcc_pure gcc_nonnull_all
static inline char *
StringFind(char *haystack, char needle, size_t size) noexcept
{
return (char *)memchr(haystack, needle, size);
return (char *)std::memchr(haystack, needle, size);
}
gcc_pure gcc_nonnull_all
static inline const char *
StringFind(const char *haystack, char needle, size_t size) noexcept
{
return (const char *)memchr(haystack, needle, size);
return (const char *)std::memchr(haystack, needle, size);
}
gcc_pure gcc_nonnull_all
static inline const char *
StringFind(const char *haystack, char needle) noexcept
{
return strchr(haystack, needle);
return std::strchr(haystack, needle);
}
gcc_pure gcc_nonnull_all
static inline char *
StringFind(char *haystack, char needle) noexcept
{
return strchr(haystack, needle);
return std::strchr(haystack, needle);
}
gcc_pure gcc_nonnull_all
static inline const char *
StringFindLast(const char *haystack, char needle) noexcept
{
return strrchr(haystack, needle);
return std::strrchr(haystack, needle);
}
gcc_pure gcc_nonnull_all
static inline char *
StringFindLast(char *haystack, char needle) noexcept
{
return strrchr(haystack, needle);
return std::strrchr(haystack, needle);
}
gcc_pure gcc_nonnull_all
......
......@@ -30,14 +30,14 @@
#ifndef TEXT_FILE_HXX
#define TEXT_FILE_HXX
#include <string.h>
#include <cstring>
template<typename B>
char *
ReadBufferedLine(B &buffer)
{
auto r = buffer.Read();
char *newline = reinterpret_cast<char*>(memchr(r.data, '\n', r.size));
char *newline = reinterpret_cast<char*>(std::memchr(r.data, '\n', r.size));
if (newline == nullptr)
return nullptr;
......
......@@ -124,7 +124,7 @@ uri_get_path(std::string_view uri) noexcept
const char *
uri_get_suffix(const char *uri) noexcept
{
const char *suffix = strrchr(uri, '.');
const char *suffix = std::strrchr(uri, '.');
if (suffix == nullptr || suffix == uri ||
suffix[-1] == '/' || suffix[-1] == '\\')
return nullptr;
......@@ -144,7 +144,7 @@ uri_get_suffix(const char *uri, UriSuffixBuffer &buffer) noexcept
if (suffix == nullptr)
return nullptr;
const char *q = strchr(suffix, '?');
const char *q = std::strchr(suffix, '?');
if (q != nullptr && size_t(q - suffix) < sizeof(buffer.data)) {
memcpy(buffer.data, suffix, q - suffix);
buffer.data[q - suffix] = 0;
......@@ -157,7 +157,7 @@ uri_get_suffix(const char *uri, UriSuffixBuffer &buffer) noexcept
const char *
uri_get_fragment(const char *uri) noexcept
{
const char *fragment = strchr(uri, '#');
const char *fragment = std::strchr(uri, '#');
if (fragment == nullptr)
return nullptr;
......
......@@ -31,8 +31,7 @@
#include "ASCII.hxx"
#include <cassert>
#include <string.h>
#include <cstring>
static const char *
verify_uri_segment(const char *p) noexcept
......@@ -46,7 +45,7 @@ verify_uri_segment(const char *p) noexcept
if (dots <= 2 && (*p == 0 || *p == '/'))
return nullptr;
const char *q = strchr(p + 1, '/');
const char *q = std::strchr(p + 1, '/');
return q != nullptr ? q : "";
}
......@@ -89,11 +88,11 @@ uri_remove_auth(const char *uri) noexcept
/* unrecognized URI */
return std::string();
const char *slash = strchr(auth, '/');
const char *slash = std::strchr(auth, '/');
if (slash == nullptr)
slash = auth + strlen(auth);
const char *at = (const char *)memchr(auth, '@', slash - auth);
const char *at = (const char *)std::memchr(auth, '@', slash - auth);
if (at == nullptr)
/* no auth info present, do nothing */
return std::string();
......
......@@ -32,7 +32,7 @@
#include "Compiler.h"
#include <wchar.h>
#include <cwchar>
gcc_pure gcc_nonnull_all
static inline size_t
......@@ -52,14 +52,14 @@ gcc_pure gcc_nonnull_all
static inline const wchar_t *
StringFind(const wchar_t *haystack, wchar_t needle, size_t size) noexcept
{
return wmemchr(haystack, needle, size);
return std::wmemchr(haystack, needle, size);
}
gcc_pure gcc_nonnull_all
static inline wchar_t *
StringFind(wchar_t *haystack, wchar_t needle, size_t size) noexcept
{
return wmemchr(haystack, needle, size);
return std::wmemchr(haystack, needle, size);
}
gcc_pure gcc_nonnull_all
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment