storj-uplink: 1.119.15 -> 1.120.4 (#375732)
[NixPkgs.git] / pkgs / by-name / li / libfprint-2-tod1-broadcom / wrapper-lib.c
blobc6909ae55a525eff6655aec710113b1decc4ef6b
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
5 static const char from[] = "/var/lib/fprint/fw";
6 static const char to[] = "@to@";
8 FILE* fopen_wrapper(const char* fn, const char* mode) {
9 size_t fn_len = strlen(fn);
10 size_t from_len = strlen(from);
11 if (fn_len > from_len && memcmp(fn, from, from_len) == 0) {
12 size_t to_len = strlen(to);
13 char* rewritten = calloc(fn_len + (to_len - from_len) + 1, 1);
14 memcpy(rewritten, to, to_len);
15 memcpy(rewritten + to_len, fn + from_len, fn_len - from_len);
17 printf("fopen_wrapper.c: Replacing path '%s' with '%s'\n", fn, rewritten);
18 FILE* result = fopen(rewritten, mode);
19 free(rewritten);
20 return result;
22 return fopen(fn, mode);