summaryrefslogtreecommitdiff
path: root/libpiano/src/http.c
diff options
context:
space:
mode:
authorLars-Dominik Braun <PromyLOPh@gmail.com>2008-08-08 19:37:31 +0200
committerLars-Dominik Braun <PromyLOPh@gmail.com>2008-08-08 19:37:31 +0200
commitb55cf2b0641d67f9832b14285af741ef0ed9d8bf (patch)
treecf3596f231dd0a27892fc138060062e70aeb1e79 /libpiano/src/http.c
parente1cb484fe66410e45363f29b167fedf19f236ded (diff)
downloadpianobar-b55cf2b0641d67f9832b14285af741ef0ed9d8bf.tar.gz
pianobar-b55cf2b0641d67f9832b14285af741ef0ed9d8bf.tar.bz2
pianobar-b55cf2b0641d67f9832b14285af741ef0ed9d8bf.zip
Several code optimizations
Diffstat (limited to 'libpiano/src/http.c')
-rw-r--r--libpiano/src/http.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/libpiano/src/http.c b/libpiano/src/http.c
index 91941d9..88d299c 100644
--- a/libpiano/src/http.c
+++ b/libpiano/src/http.c
@@ -39,12 +39,13 @@ THE SOFTWARE.
size_t PianoCurlRetToVar (void *ptr, size_t size, size_t nmemb, void *stream) {
char *charPtr = ptr;
char *streamPtr = stream;
+ size_t streamPtrN = strlen (streamPtr);
- if (strlen (streamPtr) + nmemb > PIANO_HTTP_BUFFER_SIZE) {
+ if (streamPtrN + nmemb > PIANO_HTTP_BUFFER_SIZE) {
printf ("buffer overflow...\n");
return 0;
} else {
- memcpy (streamPtr+strlen(streamPtr), charPtr, size*nmemb);
+ memcpy (streamPtr+streamPtrN, charPtr, size*nmemb);
return size*nmemb;
}
}
@@ -78,8 +79,7 @@ PianoReturn_t PianoHttpPost (CURL *ch, const char *url, const char *postData,
if (curl_easy_perform (ch) == CURLE_OK) {
ret = PIANO_RET_OK;
- *retData = calloc (strlen (curlRet) + 1, sizeof (char));
- strcpy (*retData, curlRet);
+ *retData = strdup (curlRet);
} else {
ret = PIANO_RET_NET_ERROR;
*retData = NULL;
@@ -111,8 +111,7 @@ PianoReturn_t PianoHttpGet (CURL *ch, const char *url, char **retData) {
if (curl_easy_perform (ch) == CURLE_OK) {
ret = PIANO_RET_OK;
- *retData = calloc (strlen (curlRet) + 1, sizeof (char));
- strcpy (*retData, curlRet);
+ *retData = strdup (curlRet);
} else {
ret = PIANO_RET_NET_ERROR;
*retData = NULL;