Skip to content

Commit e37118f

Browse files
authored
Merge pull request KageKirin#3 from KageKirin/b-openfile-cb
added custom callback for fileopen()
2 parents b917bb3 + 58ffe3d commit e37118f

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

cpp3.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ ReturnCode fpp_openfile(struct Global *global, char *filename)
3535
FILE *fp;
3636
ReturnCode ret;
3737

38-
if ((fp = fopen(filename, "r")) == NULL)
38+
if (global->openfile)
39+
fp = global->openfile(filename, "r", global->userdata);
40+
else
41+
fp = fopen(filename, "r");
42+
43+
if (fp == NULL)
3944
ret=FPP_OPEN_ERROR;
4045
else
4146
ret=fpp_addfile(global, fp, filename);
@@ -268,6 +273,9 @@ int fpp_dooptions(struct Global *global, struct fppTag *tags)
268273
case FPPTAG_ALLOW_INCLUDE_LOCAL:
269274
global->allowincludelocal=(tags->data?1:0);
270275
break;
276+
case FPPTAG_FILEOPENFUNC:
277+
global->openfile = (FILE* (*)(char *,char *))tags->data;
278+
break;
271279
default:
272280
fpp_cwarn(global, WARN_INTERNAL_ERROR, NULL);
273281
break;

cppadd.h

+2
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ struct Global {
253253
char webmode; /* WWW process mode */
254254

255255
char allowincludelocal;
256+
257+
FILE* (*openfile)(char *,char *, void *);
256258
};
257259

258260
typedef enum {

fpp.h

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ struct fppTag {
165165
/* Allow include "X" (rather than <X>) to search local files, default is FPP_TRUE */
166166
#define FPPTAG_ALLOW_INCLUDE_LOCAL 35
167167

168+
/* Fileopen function. If set, this is called when FPP tries to open a file: */
169+
#define FPPTAG_FILEOPENFUNC 36 /* data is function pointer to a
170+
"FILE* (*)(char * filename, char * mode, void * userdata)", default is NULL */
171+
168172
int fppPreProcess(struct fppTag *);
169173

170174
#ifdef __cplusplus

0 commit comments

Comments
 (0)