rts/c/util.h
// Read a file into a NUL-terminated string; returns NULL on error.
Read a file into a NUL-terminated string; returns NULL on error.
Read a file into a NUL - terminated string ; returns NULL on error .
static void* slurp_file(const char *filename, size_t *size) {
  unsigned char *s;
  FILE *f = fopen(filename, "rb"); 
  if (f == NULL) return NULL;
  fseek(f, 0, SEEK_END);
  size_t src_size = ftell(f);
  fseek(f, 0, SEEK_SET);
  s = (unsigned char*) malloc(src_size + 1);
  if (fread(s, 1, src_size, f) != src_size) {
    free(s);
    s = NULL;
  } else {
    s[src_size] = '\0';
  }
  fclose(f);
  if (size) {
    *size = src_size;
  }
  return s;
}
static void * slurp_file ( const char * filename , size_t * size ) { unsigned char * s ; FILE * f = fopen ( filename , " " ) ; if ( f == NULL ) return NULL ; fseek ( f , 0 , SEEK_END ) ; size_t src_size = ftell ( f ) ; fseek ( f , 0 , SEEK_SET ) ; s = ( unsigned char * ) malloc ( src_size + 1 ) ; if ( fread ( s , 1 , src_size , f ) != src_size ) { free ( s ) ; s = NULL ; } else { s [ src_size ] = ' \0 ' ; } fclose ( f ) ; if ( size ) { * size = src_size ; } return s ; }
Read a file into a NUL-terminated string; returns NULL on error.
Read a file into a NUL - terminated string ; returns NULL on error .
// To avoid Windows messing with linebreaks.