use nullptr instead of NULL

This commit is contained in:
john30
2018-05-06 14:54:52 +02:00
parent dc12476bc1
commit 1c17f7c466
41 changed files with 625 additions and 626 deletions
+9 -9
View File
@@ -58,9 +58,9 @@ bool HttpClient::parseUrl(const string& url, string& proto, string& host, uint16
}
port = 80;
if (pos != string::npos) {
char* strEnd = NULL;
char* strEnd = nullptr;
unsigned long value = strtoul(host.c_str()+pos+1, &strEnd, 10);
if (strEnd == NULL || *strEnd != '\0' || value < 1 || value > 65535) {
if (strEnd == nullptr || *strEnd != '\0' || value < 1 || value > 65535) {
return false;
}
port = static_cast<uint16_t>(value);
@@ -182,30 +182,30 @@ bool HttpClient::request(const string& method, const string& uri, const string&
// Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
struct tm t;
pos += strlen("\r\nLast-Modified: ") + 5;
char* strEnd = NULL;
char* strEnd = nullptr;
t.tm_mday = (int)strtol(hdrs + pos, &strEnd, 10);
if (strEnd != hdrs + pos + 2 || t.tm_mday < 1 || t.tm_mday > 31) {
t.tm_mday = -1;
}
t.tm_mon = indexToMonth[((hdrs[pos+4]&0x10)>>1) | (hdrs[pos+5]&0x17)] - 1;
strEnd = NULL;
strEnd = nullptr;
t.tm_year = (int)strtol(hdrs + pos + 7, &strEnd, 10);
if (strEnd != hdrs + pos + 11 || t.tm_year < 1970 || t.tm_year >= 3000) {
t.tm_year = -1;
} else {
t.tm_year -= 1900;
}
strEnd = NULL;
strEnd = nullptr;
t.tm_hour = (int)strtol(hdrs + pos + 12, &strEnd, 10);
if (strEnd != hdrs + pos + 14 || t.tm_hour > 23) {
t.tm_hour = -1;
}
strEnd = NULL;
strEnd = nullptr;
t.tm_min = (int)strtol(hdrs + pos + 15, &strEnd, 10);
if (strEnd != hdrs + pos + 17 || t.tm_min > 59) {
t.tm_min = -1;
}
strEnd = NULL;
strEnd = nullptr;
t.tm_sec = (int)strtol(hdrs + pos + 18, &strEnd, 10);
if (strEnd != hdrs + pos + 20 || t.tm_sec > 59) {
t.tm_sec = -1;
@@ -220,9 +220,9 @@ bool HttpClient::request(const string& method, const string& uri, const string&
disconnect();
return true;
}
char* strEnd = NULL;
char* strEnd = nullptr;
unsigned long length = strtoul(hdrs + pos + strlen("\r\nContent-Length: "), &strEnd, 10);
if (strEnd == NULL || *strEnd != '\r') {
if (strEnd == nullptr || *strEnd != '\r') {
disconnect();
response = "invalid content length ";
return false;
+4 -4
View File
@@ -100,10 +100,10 @@ class HttpClient {
* @param uri the URI string.
* @param body the optional body to send.
* @param response the response body from the server (or the HTTP header on error).
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL.
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or nullptr.
* @return true on success, false on error.
*/
bool get(const string& uri, const string& body, string& response, time_t* time = NULL);
bool get(const string& uri, const string& body, string& response, time_t* time = nullptr);
/**
* Execute a POST request.
@@ -119,10 +119,10 @@ class HttpClient {
* @param uri the URI string.
* @param body the optional body to send.
* @param response the response body from the server (or the HTTP header on error).
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or NULL.
* @param time optional pointer to a @a time_t value for storing the modification time of the file, or nullptr.
* @return true on success, false on error.
*/
bool request(const string& method, const string& uri, const string& body, string& response, time_t* time = NULL);
bool request(const string& method, const string& uri, const string& body, string& response, time_t* time = nullptr);
private:
/**
+9 -9
View File
@@ -39,7 +39,7 @@ static const char *facilityNames[] = {
"update",
"other",
"all",
NULL
nullptr
};
/** the name of each @a LogLevel. */
@@ -49,7 +49,7 @@ static const char* levelNames[] = {
"notice",
"info",
"debug",
NULL
nullptr
};
/** the current log level by log facility. */
@@ -63,7 +63,7 @@ LogFacility parseLogFacility(const char* facility) {
return lf_COUNT;
}
char *input = strdup(facility);
char *opt = reinterpret_cast<char*>(input), *value = NULL;
char *opt = reinterpret_cast<char*>(input), *value = nullptr;
int val = getsubopt(&opt, (char *const *)facilityNames, &value);
if (val < 0 || val >= lf_COUNT || value || *opt) {
free(input);
@@ -75,7 +75,7 @@ LogFacility parseLogFacility(const char* facility) {
int parseLogFacilities(const char* facilities) {
char *input = strdup(facilities);
char *opt = reinterpret_cast<char*>(input), *value = NULL;
char *opt = reinterpret_cast<char*>(input), *value = nullptr;
int newFacilites = 0;
while (*opt) {
int val = getsubopt(&opt, (char *const *)facilityNames, &value);
@@ -98,7 +98,7 @@ LogLevel parseLogLevel(const char* level) {
return ll_COUNT;
}
char *input = strdup(level);
char *opt = reinterpret_cast<char*>(input), *value = NULL;
char *opt = reinterpret_cast<char*>(input), *value = nullptr;
int val = getsubopt(&opt, (char *const *)levelNames, &value);
if (val < 0 || val >= ll_COUNT || value || *opt) {
free(input);
@@ -133,7 +133,7 @@ LogLevel getFacilityLogLevel(LogFacility facility) {
bool setLogFile(const char* filename) {
FILE* newFile = fopen(filename, "a");
if (newFile == NULL) {
if (newFile == nullptr) {
return false;
}
closeLogFile();
@@ -142,11 +142,11 @@ bool setLogFile(const char* filename) {
}
void closeLogFile() {
if (s_logFile != NULL) {
if (s_logFile != nullptr) {
if (s_logFile != stdout) {
fclose(s_logFile);
}
s_logFile = NULL;
s_logFile = nullptr;
}
}
@@ -155,7 +155,7 @@ bool needsLog(const LogFacility facility, const LogLevel level) {
}
void logWrite(const char* facility, const char* level, const char* message, va_list ap) {
if (s_logFile == NULL) {
if (s_logFile == nullptr) {
return;
}
struct timespec ts;
+6 -6
View File
@@ -41,8 +41,8 @@ class Queue {
* Constructor.
*/
Queue() {
pthread_mutex_init(&m_mutex, NULL);
pthread_cond_init(&m_cond, NULL);
pthread_mutex_init(&m_mutex, nullptr);
pthread_cond_init(&m_cond, nullptr);
}
/**
@@ -77,7 +77,7 @@ class Queue {
/**
* Remove the first item from the queue optionally waiting for the queue being non-empty.
* @param timeout the maximum time in seconds to wait for the queue being filled, or 0 for no wait.
* @return the item, or NULL if no item is available within the specified time.
* @return the item, or nullptr if no item is available within the specified time.
*/
T pop(int timeout = 0) {
T item;
@@ -93,7 +93,7 @@ class Queue {
}
}
if (m_queue.empty()) {
item = NULL;
item = nullptr;
} else {
item = m_queue.front();
m_queue.pop_front();
@@ -137,13 +137,13 @@ class Queue {
/**
* Return the first item in the queue without removing it.
* @return the item, or NULL if no item is available.
* @return the item, or nullptr if no item is available.
*/
T peek() {
T item;
pthread_mutex_lock(&m_mutex);
if (m_queue.empty()) {
item = NULL;
item = nullptr;
} else {
item = m_queue.front();
}
+2 -2
View File
@@ -34,7 +34,7 @@ using std::streamsize;
RotateFile::~RotateFile() {
if (m_stream) {
fclose(m_stream);
m_stream = NULL;
m_stream = nullptr;
}
}
@@ -45,7 +45,7 @@ bool RotateFile::setEnabled(bool enabled) {
m_enabled = enabled;
if (m_stream) {
fclose(m_stream);
m_stream = NULL;
m_stream = nullptr;
}
if (enabled) {
m_stream = fopen(m_fileName.c_str(), m_textMode ? "w" : "wb");
+12 -12
View File
@@ -54,14 +54,14 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
struct hostent* he;
he = gethostbyname(server.c_str());
if (he == NULL) {
return NULL;
if (he == nullptr) {
return nullptr;
}
memcpy(&address.sin_addr, he->h_addr_list[0], he->h_length);
} else {
ret = inet_aton(server.c_str(), &address.sin_addr);
if (ret == 0) {
return NULL;
return nullptr;
}
}
@@ -70,7 +70,7 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
int sfd = socket(AF_INET, SOCK_STREAM, 0);
if (sfd < 0) {
return NULL;
return nullptr;
}
#ifndef HAVE_PPOLL
#ifndef HAVE_PSELECT
@@ -79,13 +79,13 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
#endif
if (timeout > 0 && fcntl(sfd, F_SETFL, O_NONBLOCK) < 0) { // set non-blocking
close(sfd);
return NULL;
return nullptr;
}
ret = ::connect(sfd, (struct sockaddr *) &address, sizeof(address));
if (ret != 0) {
if (ret < 0 && (timeout <= 0 || errno != EINPROGRESS)) {
close(sfd);
return NULL;
return nullptr;
}
if (timeout > 0) {
struct timespec tdiff;
@@ -97,7 +97,7 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
memset(fds, 0, sizeof(fds));
fds[0].fd = sfd;
fds[0].events = POLLIN|POLLOUT;
ret = ppoll(fds, nfds, &tdiff, NULL);
ret = ppoll(fds, nfds, &tdiff, nullptr);
if (ret == 1 && fds[0].revents & POLLERR) {
ret = -1;
}
@@ -107,20 +107,20 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port, int ti
FD_ZERO(&writefds);
FD_ZERO(&exceptfds);
FD_SET(sfd, &readfds);
ret = pselect(sfd + 1, &readfds, &writefds, &exceptfds, &tdiff, NULL);
ret = pselect(sfd + 1, &readfds, &writefds, &exceptfds, &tdiff, nullptr);
if (ret >= 1 && FD_ISSET(sfd, &exceptfds)) {
ret = -1;
}
#endif
if (ret == -1 || ret == 0) {
close(sfd);
return NULL;
return nullptr;
}
}
}
if (timeout > 0 && fcntl(sfd, F_SETFL, 0) < 0) { // set blocking again
close(sfd);
return NULL;
return nullptr;
}
TCPSocket* s = new TCPSocket(sfd, &address);
if (timeout > 0) {
@@ -164,7 +164,7 @@ int TCPServer::start() {
TCPSocket* TCPServer::newSocket() {
if (!m_listening) {
return NULL;
return nullptr;
}
socketaddress address;
socklen_t len = sizeof(address);
@@ -173,7 +173,7 @@ TCPSocket* TCPServer::newSocket() {
int sfd = accept(m_lfd, (struct sockaddr*) &address, &len);
if (sfd < 0) {
return NULL;
return nullptr;
}
return new TCPSocket(sfd, &address);
}
+5 -5
View File
@@ -27,7 +27,7 @@ namespace ebusd {
void* Thread::runThread(void* arg) {
reinterpret_cast<Thread*>(arg)->enter();
return NULL;
return nullptr;
}
Thread::~Thread() {
@@ -38,7 +38,7 @@ Thread::~Thread() {
}
bool Thread::start(const char* name) {
int result = pthread_create(&m_threadid, NULL, runThread, this);
int result = pthread_create(&m_threadid, nullptr, runThread, this);
if (result == 0) {
#ifdef HAVE_PTHREAD_SETNAME_NP
#ifndef __MACH__
@@ -55,7 +55,7 @@ bool Thread::join() {
int result = -1;
if (m_started) {
m_stopped = true;
result = pthread_join(m_threadid, NULL);
result = pthread_join(m_threadid, nullptr);
if (result == 0) {
m_started = false;
}
@@ -72,8 +72,8 @@ void Thread::enter() {
WaitThread::WaitThread()
: Thread() {
pthread_mutex_init(&m_mutex, NULL);
pthread_cond_init(&m_cond, NULL);
pthread_mutex_init(&m_mutex, nullptr);
pthread_cond_init(&m_cond, nullptr);
}
WaitThread::~WaitThread() {
+1 -1
View File
@@ -43,7 +43,7 @@ class Thread {
/**
* Thread entry helper for pthread_create.
* @param arg pointer to the @a Thread.
* @return NULL.
* @return nullptr.
*/
static void* runThread(void* arg);