replace exit and _exit with std variants

_exit and std::_Exit are identical, expect the latter is standard C++.

Added several functions to the std namespace as a result of headers.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2020-03-26 18:44:09 -07:00
parent cfa4524cb3
commit 3540cf26b1
4 changed files with 20 additions and 27 deletions

View File

@ -66,9 +66,6 @@
#include "archive/ArchivePlugin.hxx" #include "archive/ArchivePlugin.hxx"
#endif #endif
#include <stdio.h>
#include <stdlib.h>
namespace { namespace {
#ifdef _WIN32 #ifdef _WIN32
constexpr auto CONFIG_FILE_LOCATION = Path::FromFS(PATH_LITERAL("mpd\\mpd.conf")); constexpr auto CONFIG_FILE_LOCATION = Path::FromFS(PATH_LITERAL("mpd\\mpd.conf"));
@ -256,7 +253,7 @@ static void version()
#endif #endif
"\n"); "\n");
exit(EXIT_SUCCESS); std::exit(EXIT_SUCCESS);
} }
static void PrintOption(const OptionDef &opt) static void PrintOption(const OptionDef &opt)
@ -286,7 +283,7 @@ static void help()
if(i.HasDescription()) // hide hidden options from help print if(i.HasDescription()) // hide hidden options from help print
PrintOption(i); PrintOption(i);
exit(EXIT_SUCCESS); std::exit(EXIT_SUCCESS);
} }
class ConfigLoader class ConfigLoader

View File

@ -22,11 +22,9 @@
#include "LogV.hxx" #include "LogV.hxx"
#include <cstdarg> #include <cstdarg>
#include <cstdio>
#include <unistd.h> #include <cstdlib>
#include <stdio.h> #include <cstring>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
@ -40,7 +38,7 @@ static constexpr Domain fatal_error_domain("fatal_error");
static void static void
Abort() Abort()
{ {
_exit(EXIT_FAILURE); std::_Exit(EXIT_FAILURE);
} }
void void
@ -82,7 +80,7 @@ FatalSystemError(const char *msg)
#ifdef _WIN32 #ifdef _WIN32
FatalSystemError(msg, GetLastError()); FatalSystemError(msg, GetLastError());
#else #else
const char *system_error = strerror(errno); auto system_error = std::strerror(errno);
FormatError(fatal_error_domain, "%s: %s", msg, system_error); FormatError(fatal_error_domain, "%s: %s", msg, system_error);
Abort(); Abort();
#endif #endif
@ -94,7 +92,7 @@ FormatFatalSystemError(const char *fmt, ...)
char buffer[1024]; char buffer[1024];
std::va_list ap; std::va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
vsnprintf(buffer, sizeof(buffer), fmt, ap); std::vsnprintf(buffer, sizeof(buffer), fmt, ap);
va_end(ap); va_end(ap);
FatalSystemError(buffer); FatalSystemError(buffer);

View File

@ -27,8 +27,6 @@
#include "PidFile.hxx" #include "PidFile.hxx"
#endif #endif
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#ifndef _WIN32 #ifndef _WIN32
@ -81,7 +79,7 @@ daemonize_kill()
if (kill(pid, SIGTERM) < 0) if (kill(pid, SIGTERM) < 0)
throw FormatErrno("unable to kill process %i", int(pid)); throw FormatErrno("unable to kill process %i", int(pid));
exit(EXIT_SUCCESS); std::exit(EXIT_SUCCESS);
} }
void void
@ -180,7 +178,7 @@ daemonize_begin(bool detach)
if (nbytes == (ssize_t)sizeof(result)) { if (nbytes == (ssize_t)sizeof(result)) {
/* the child process was successful */ /* the child process was successful */
pidfile2.Write(pid); pidfile2.Write(pid);
exit(EXIT_SUCCESS); std::exit(EXIT_SUCCESS);
} }
/* something bad happened in the child process */ /* something bad happened in the child process */
@ -196,7 +194,7 @@ daemonize_begin(bool detach)
throw FormatErrno("MPD died from signal %d%s", WTERMSIG(status), throw FormatErrno("MPD died from signal %d%s", WTERMSIG(status),
WCOREDUMP(status) ? " (core dumped)" : ""); WCOREDUMP(status) ? " (core dumped)" : "");
exit(WEXITSTATUS(status)); std::exit(WEXITSTATUS(status));
} }
void void

View File

@ -21,8 +21,8 @@
#include "Alloc.hxx" #include "Alloc.hxx"
#include "ConcatString.hxx" #include "ConcatString.hxx"
#include <stdlib.h> #include <cstring>
#include <string.h>
#include <unistd.h> #include <unistd.h>
[[noreturn]] [[noreturn]]
@ -30,13 +30,13 @@ static void
oom() oom()
{ {
(void)write(STDERR_FILENO, "Out of memory\n", 14); (void)write(STDERR_FILENO, "Out of memory\n", 14);
_exit(1); std::_Exit(1);
} }
void * void *
xalloc(size_t size) xalloc(size_t size)
{ {
void *p = malloc(size); auto p = std::malloc(size);
if (gcc_unlikely(p == nullptr)) if (gcc_unlikely(p == nullptr))
oom(); oom();
@ -46,8 +46,8 @@ xalloc(size_t size)
void * void *
xmemdup(const void *s, size_t size) xmemdup(const void *s, size_t size)
{ {
void *p = xalloc(size); auto p = xalloc(size);
memcpy(p, s, size); std::memcpy(p, s, size);
return p; return p;
} }
@ -69,8 +69,8 @@ xstrndup(const char *s, size_t n)
if (gcc_unlikely(p == nullptr)) if (gcc_unlikely(p == nullptr))
oom(); oom();
#else #else
char *p = (char *)xalloc(n + 1); auto p = (char *)xalloc(n + 1);
memcpy(p, s, n); std::memcpy(p, s, n);
p[n] = 0; p[n] = 0;
#endif #endif
@ -87,7 +87,7 @@ t_xstrcatdup(Args&&... args)
size_t lengths[n]; size_t lengths[n];
const size_t total = FillLengths(lengths, args...); const size_t total = FillLengths(lengths, args...);
char *p = (char *)xalloc(total + 1); auto p = (char *)xalloc(total + 1);
*StringCat(p, lengths, args...) = 0; *StringCat(p, lengths, args...) = 0;
return p; return p;
} }