mirror of https://github.com/libAthena/athena.git
General: Use nullptr where applicable
Uses nullptr instead of NULL or the 0 integer literal where applicable.
This commit is contained in:
parent
d735ed45db
commit
54b1e8f836
|
@ -181,9 +181,9 @@ atUint64 rand64();
|
||||||
std::string join(const std::vector<std::string>& elems, std::string_view delims);
|
std::string join(const std::vector<std::string>& elems, std::string_view delims);
|
||||||
void tolower(std::string& str);
|
void tolower(std::string& str);
|
||||||
void toupper(std::string& str);
|
void toupper(std::string& str);
|
||||||
bool parseBool(std::string_view boolean, bool* valid = NULL);
|
bool parseBool(std::string_view boolean, bool* valid = nullptr);
|
||||||
|
|
||||||
int countChar(std::string_view str, const char chr, int* lastOccur = NULL);
|
int countChar(std::string_view str, char chr, int* lastOccur = nullptr);
|
||||||
|
|
||||||
// trim from start
|
// trim from start
|
||||||
std::string& ltrim(std::string& s);
|
std::string& ltrim(std::string& s);
|
||||||
|
|
|
@ -106,7 +106,7 @@ atUint32 LZType11::compress(const atUint8* src, atUint8** dst, atUint32 srcLengt
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] compressedBytes;
|
delete[] compressedBytes;
|
||||||
compressedBytes = NULL;
|
compressedBytes = nullptr;
|
||||||
|
|
||||||
// Add zeros until the file is a multiple of 4
|
// Add zeros until the file is a multiple of 4
|
||||||
while ((outbuff.position() % 4) != 0)
|
while ((outbuff.position() % 4) != 0)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
namespace athena::io::Compression {
|
namespace athena::io::Compression {
|
||||||
|
|
||||||
atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) {
|
atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) {
|
||||||
z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
z_stream strm = {};
|
||||||
strm.total_in = strm.avail_in = srcLen;
|
strm.total_in = strm.avail_in = srcLen;
|
||||||
strm.total_out = strm.avail_out = dstLen;
|
strm.total_out = strm.avail_out = dstLen;
|
||||||
strm.next_in = (Bytef*)src;
|
strm.next_in = (Bytef*)src;
|
||||||
|
@ -45,7 +45,7 @@ atInt32 decompressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint
|
||||||
}
|
}
|
||||||
|
|
||||||
atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) {
|
atInt32 compressZlib(const atUint8* src, atUint32 srcLen, atUint8* dst, atUint32 dstLen) {
|
||||||
z_stream strm = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
z_stream strm = {};
|
||||||
strm.total_in = strm.avail_in = srcLen;
|
strm.total_in = strm.avail_in = srcLen;
|
||||||
strm.total_out = strm.avail_out = dstLen;
|
strm.total_out = strm.avail_out = dstLen;
|
||||||
strm.next_in = (Bytef*)src;
|
strm.next_in = (Bytef*)src;
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
#include "athena/Dir.hpp"
|
#include "athena/Dir.hpp"
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <climits>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <limits.h>
|
#include <ctime>
|
||||||
#define __STDC_FORMAT_MACROS
|
#define __STDC_FORMAT_MACROS
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
#include "athena/Utility.hpp"
|
#include "athena/Utility.hpp"
|
||||||
|
@ -10,7 +11,6 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
#else
|
||||||
#include <ctime>
|
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ bool Dir::cd(std::string_view path) {
|
||||||
bool Dir::rm(std::string_view path) { return !(remove((m_path + "/" + path.data()).c_str()) < 0); }
|
bool Dir::rm(std::string_view path) { return !(remove((m_path + "/" + path.data()).c_str()) < 0); }
|
||||||
|
|
||||||
bool Dir::touch() {
|
bool Dir::touch() {
|
||||||
srand(time(NULL));
|
std::srand(std::time(nullptr));
|
||||||
atUint64 tmp = utility::rand64();
|
atUint64 tmp = utility::rand64();
|
||||||
std::string tmpFile = fmt::format(fmt("{:016X}.tmp"), tmp);
|
std::string tmpFile = fmt::format(fmt("{:016X}.tmp"), tmp);
|
||||||
bool ret = FileInfo(m_path + "/" + tmpFile).touch();
|
bool ret = FileInfo(m_path + "/" + tmpFile).touch();
|
||||||
|
|
|
@ -104,7 +104,7 @@ bool FileInfo::touch() const {
|
||||||
(void)athena::io::FileWriter(m_path);
|
(void)athena::io::FileWriter(m_path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (utimes(m_path.c_str(), NULL) < 0) {
|
if (utimes(m_path.c_str(), nullptr) < 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
|
@ -114,7 +114,7 @@ bool FileInfo::touch() const {
|
||||||
wchar_t date[80], time[80];
|
wchar_t date[80], time[80];
|
||||||
|
|
||||||
#if !WINDOWS_STORE
|
#if !WINDOWS_STORE
|
||||||
fh = CreateFileA(m_path.c_str(), GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, NULL, CREATE_NEW, 0, NULL);
|
fh = CreateFileA(m_path.c_str(), GENERIC_READ | FILE_WRITE_ATTRIBUTES, 0, nullptr, CREATE_NEW, 0, nullptr);
|
||||||
|
|
||||||
if (fh == INVALID_HANDLE_VALUE)
|
if (fh == INVALID_HANDLE_VALUE)
|
||||||
return false;
|
return false;
|
||||||
|
@ -122,14 +122,14 @@ bool FileInfo::touch() const {
|
||||||
/*
|
/*
|
||||||
* Use GetFileTime() to get the file modification time.
|
* Use GetFileTime() to get the file modification time.
|
||||||
*/
|
*/
|
||||||
if (GetFileTime(fh, NULL, NULL, &modtime) == 0) {
|
if (GetFileTime(fh, nullptr, nullptr, &modtime) == 0) {
|
||||||
CloseHandle(fh);
|
CloseHandle(fh);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileTimeToSystemTime(&modtime, &st);
|
FileTimeToSystemTime(&modtime, &st);
|
||||||
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, date, sizeof date / sizeof date[0]) == 0 ||
|
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, nullptr, date, sizeof date / sizeof date[0]) == 0 ||
|
||||||
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, time, sizeof time / sizeof time[0]) == 0) {
|
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, nullptr, time, sizeof time / sizeof time[0]) == 0) {
|
||||||
CloseHandle(fh);
|
CloseHandle(fh);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -139,13 +139,13 @@ bool FileInfo::touch() const {
|
||||||
* to the current time.
|
* to the current time.
|
||||||
*/
|
*/
|
||||||
GetSystemTime(&st);
|
GetSystemTime(&st);
|
||||||
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, date, sizeof date / sizeof date[0]) == 0 ||
|
if (GetDateFormatW(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, nullptr, date, sizeof date / sizeof date[0]) == 0 ||
|
||||||
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, time, sizeof time / sizeof time[0]) == 0) {
|
GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, nullptr, time, sizeof time / sizeof time[0]) == 0) {
|
||||||
CloseHandle(fh);
|
CloseHandle(fh);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SystemTimeToFileTime(&st, &modtime);
|
SystemTimeToFileTime(&st, &modtime);
|
||||||
if (SetFileTime(fh, NULL, NULL, &modtime) == 0) {
|
if (SetFileTime(fh, nullptr, nullptr, &modtime) == 0) {
|
||||||
CloseHandle(fh);
|
CloseHandle(fh);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,8 +45,8 @@ void IPAddress::resolve(const std::string& address) {
|
||||||
addrinfo hints;
|
addrinfo hints;
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
hints.ai_family = AF_INET;
|
hints.ai_family = AF_INET;
|
||||||
addrinfo* result = NULL;
|
addrinfo* result = nullptr;
|
||||||
if (getaddrinfo(address.c_str(), NULL, &hints, &result) == 0) {
|
if (getaddrinfo(address.c_str(), nullptr, &hints, &result) == 0) {
|
||||||
if (result) {
|
if (result) {
|
||||||
addr = reinterpret_cast<sockaddr_in*>(result->ai_addr)->sin_addr;
|
addr = reinterpret_cast<sockaddr_in*>(result->ai_addr)->sin_addr;
|
||||||
freeaddrinfo(result);
|
freeaddrinfo(result);
|
||||||
|
|
|
@ -100,7 +100,7 @@ int countChar(std::string_view str, const char chr, int* lastOccur) {
|
||||||
|
|
||||||
for (char c : str) {
|
for (char c : str) {
|
||||||
if (c == chr) {
|
if (c == chr) {
|
||||||
if (lastOccur != NULL)
|
if (lastOccur != nullptr)
|
||||||
*lastOccur = index;
|
*lastOccur = index;
|
||||||
|
|
||||||
ret++;
|
ret++;
|
||||||
|
|
Loading…
Reference in New Issue