diff options
author | Diego 'Flameeyes' Pettenò <flameeyes@gmail.com> | 2008-05-07 17:49:47 +0200 |
---|---|---|
committer | Diego 'Flameeyes' Pettenò <flameeyes@gmail.com> | 2008-05-07 17:49:47 +0200 |
commit | c3744b6736ce45c1c700b7f026fb0acfb0069a6d (patch) | |
tree | f92efb8a27043f24f2ef5d4a916f23a769634b15 /src/input/librtsp/rtsp.c | |
parent | 4527fd438b39dc312c69839f051e0a2ac0046356 (diff) | |
download | xine-lib-c3744b6736ce45c1c700b7f026fb0acfb0069a6d.tar.gz xine-lib-c3744b6736ce45c1c700b7f026fb0acfb0069a6d.tar.bz2 |
Use asprintf() rather than malloc() + sprintf().
Using asprintf() instead of malloc() + sprintf() reduces the lines of
code in xine-lib (moving the allocation to the C library or asprintf
replacement), makes it safer to access the string and can also improve
performance whenever the value returned by a function was used as
parameter, as before it had to run the function twice in almost every
case (once for strlen(), once for sprintf()).
Diffstat (limited to 'src/input/librtsp/rtsp.c')
-rw-r--r-- | src/input/librtsp/rtsp.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/src/input/librtsp/rtsp.c b/src/input/librtsp/rtsp.c index 530ffc6cf..beb77d8b4 100644 --- a/src/input/librtsp/rtsp.c +++ b/src/input/librtsp/rtsp.c @@ -21,6 +21,10 @@ * *not* RFC 2326 compilant yet. */ +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + #include <unistd.h> #include <stdio.h> #include <assert.h> @@ -173,9 +177,7 @@ static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) { char **payload=s->scheduled; char *buf; - buf = malloc(strlen(type)+strlen(what)+strlen(rtsp_protocol_version)+3); - - sprintf(buf,"%s %s %s",type, what, rtsp_protocol_version); + asprintf(&buf,"%s %s %s",type, what, rtsp_protocol_version); rtsp_put(s,buf); free(buf); if (payload) @@ -200,8 +202,7 @@ static void rtsp_schedule_standard(rtsp_t *s) { if (s->session) { char *buf; - buf = malloc(strlen(s->session)+15); - sprintf(buf, "Session: %s", s->session); + asprintf(&buf, "Session: %s", s->session); rtsp_schedule_field(s, buf); free(buf); } @@ -304,8 +305,7 @@ int rtsp_request_options(rtsp_t *s, const char *what) { buf=strdup(what); } else { - buf = malloc(sizeof(char)*(strlen(s->host)+16)); - sprintf(buf,"rtsp://%s:%i", s->host, s->port); + asprintf(&buf,"rtsp://%s:%i", s->host, s->port); } rtsp_send_request(s,"OPTIONS",buf); free(buf); @@ -321,8 +321,7 @@ int rtsp_request_describe(rtsp_t *s, const char *what) { buf=strdup(what); } else { - buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16)); - sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); + asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); } rtsp_send_request(s,"DESCRIBE",buf); free(buf); @@ -345,8 +344,7 @@ int rtsp_request_setparameter(rtsp_t *s, const char *what) { buf=strdup(what); } else { - buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16)); - sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); + asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); } rtsp_send_request(s,"SET_PARAMETER",buf); free(buf); @@ -362,8 +360,7 @@ int rtsp_request_play(rtsp_t *s, const char *what) { buf=strdup(what); } else { - buf = malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16)); - sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); + asprintf(&buf,"rtsp://%s:%i/%s", s->host, s->port, s->path); } rtsp_send_request(s,"PLAY",buf); free(buf); @@ -412,8 +409,7 @@ int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size) { } /* lets make the server happy */ rtsp_put(s, "RTSP/1.0 451 Parameter Not Understood"); - rest = malloc(sizeof(char)*17); - sprintf(rest,"CSeq: %u", seq); + asprintf(&rest,"CSeq: %u", seq); rtsp_put(s, rest); free(rest); rtsp_put(s, ""); |