commit 6daee62e595d6ef5d878d2a700312672d28f1943
parent 22f18d6a6479e1446fee599e668f53d20c48f264
Author: gearsix <gearsix@tuta.io>
Date: Thu, 10 Oct 2024 10:06:41 +0100
created test.c; lots of fixes.
Diffstat:
6 files changed, 41 insertions(+), 14 deletions(-)
diff --git a/idx.h b/idx.h
@@ -4,7 +4,8 @@
extern "C" {
#endif
-#include "idx_t.h" /* idx_t typedef */
+#include "idx_t.h" /* idx_t */
+#include <stdio.h> /* FILE */
int idxseek(FILE *stream, idx_t offset, int origin);
diff --git a/idx_posix.c b/idx_posix.c
@@ -1,11 +1,12 @@
-#ifdef IDX_POSIX
+#include "idx.h"
-#include <stdio.h>
+#ifdef IDX_POSIX
+#include <stdlib.h> /* strtoull */
int idxseek(FILE *stream, idx_t offset, int origin)
{
- return _fseeko(stream, (off_t)offset, origin);
+ return fseeko(stream, (off_t)offset, origin);
}
idx_t idxtell(FILE *stream)
@@ -20,7 +21,7 @@ idx_t strtoidx(const char *s, char **end, int base)
int idxtostr(idx_t i, char **buf)
{
- return sprintf(buf, "%llu", i);
+ return sprintf(*buf, "%llu", i);
}
#endif
diff --git a/idx_t.h b/idx_t.h
@@ -6,10 +6,10 @@ extern "C" {
/* Systems with POSIX support */
-#ifdef __unix__ || (__APPLE__ && __MACH__)
+#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
#include <unistd.h>
#define IDX_POSIX
- typedef off_t idx_t
+ typedef off_t idx_t;
/* Windows... */
#elif defined(_WIN32)
diff --git a/idx_ukwn.c b/idx_ukwn.c
@@ -1,5 +1,6 @@
-#ifdef IDX_UNKW || IDX_UNKWC99
+#include "idx.h"
+#if defined(IDX_UNKW) || defined(IDX_UNKWC99)
int idxseek(FILE *stream, idx_t offset, int origin)
{
@@ -23,9 +24,9 @@ idx_t strtoidx(const char *s, char **end, int base)
int idxtostr(idx_t i, char **buf)
{
#ifdef IDX_UKWNC99
- return sprintf(buf, "%llu", i);
+ return sprintf(*buf, "%llu", i);
#else
- return sprintf(buf, "%lu", i);
+ return sprintf(*buf, "%lu", i);
#endif
}
diff --git a/idx_win.c b/idx_win.c
@@ -1,7 +1,6 @@
-#ifdef IDX_WIN
-
-#include <stdio.h>
+#include "idx.h"
+#ifdef IDX_WIN
int idxseek(FILE *stream, idx_t offset, int origin)
{
@@ -20,7 +19,7 @@ idx_t strtoidx(const char *s, char **end, int base)
int idxtostr(idx_t i, char **buf)
{
- return sprintf(buf, "%I64", i);
+ return sprintf(*buf, "%I64", i);
}
#endif
diff --git a/test.c b/test.c
@@ -0,0 +1,25 @@
+#include "idx.h"
+
+#include <assert.h>
+
+#define FSIZE 9327112 // around 4.4GB
+
+int main(int argc, char **argv)
+{
+ idx_t pos;
+ FILE *f;
+
+ f = tmpfile();
+ if (!f) return -1;
+
+ for (pos = 0; pos < FSIZE; ++pos)
+ fputc('.', f);
+ assert(pos == FSIZE);
+
+ idxseek(f, FSIZE / 2, SEEK_SET);
+ pos = ftell(f);
+ assert(pos == FSIZE / 2);
+
+ return fclose(f);
+}
+