1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

added flags parameter to afopen()

This commit is contained in:
Steffen Vogel 2017-02-12 14:39:55 -03:00
parent 88a21ade2e
commit e7ba883b60
3 changed files with 16 additions and 10 deletions

View file

@ -9,18 +9,24 @@
#include <curl/curl.h>
enum advio_flags {
ADVIO_MEM = (1 << 0), /**< Instead of a real file, a memory backed stdio stream is used. */
ADVIO_DIRTY = (1 << 1) /**< The file contents have been modified. We need to upload. */
};
struct advio {
int flags;
CURL *curl;
FILE *file;
const char *url;
bool dirty; /**< The file contents have been modified. We need to upload */
};
typedef struct advio AFILE;
AFILE *afopen(const char *url, const char *mode);
AFILE *afopen(const char *url, const char *mode, int flags);
int afclose(AFILE *file);

View file

@ -32,7 +32,7 @@
#include "config.h"
#include "advio.h"
AFILE *afopen(const char *url, const char *mode)
AFILE *afopen(const char *uri, const char *mode, int flags)
{
CURLcode res;
@ -80,8 +80,8 @@ AFILE *afopen(const char *url, const char *mode)
}
af->url = strdup(url);
af->dirty = false;
af->flags = flags & ~ADVIO_DIRTY;
return af;
out0: curl_easy_cleanup(af->curl);
@ -118,7 +118,7 @@ int afflush(AFILE *af)
return ret;
/* Only upload file if it was changed */
if (af->dirty) {
if (af->flags & ADVIO_DIRTY) {
CURLcode res;
long pos;
@ -137,7 +137,7 @@ int afflush(AFILE *af)
if (res != CURLE_OK)
return -1;
af->dirty = false;
af->flags &= ADVIO_DIRTY;
}
return 0;
@ -155,7 +155,7 @@ size_t afwrite(const void *restrict ptr, size_t size, size_t nitems, AFILE *rest
ret = fwrite(ptr, size, nitems, stream->file);
if (ret > 0)
stream->dirty = true;
af->flags |= ADVIO_DIRTY;
return ret;
}

View file

@ -16,7 +16,7 @@ Test(advio, download)
const char *url = "http://www.textfiles.com/100/angela.art";
af = afopen(url, "r");
af = afopen(url, "r", 0);
cr_assert(af, "Failed to download file");
cr_log_info("Opened file %s", url);
@ -46,7 +46,7 @@ Test(advio, upload)
len1 = read_random(rnd, sizeof(rnd));
/* Open file for writing */
af = afopen(uri, "w+");
af = afopen(uri, "w+", 0);
cr_assert(af, "Failed to download file");
len2 = afwrite(rnd, 1, len1, af);
@ -56,7 +56,7 @@ Test(advio, upload)
cr_assert_eq(ret, 0, "Failed to close/upload file");
/* Open for reading and comparison */
af = afopen(uri, "r");
af = afopen(uri, "r", 0);
cr_assert(af, "Failed to download file");
len2 = afread(buffer, 1, len1, af);