mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
add support for memory backed local-copy of advio files
This commit is contained in:
parent
e7ba883b60
commit
93c620eedf
2 changed files with 14 additions and 5 deletions
|
@ -21,6 +21,9 @@ struct advio {
|
|||
FILE *file;
|
||||
|
||||
const char *url;
|
||||
/* For use with ADVIO_MODE_MEM */
|
||||
char *buf;
|
||||
size_t size;
|
||||
|
||||
};
|
||||
|
||||
|
|
16
lib/advio.c
16
lib/advio.c
|
@ -38,7 +38,11 @@ AFILE *afopen(const char *uri, const char *mode, int flags)
|
|||
|
||||
AFILE *af = alloc(sizeof(AFILE));
|
||||
|
||||
af->file = tmpfile();
|
||||
if (flags & ADVIO_MEM)
|
||||
af->file = open_memstream(&af->buf, &af->size);
|
||||
else
|
||||
af->file = tmpfile();
|
||||
|
||||
if (!af->file)
|
||||
goto out2;
|
||||
|
||||
|
@ -113,10 +117,6 @@ int afflush(AFILE *af)
|
|||
{
|
||||
int ret;
|
||||
|
||||
ret = fflush(af->file);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Only upload file if it was changed */
|
||||
if (af->flags & ADVIO_DIRTY) {
|
||||
CURLcode res;
|
||||
|
@ -125,6 +125,12 @@ int afflush(AFILE *af)
|
|||
/* Remember old stream pointer */
|
||||
pos = ftell(af->file);
|
||||
fseek(af->file, 0, SEEK_SET);
|
||||
/* Flushing a memory backed stream is sensless */
|
||||
if (!(af->flags & ADVIO_MEM)) {
|
||||
ret = fflush(af->file);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
curl_easy_setopt(af->curl, CURLOPT_UPLOAD, 1L);
|
||||
curl_easy_setopt(af->curl, CURLOPT_READDATA, af->file);
|
||||
|
|
Loading…
Add table
Reference in a new issue