mirror of
https://github.com/ksherlock/gopher.git
synced 2024-12-30 17:30:48 +00:00
url c malloc
This commit is contained in:
parent
39bc3dde14
commit
c5253c6ce3
29
url.c
29
url.c
@ -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
2
url.h
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user