[MPlayer-dev-eng] [PATCH] asprintf undefined
Steven M. Schultz
sms at 2BSD.COM
Mon Dec 8 20:39:40 CET 2003
Hi -
On a linux system the asprintf manpage mentiones that asprintf
is a GNU extension and one of the systems I'm using (a BSD variant)
happens to be unlucky enough to lack asprintf.
I've attached a patch for consideration which uses malloc + strlen
to achieve the same effect as asprintf.
Cheers,
Steven Schultz
-------------- next part --------------
--- cookies.c.dist Mon Dec 8 05:51:00 2003
+++ cookies.c Mon Dec 8 11:35:43 2003
@@ -177,14 +177,18 @@
return list;
- asprintf(&buf, "%s/.mozilla/default", homedir);
+ buf = malloc(strlen(homedir) + sizeof("/.mozilla/default") + 1);
+ sprintf(buf, "%s/.mozilla/default", homedir);
dir = opendir(buf);
free(buf);
if (dir) {
while ((ent = readdir(dir)) != NULL) {
if ((ent->d_name)[0] != '.') {
- asprintf(&buf, "%s/.mozilla/default/%s/cookies.txt",
+ buf = malloc(strlen(getenv("HOME")) +
+ sizeof("/.mozilla/default/") +
+ strlen(ent->d_name) + sizeof("cookies.txt") + 1);
+ sprintf(buf, "%s/.mozilla/default/%s/cookies.txt",
getenv("HOME"), ent->d_name);
list = load_cookies_from(buf, list);
free(buf);
@@ -193,7 +197,8 @@
closedir(dir);
}
- asprintf(&buf, "%s/.netscape/cookies.txt", homedir);
+ buf = malloc(strlen(homedir) + sizeof("/.netscape/cookies.txt") + 1);
+ sprintf(buf, "%s/.netscape/cookies.txt", homedir);
list = load_cookies_from(buf, list);
free(buf);
@@ -250,16 +255,19 @@
}
- asprintf(&buf, "Cookie:");
+ buf = strdup("Cookie:");
for (i = 0; i < found_cookies; i++) {
char *nbuf;
- asprintf(&nbuf, "%s %s=%s;", buf, cookies[i]->name,
+ nbuf = malloc(strlen(buf) + strlen(" ") + strlen(cookies[i]->name) +
+ strlen("=") + strlen(cookies[i]->value) + strlen(";") + 1);
+ sprintf(nbuf, "%s %s=%s;", buf, cookies[i]->name,
cookies[i]->value);
free(buf);
buf = nbuf;
}
+
if (found_cookies)
http_set_field(http_hdr, buf);
else
More information about the MPlayer-dev-eng
mailing list