Commit f8cbba18 authored by Max Kellermann's avatar Max Kellermann

util/Alloc: remove unused library

parent 635ec3ce
......@@ -33,7 +33,6 @@
#include "storage/FileInfo.hxx"
#include "input/InputStream.hxx"
#include "input/Error.hxx"
#include "util/Alloc.hxx"
#include "util/StringCompare.hxx"
#include "util/UriExtract.hxx"
#include "Log.hxx"
......
/*
* Copyright 2003-2021 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include "Alloc.hxx"
#include "ConcatString.hxx"
#include <cstring>
#include <unistd.h>
[[noreturn]]
static void
oom()
{
(void)write(STDERR_FILENO, "Out of memory\n", 14);
std::_Exit(1);
}
void *
xalloc(size_t size)
{
auto p = std::malloc(size);
if (gcc_unlikely(p == nullptr))
oom();
return p;
}
void *
xmemdup(const void *s, size_t size)
{
auto p = xalloc(size);
std::memcpy(p, s, size);
return p;
}
char *
xstrdup(const char *s)
{
char *p = strdup(s);
if (gcc_unlikely(p == nullptr))
oom();
return p;
}
char *
xstrndup(const char *s, size_t n)
{
#ifdef HAVE_STRNDUP
char *p = strndup(s, n);
if (gcc_unlikely(p == nullptr))
oom();
#else
auto p = (char *)xalloc(n + 1);
std::memcpy(p, s, n);
p[n] = 0;
#endif
return p;
}
template<typename... Args>
gcc_malloc gcc_nonnull_all
static inline char *
t_xstrcatdup(Args&&... args)
{
constexpr size_t n = sizeof...(args);
size_t lengths[n];
const size_t total = FillLengths(lengths, args...);
auto p = (char *)xalloc(total + 1);
*StringCat(p, lengths, args...) = 0;
return p;
}
char *
xstrcatdup(const char *a, const char *b)
{
return t_xstrcatdup(a, b);
}
char *
xstrcatdup(const char *a, const char *b, const char *c)
{
return t_xstrcatdup(a, b, c);
}
char *
xstrcatdup(const char *a, const char *b, const char *c, const char *d)
{
return t_xstrcatdup(a, b, c, d);
}
/*
* Copyright 2003-2021 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_ALLOC_HXX
#define MPD_ALLOC_HXX
#include "Compiler.h"
#include <cstddef>
/**
* Allocate memory. Use free() to free it.
*
* This function never fails; in out-of-memory situations, it aborts
* the process.
*/
gcc_malloc gcc_returns_nonnull
void *
xalloc(size_t size);
/**
* Duplicate memory. Use free() to free it.
*
* This function never fails; in out-of-memory situations, it aborts
* the process.
*/
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
void *
xmemdup(const void *s, size_t size);
/**
* Duplicate a string. Use free() to free it.
*
* This function never fails; in out-of-memory situations, it aborts
* the process.
*/
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
char *
xstrdup(const char *s);
/**
* Duplicate a string. Use free() to free it.
*
* This function never fails; in out-of-memory situations, it aborts
* the process.
*/
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
char *
xstrndup(const char *s, size_t n);
/**
* Concatenate two strings, returning a new allocation. Use free() to
* free it.
*
* This function never fails; in out-of-memory situations, it aborts
* the process.
*/
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
char *
xstrcatdup(const char *a, const char *b);
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
char *
xstrcatdup(const char *a, const char *b, const char *c);
gcc_malloc gcc_returns_nonnull gcc_nonnull_all
char *
xstrcatdup(const char *a, const char *b, const char *c, const char *d);
#endif
/*
* Copyright (C) 2014-2017 Max Kellermann <max.kellermann@gmail.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CONCAT_STRING_HXX
#define CONCAT_STRING_HXX
#include <algorithm>
#include <string.h>
template<typename... Args>
size_t
FillLengths(size_t *lengths, const char *a, Args&&... args)
{
return FillLengths(lengths, a) + FillLengths(lengths + 1, args...);
}
template<>
size_t
FillLengths(size_t *lengths, const char *a)
{
return *lengths = strlen(a);
}
template<typename... Args>
char *
StringCat(char *p, const size_t *lengths, const char *a, Args&&... args)
{
return StringCat(StringCat(p, lengths, a),
lengths + 1, args...);
}
template<>
char *
StringCat(char *p, const size_t *lengths, const char *a)
{
return std::copy_n(a, *lengths, p);
}
#endif
util = static_library(
'util',
'Exception.cxx',
'Alloc.cxx',
'UTF8.cxx',
'HexFormat.cxx',
'MimeType.cxx',
......
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