removed strclone function (I have no idea why I added it in the first place)

This commit is contained in:
overflowerror 2021-05-05 23:03:57 +02:00
parent b3689b1c03
commit 181359bd81
6 changed files with 22 additions and 28 deletions

View file

@ -166,9 +166,9 @@ struct config* config_parse(FILE* file) {
char* host;
if (strcmp(currentToken, "*") == 0)
host = strclone("0.0.0.0");
host = strdup("0.0.0.0");
else
host = strclone(currentToken);
host = strdup(currentToken);
if (host == NULL) {
error("config: error cloning host string");
@ -177,7 +177,7 @@ struct config* config_parse(FILE* file) {
}
replaceOrAdd(toFree, &toFreeLength, NULL, host);
char* port = strclone(seperator + 1);
char* port = strdup(seperator + 1);
if (port == NULL) {
error("config: error cloning port string");
freeEverything(toFree, toFreeLength);
@ -397,7 +397,7 @@ struct config* config_parse(FILE* file) {
replaceOrAdd(toFree, &toFreeLength, currentSite->hostnames, tmpArray);
currentSite->hostnames = tmpArray;
tmp = strclone(currentToken);
tmp = strdup(currentToken);
if (tmp == NULL) {
error("config: error cloning hostname string");
freeEverything(toFree, toFreeLength);
@ -431,7 +431,7 @@ struct config* config_parse(FILE* file) {
state = SITE_CONTENT;
break;
case HANDLER_VALUE:
currentHandler->dir = strclone(currentToken);
currentHandler->dir = strdup(currentToken);
if (currentHandler->dir == NULL) {
error("config: error cloning handle directory string");
freeEverything(toFree, toFreeLength);
@ -509,7 +509,7 @@ struct config* config_parse(FILE* file) {
replaceOrAdd(toFree, &toFreeLength, settings->indexfiles.files, tmpArray);
settings->indexfiles.files = tmpArray;
tmp = strclone(currentToken);
tmp = strdup(currentToken);
if (tmp == NULL) {
error("config: error cloning hostname string");
freeEverything(toFree, toFreeLength);
@ -554,7 +554,7 @@ struct config* config_parse(FILE* file) {
state = LOGGING_ACCESS_FILE_VALUE;
break;
case LOGGING_ACCESS_FILE_VALUE:
config->logging.accessLogfile = strclone(currentToken);
config->logging.accessLogfile = strdup(currentToken);
if (config->logging.accessLogfile == NULL) {
error("config: error cloning access log file string");
freeEverything(toFree, toFreeLength);
@ -572,7 +572,7 @@ struct config* config_parse(FILE* file) {
state = LOGGING_SERVER_FILE_VALUE;
break;
case LOGGING_SERVER_FILE_VALUE:
config->logging.serverLogfile = strclone(currentToken);
config->logging.serverLogfile = strdup(currentToken);
if (config->logging.serverLogfile == NULL) {
error("config: error cloning server log file string");
freeEverything(toFree, toFreeLength);

View file

@ -46,12 +46,12 @@ int headers_remove(struct headers* headers, const char* key) {
}
int headers_mod(struct headers* headers, const char* _key, const char* _value) {
char* tmp = strclone(_key);
char* tmp = strdup(_key);
if (tmp == NULL) {
return HEADERS_ALLOC_ERROR;
}
char* key = tmp;
tmp = strclone(_value);
tmp = strdup(_value);
if (tmp == NULL) {
return HEADERS_ALLOC_ERROR;
}

View file

@ -683,14 +683,21 @@ void* listenThread(void* _bind) {
gethostbyaddr_r(&client, sizeof(client), family, &entry, &(buffer[0]), LOCAL_BUFFER_SIZE, &result, &h_errno);
if (result == NULL) {
peer.name = strclone("");
peer.name = strdup("");
} else {
peer.name = strclone(entry.h_name);
peer.name = strdup(entry.h_name);
if (peer.name == NULL) {
error("networking: Couldn't strclone hostname: %s", strerror(errno));
peer.name = strclone("");
error("networking: Couldn't strdup hostname: %s", strerror(errno));
peer.name = strdup("");
}
}
if (peer.name == NULL) {
close(tmp);
free(connection);
error("networking: bad: strdup on empty string: %s", strerror(errno));
continue;
}
snprintf(&(peer.portStr[0]), 5 + 1, "%d", peer.port);

View file

@ -53,10 +53,7 @@ void showError() {
void testUtil() {
const char* original = "Hello World";
char* clone = strclone(original);
checkNull(clone, "clone: null check");
checkString(clone, original, "clone: value check");
char* clone = strdup(original);
strremove(clone, 4, 1);
checkString(clone, "Hell World", "remove: middle");

View file

@ -180,14 +180,6 @@ void* fileCopyThread(void* data) {
return NULL;
}
char* strclone(const char* string) {
char* result = malloc(strlen(string) + 1);
if (result == NULL)
return NULL;
strcpy(result, string);
return result;
}
int strlenOfNumber(long long number) {
int result = 1;

View file

@ -18,8 +18,6 @@ struct fileCopy {
int startCopyThread(int from, int to, bool closeWriteFd, pthread_t* thread);
void* fileCopyThread(void* data);
char* strclone(const char* string);
int strlenOfNumber(long long number);
char* getTimestamp();