From 05f04e5109a1410b0645d8553fe59c07f5230019 Mon Sep 17 00:00:00 2001 From: Szabolcs Nagy Date: Fri, 7 Feb 2014 19:23:02 +0100 Subject: [PATCH] add ftello regression test --- src/regression/ftello-unflushed-append.c | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/regression/ftello-unflushed-append.c diff --git a/src/regression/ftello-unflushed-append.c b/src/regression/ftello-unflushed-append.c new file mode 100644 index 0000000..5473719 --- /dev/null +++ b/src/regression/ftello-unflushed-append.c @@ -0,0 +1,44 @@ +// commit 3af2edee150484940916eba1984f78c3b965dd05 2014-02-07 +// fix ftello result for append streams with unflushed output +#include +#include +#include +#include +#include +#include +#include "test.h" + +#define ASSERT(c) do { \ + errno = 0; \ + if (!(c)) \ + t_error("%s failed (errno: %s)\n", #c, strerror(errno)); \ +} while(0) + +int main(void) +{ + char tmp[] = "/tmp/testsuite-XXXXXX"; + int fd; + FILE *f; + off_t off; + + ASSERT((fd = mkstemp(tmp)) > 2); + ASSERT(write(fd, "abcd", 4) == 4); + ASSERT(close(fd) == 0); + + ASSERT((fd = open(tmp, O_WRONLY)) > 2); + ASSERT(f = fdopen(fd, "a")); + if (f) { + ASSERT(fwrite("efg", 1, 3, f) == 3); + ASSERT((off = ftello(f)) != -1); + if (off != 7) + t_error("ftello is broken before flush: got %lld, want 7\n", (long long)off); + ASSERT(fflush(f) == 0); + ASSERT((off = ftello(f)) != -1); + if (off != 7) + t_error("ftello is broken after flush: got %lld, want 7\n", (long long)off); + ASSERT(fclose(f) == 0); + } + if (fd > 2) + ASSERT(unlink(tmp) == 0); + return t_status; +} -- 2.20.1