www.pudn.com > PEMonitor_0.10_src.zip > FileServ.c


/////////////////////////////////////////////////////////////////////////////// 
// 
//  FileName    :   FileServ.c 
//  Version     :   0.10 
//  Author      :   Luo Cong 
//  Date        :   2004-09-02 (yyyy-mm-dd) 
//  Comment     : 
// 
/////////////////////////////////////////////////////////////////////////////// 
 
#include  
#include  
#include "Misc.h" 
#include "FileServ.h" 
 
int ReadFileContents( 
    /* [in] */ const char *szFileName 
) 
{ 
    int nRetResult = 0; 
    FILE *fp_in = NULL; 
 
    fp_in = fopen(szFileName, "rb"); 
    if (NULL == fp_in) 
    { 
        printf(ErrMsg[ERR_OPEN_FILE], szFileName); 
        goto Exit0; 
    } 
 
    fseek(fp_in, 0L, SEEK_END); 
    g_lFileSize = ftell(fp_in); 
    rewind(fp_in); 
 
    g_FileContents = (char *)malloc(g_lFileSize); 
    if (NULL == g_FileContents) 
    { 
        printf(ErrMsg[ERR_MALLOC_MEMORY], szFileName); 
        goto Exit0; 
    } 
 
    fread(g_FileContents, 1, g_lFileSize, fp_in); 
 
    nRetResult = 1; 
Exit0: 
    if (fp_in) 
    { 
        fclose(fp_in); 
        fp_in = NULL; 
    } 
    return nRetResult; 
} 
 
void FreeFileContents() 
{ 
    if (g_FileContents) 
    { 
        free(g_FileContents); 
        g_FileContents = NULL; 
    } 
}