Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

librclone/ctest: add Windows support and fix memory management

BizaNatorffdd043b957a
diff --git a/librclone/ctest/Makefile b/librclone/ctest/Makefile
index 2de219101..c4e4d11a5 100644
--- a/librclone/ctest/Makefile
+++ b/librclone/ctest/Makefile
@@ -1,17 +1,26 @@
CFLAGS = -g -Wall
+
+ifeq ($(OS),Windows_NT)
+EXE = .exe
+LIB = librclone.lib
+LDFLAGS = -L. -lrclone -lwinmm -lws2_32 -lole32
+else
+EXE =
+LIB = librclone.a
LDFLAGS = -L. -lrclone -lpthread -ldl
+endif
-ctest: ctest.o librclone.a
+ctest$(EXE): ctest.o $(LIB)
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
ctest.o: ctest.c librclone.h
$(CC) $(CFLAGS) -c $^ $(LDFLAGS)
-librclone.a librclone.h:
- go build --buildmode=c-archive -o librclone.a github.com/rclone/rclone/librclone
+$(LIB) librclone.h:
+ go build --buildmode=c-archive -o $(LIB) github.com/rclone/rclone/librclone
-test: ctest
- ./ctest
+test: ctest$(EXE)
+ ./ctest$(EXE)
clean:
- rm -f tmp ctest *.o *.a *.h *.gch
+ rm -f tmp ctest ctest.exe *.o *.a *.lib *.h *.gch
diff --git a/librclone/ctest/ctest.c b/librclone/ctest/ctest.c
index 64b1bb1e8..145d34dd5 100644
--- a/librclone/ctest/ctest.c
+++ b/librclone/ctest/ctest.c
@@ -4,14 +4,13 @@ This is a very simple test/demo program for librclone's C interface
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <dlfcn.h>
#include "librclone.h"
void testRPC(char *method, char *in) {
struct RcloneRPCResult out = RcloneRPC(method, in);
printf("status: %d\n", out.Status);
printf("output: %s\n", out.Output);
- free(out.Output);
+ RcloneFreeString(out.Output);
}
// noop command
@@ -44,7 +43,7 @@ void testNoOp() {
fprintf(stderr, "Wrong status: want: %d: got: %d\n", 200, out.Status);
exit(EXIT_FAILURE);
}
- free(out.Output);
+ RcloneFreeString(out.Output);
}
// error command
@@ -83,7 +82,7 @@ void testError() {
fprintf(stderr, "Wrong status: want: %d: got: %d\n", 500, out.Status);
exit(EXIT_FAILURE);
}
- free(out.Output);
+ RcloneFreeString(out.Output);
}
// copy file using "operations/copyfile" command