7 /* load file with some prejudice
9 /* #include <load_file.h>
11 /* void load_file(path, action, context)
13 /* void (*action)(VSTREAM, void *);
16 /* This routine reads a file and reads it again when the
17 /* file changed recently.
21 /* The file to be opened, read-only.
23 /* The function that presumably reads the file.
25 /* Application-specific context for the action routine.
27 /* Fatal errors: out of memory, cannot open file.
31 /* The Secure Mailer license must be distributed with this software.
34 /* IBM T.J. Watson Research
36 /* Yorktown Heights, NY 10598, USA
45 /* Utility library. */
50 #include <load_file.h>
52 /* load_file - load file with some prejudice */
54 void load_file(const char *path
, LOAD_FILE_FN action
, void *context
)
62 * Read the file again if it is hot. This may result in reading a partial
63 * parameter name or missing end marker when a file changes in the middle
66 for (before
= time((time_t *) 0); /* see below */ ; before
= after
) {
67 if ((fp
= vstream_fopen(path
, O_RDONLY
, 0)) == 0)
68 msg_fatal("open %s: %m", path
);
70 if (fstat(vstream_fileno(fp
), &st
) < 0)
71 msg_fatal("fstat %s: %m", path
);
72 if (vstream_ferror(fp
) || vstream_fclose(fp
))
73 msg_fatal("read %s: %m", path
);
74 after
= time((time_t *) 0);
75 if (st
.st_mtime
< before
- 1 || st
.st_mtime
> after
)
78 msg_info("pausing to let %s cool down", path
);