+/*
+ called when esp wants to read a file to support include() calls
+*/
+static int http_readFile(EspHandle handle, char **buf, int *len, char *path)
+{
+ int fd = -1;
+ struct stat st;
+ *buf = NULL;
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1 || fstat(fd, &st) != 0 || !S_ISREG(st.st_mode)) goto failed;
+
+ *buf = talloc_size(handle, st.st_size+1);
+ if (*buf == NULL) goto failed;
+
+ if (read(fd, *buf, st.st_size) != st.st_size) goto failed;
+
+ (*buf)[st.st_size] = 0;
+
+ close(fd);
+ *len = st.st_size;
+ return 0;
+
+failed:
+ if (fd != -1) close(fd);
+ talloc_free(*buf);
+ *buf = NULL;
+ return -1;
+}
+