librclone: export the rclone RC as a C library #4891
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
CFLAGS = -g -Wall
|
||||
LDFLAGS = -L. -lrclone -lpthread -ldl
|
||||
|
||||
static: ctest
|
||||
|
||||
shared:
|
||||
go build --buildmode=c-shared -o librclone.so github.com/rclone/rclone/librclone
|
||||
|
||||
ctest: ctest.o librclone.h
|
||||
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS)
|
||||
|
||||
ctest.o: ctest.c librclone.h
|
||||
$(CC) $(CFLAGS) -c $^ $(LDFLAGS)
|
||||
|
||||
build:
|
||||
go build
|
||||
|
||||
librclone.h:
|
||||
go build --buildmode=c-archive -o librclone.a github.com/rclone/rclone/librclone
|
||||
|
||||
clean:
|
||||
rm -f tmp ctest *.o *.a *.h *.gch
|
||||
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
#include "librclone.h"
|
||||
|
||||
// copy file using "operations/copyfile" command
|
||||
void testCopyFile() {
|
||||
struct CRPC_return res = CRPC("operations/copyfile", "{ \"srcFs\": \"/tmp\", \"srcRemote\": \"tmpfile\", \"dstFs\": \"/tmp\", \"dstRemote\": \"tmpfile2\" }");
|
||||
printf("%d\n", res.r1); // status
|
||||
printf("%s\n", res.r0); // output
|
||||
free(res.r0);
|
||||
}
|
||||
|
||||
// noop command
|
||||
void testNoOp() {
|
||||
struct CRPC_return res = CRPC("rc/noop", "{ \"p1\": [1,\"2\",null,4], \"p2\": { \"a\":1, \"b\":2 } }");
|
||||
printf("%d\n", res.r1); // status
|
||||
printf("%s\n", res.r0); // output
|
||||
free(res.r0);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
printf("c main begin\n");
|
||||
Cinit();
|
||||
|
||||
//testNoOp();
|
||||
testCopyFile();
|
||||
|
||||
Cdestroy();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user