url c malloc

This commit is contained in:
Kelvin Sherlock 2012-04-24 23:55:18 -04:00
parent 39bc3dde14
commit c5253c6ce3
2 changed files with 31 additions and 0 deletions

29
url.c
View File

@ -28,6 +28,35 @@ extern void parse_scheme(const char *cp, unsigned size, URLComponents *c);
*
*/
char *URLComponentGetCMalloc(
const char *url,
URLComponents *components,
int type)
{
URLRange *rangePtr;
URLRange r;
char *tmp;
if (!url || !components) return NULL;
if (type < URLComponentScheme || type > URLComponentPathAndQuery)
return NULL;
rangePtr = &components->scheme;
r = rangePtr[type];
if (!r.length) return NULL;
tmp = (char *)malloc(r.length + 1);
if (!tmp) return NULL;
memcpy(tmp, url + r.location, r.length);
tmp[r.length] = 0;
return tmp;
}
int URLComponentGetC(const char *url, URLComponents *components, int type, char *dest)
{
URLRange *rangePtr;

2
url.h
View File

@ -57,6 +57,8 @@ typedef struct URLComponents {
int ParseURL(const char *url, int length, URLComponents *components);
char *URLComponentGetCMalloc(const char *url, URLComponents *, int);
int URLComponentGet(const char *url, URLComponents *, int, char *);
int URLComponentGetC(const char *url, URLComponents *, int, char *);
//int URLComponentGetGS(const char *url, URLComponents *, int, GSString255Ptr);