// this and can specify len_out as NULL.
PUBLIC_CONST JH_SLURP_NO_STAT 1
PUBLIC_CONST JH_SLURP_REALLOC 2 /* realloc result block if it saves RAM */
// this and can specify len_out as NULL.
PUBLIC_CONST JH_SLURP_NO_STAT 1
PUBLIC_CONST JH_SLURP_REALLOC 2 /* realloc result block if it saves RAM */
-PUBLIC_FN char *slurp_fd(int fd, size_t *len_out, int flags) {
+PUBLIC_CONST JH_SLURP_8BYTE_PAD 4 /* pad buffer with eight nullbytes, not one */
+PUBLIC_FN void *slurp_fd(int fd, size_t *len_out, int flags) {
// If we can determine the exact size, we don't have to guess. So try
// to determine the exact size.
if (!(flags&JH_SLURP_NO_STAT)) {
// If we can determine the exact size, we don't have to guess. So try
// to determine the exact size.
if (!(flags&JH_SLURP_NO_STAT)) {
if (buf == NULL) return NULL;
int last_res;
ssize_t read_res = read_nointr(fd, buf+done, size_guess-done, &last_res);
if (buf == NULL) return NULL;
int last_res;
ssize_t read_res = read_nointr(fd, buf+done, size_guess-done, &last_res);
if (done != size_guess && (flags&JH_SLURP_REALLOC)) {
// Well, it'd be weird if shrinking could fail... but meh, I can't find
// an explicit statement about this being disallowed, so try staying on
// the safe side.
if (done != size_guess && (flags&JH_SLURP_REALLOC)) {
// Well, it'd be weird if shrinking could fail... but meh, I can't find
// an explicit statement about this being disallowed, so try staying on
// the safe side.
int fd = open(path, O_RDONLY|O_CLOEXEC);
if (fd == -1) return NULL;
char *res = slurp_fd(fd, len_out, flags);
int fd = open(path, O_RDONLY|O_CLOEXEC);
if (fd == -1) return NULL;
char *res = slurp_fd(fd, len_out, flags);
-PUBLIC_FN int write_file(char *path, char *buf, ssize_t len, int open_flags) {
+PUBLIC_FN int write_file(char *path, void *buf, ssize_t len, int open_flags) {
if (fd == -1) return 1;
ssize_t write_res = write_nointr(fd, buf, len, NULL);
int write_errno = errno;
if (fd == -1) return 1;
ssize_t write_res = write_nointr(fd, buf, len, NULL);
int write_errno = errno;