engine/source/scriptlib/ImportCache.c
/**
 * Reads a script file into an allocated buffer.  Be sure to call free() on the
 * returned buffer when you are done with it!
 *
 * Returns the buffer on success, NULL on failure.
 */
Reads a script file into an allocated buffer.  Be sure to call free() on the
returned buffer when you are done with it!

Returns the buffer on success, NULL on failure.
Reads a script file into an allocated buffer . Be sure to call free () on the returned buffer when you are done with it! Returns the buffer on success NULL on failure .
char *readscript(const char *path)
{
    int handle = openpackfile(path, packfile);
    int size;
    char *buffer = NULL;
    if(handle < 0)
    {
        goto error;
    }
    size = seekpackfile(handle, 0, SEEK_END);
    if(size < 0)
    {
        goto error;
    }
    buffer = malloc(size + 1);
    if(buffer == NULL)
    {
        goto error;
    }
    if(seekpackfile(handle, 0, SEEK_SET) < 0)
    {
        goto error;
    }
    if(readpackfile(handle, buffer, size) < 0)
    {
        goto error;
    }
    closepackfile(handle);
    buffer[size] = '\0';
    return buffer;
error:
    printf("Script error: unable to open file '%s' for importing\n", path);
    if(buffer)
    {
        free(buffer);
    }
    if(handle >= 0)
    {
        closepackfile(handle);
    }
    return NULL;
}
char * readscript ( const char * path ) { int handle = openpackfile ( path , packfile ) ; int size ; char * buffer = NULL ; if ( handle < 0 ) { goto error ; } size = seekpackfile ( handle , 0 , SEEK_END ) ; if ( size < 0 ) { goto error ; } buffer = malloc ( size + 1 ) ; if ( buffer == NULL ) { goto error ; } if ( seekpackfile ( handle , 0 , SEEK_SET ) < 0 ) { goto error ; } if ( readpackfile ( handle , buffer , size ) < 0 ) { goto error ; } closepackfile ( handle ) ; buffer [ size ] = ' \0 ' ; return buffer ; error : printf ( " \n " , path ) ; if ( buffer ) { free ( buffer ) ; } if ( handle >= 0 ) { closepackfile ( handle ) ; } return NULL ; }
Reads a script file into an allocated buffer.
Reads a script file into an allocated buffer .
// ideally, this error message would include the name of the file that tried to import this file