From db017545796747115b8797f03e662b0f398a7c7b Mon Sep 17 00:00:00 2001 From: San Mehat Date: Wed, 20 May 2009 15:27:14 -0700 Subject: libsysutils: const correctness fixes + remove some debugging Signed-off-by: San Mehat --- libsysutils/src/FrameworkClient.cpp | 5 ++--- libsysutils/src/SocketClient.cpp | 21 +++++++++++---------- libsysutils/src/SocketListener.cpp | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'libsysutils') diff --git a/libsysutils/src/FrameworkClient.cpp b/libsysutils/src/FrameworkClient.cpp index 237bb60f9..16869961d 100644 --- a/libsysutils/src/FrameworkClient.cpp +++ b/libsysutils/src/FrameworkClient.cpp @@ -13,8 +13,7 @@ FrameworkClient::FrameworkClient(int socket) { pthread_mutex_init(&mWriteMutex, NULL); } -int FrameworkClient::sendMsg(char *msg) { - LOGD("FrameworkClient::sendMsg(%s)", msg); +int FrameworkClient::sendMsg(const char *msg) { if (mSocket < 0) { errno = EHOSTUNREACH; return -1; @@ -28,7 +27,7 @@ int FrameworkClient::sendMsg(char *msg) { return 0; } -int FrameworkClient::sendMsg(char *msg, char *data) { +int FrameworkClient::sendMsg(const char *msg, const char *data) { char *buffer = (char *) alloca(strlen(msg) + strlen(data) + 1); if (!buffer) { errno = -ENOMEM; diff --git a/libsysutils/src/SocketClient.cpp b/libsysutils/src/SocketClient.cpp index ab020ca7b..b229627ff 100644 --- a/libsysutils/src/SocketClient.cpp +++ b/libsysutils/src/SocketClient.cpp @@ -14,7 +14,7 @@ SocketClient::SocketClient(int socket) { pthread_mutex_init(&mWriteMutex, NULL); } -int SocketClient::sendMsg(int code, char *msg, bool addErrno) { +int SocketClient::sendMsg(int code, const char *msg, bool addErrno) { char *buf; if (addErrno) { @@ -27,23 +27,24 @@ int SocketClient::sendMsg(int code, char *msg, bool addErrno) { return sendMsg(buf); } -int SocketClient::sendMsg(char *msg) { +int SocketClient::sendMsg(const char *msg) { if (mSocket < 0) { errno = EHOSTUNREACH; return -1; } - char *bp; - + char *tmp; + const char *bp = msg; + if (msg[strlen(msg)] != '\n') { - bp = (char *) alloca(strlen(msg) + 1); - strcpy(bp, msg); - strcat(bp, "\n"); - } else - bp = msg; + tmp = (char *) alloca(strlen(msg) + 1); + strcpy(tmp, msg); + strcat(tmp, "\n"); + bp = tmp; + } int rc = 0; - char *p = bp; + const char *p = bp; int brtw = strlen(bp); pthread_mutex_lock(&mWriteMutex); diff --git a/libsysutils/src/SocketListener.cpp b/libsysutils/src/SocketListener.cpp index acc4a67df..cb7dd808f 100644 --- a/libsysutils/src/SocketListener.cpp +++ b/libsysutils/src/SocketListener.cpp @@ -173,7 +173,7 @@ void SocketListener::runListener() { } } -void SocketListener::sendBroadcast(int code, char *msg, bool addErrno) { +void SocketListener::sendBroadcast(int code, const char *msg, bool addErrno) { pthread_mutex_lock(&mClientsLock); SocketClientCollection::iterator i; @@ -185,7 +185,7 @@ void SocketListener::sendBroadcast(int code, char *msg, bool addErrno) { pthread_mutex_unlock(&mClientsLock); } -void SocketListener::sendBroadcast(char *msg) { +void SocketListener::sendBroadcast(const char *msg) { pthread_mutex_lock(&mClientsLock); SocketClientCollection::iterator i; -- cgit v1.2.3