size_t read_from_url(const char *url, char *buf, size_t sz)
{
char *cmd = malloc(strlen(url) + 13);
FILE *f;
size_t off = 0;
sprintf(cmd, "wget -O - '%s'", url);
f = popen(cmd, "r");
free(cmd);
while (sz) {
size_t rd = fread(buf + off, 1, sz, f);
if (rd == 0)
break;
off += rd;
sz -= rd;
}
pclose(f);
return off;
}