Shows how to download a file using an Ecore_Con_Url object. See the complete example description at Ecore_Con_Url - downloading a file
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <Ecore.h>
#include <Ecore_Con.h>
#ifndef O_BINARY
# define O_BINARY 0
#endif
struct _request
{
long size;
};
{
float percent;
{
req->size = url_progress->
down.
now;
printf("Total of download complete: %0.1f (%0.0f)%%\n",
}
}
{
printf("\n");
printf(
"download completed with status code: %d\n", url_complete->
status);
printf("Total size of downloaded file: %ld bytes\n", req->size);
printf("Total size of downloaded file: %d bytes "
"(from received_bytes_get)\n", nbytes);
}
int
main(int argc, const char *argv[])
{
struct _request *req;
int fd;
const char *filename = "downloadedfile.dat";
if (argc < 2)
{
printf("need one parameter: <url>\n");
return -1;
}
fd = open(filename, O_CREAT | O_BINARY | O_WRONLY | O_TRUNC, 0644);
if (fd == -1)
{
printf("error: could not open file for writing: \"%s\"\n",
filename);
return -1;
}
if (!ec_url)
{
printf("error when creating ecore con url object.\n");
goto end;
}
req = malloc(sizeof(*req));
req->size = 0;
{
printf("could not realize request.\n");
goto free_ec_url;
}
free_ec_url:
free(req);
end:
close(fd);
return 0;
}