* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
-/*
- * load file into malloced buffer
- */
-char *load_file(const char *fn) _MUSTCHECK;
-
/*
* logging about specific socket
*/
#include <netdb.h>
#endif
+#include <usual/fileutil.h>
+
/*
* ConnString parsing
*/
{
char *user, *password, *buf, *p;
- buf = load_file(fn);
+ buf = load_file(fn, NULL);
if (buf == NULL) {
/* reset file info */
auth_loaded(NULL);
ConfSection *cur_section = NULL;
char keybuf[MAX_DBNAME*2];
- buf = load_file(fn);
+ buf = load_file(fn, NULL);
if (buf == NULL) {
if (!reload)
exit(1);
sock, db, user, host, port);
}
-
-/*
- * Load a file into malloc()-ed C string.
- */
-
-char *load_file(const char *fn)
-{
- struct stat st;
- char *buf = NULL;
- int res, fd;
-
- res = stat(fn, &st);
- if (res < 0) {
- log_error("%s: %s", fn, strerror(errno));
- goto load_error;
- }
-
- buf = malloc(st.st_size + 1);
- if (!buf) {
- log_error("%s: no mem", fn);
- goto load_error;
- }
-
- if ((fd = open(fn, O_RDONLY)) < 0) {
- log_error("%s: %s", fn, strerror(errno));
- goto load_error;
- }
-
- if ((res = safe_read(fd, buf, st.st_size)) < 0) {
- log_error("%s: %s", fn, strerror(errno));
- goto load_error;
- }
-
- close(fd);
- buf[st.st_size] = 0;
-
- return buf;
-
-load_error:
- if (buf != NULL)
- free(buf);
- return NULL;
-}
-
/*
* PostgreSQL MD5 hashing.
*/