  // This file has been copied from of minit-0.9.1.tar.bz2

  // Some types of the function arguments were changed to prevent warnings about mismatching
  // datatypes

#ifndef EMBEDDED
#include <stdlib.h>
#include <unistd.h>
#include <sys/fcntl.h>
#endif

int openreadclose(char const *fn, char **buf, size_t *len) {
  int fd=open(fn,O_RDONLY);
  if (fd<0) return -1;
  if (!*buf) {
    *len=lseek(fd,0,SEEK_END);
    lseek(fd,0,SEEK_SET);
    *buf=(char*)malloc(*len+1);
    if (!*buf) {
      close(fd);
      return -1;
    }
  }
  *len=read(fd,*buf,*len);
  if (*len != (unsigned long)-1)
    (*buf)[*len]=0;
  return close(fd);
}

