cmFile.h/c: Added ability to use stdin,stdout,stderr.

This commit is contained in:
kevin 2013-02-25 11:39:42 -08:00
parent 8f09079fe0
commit c9a0a1b2dc
2 changed files with 38 additions and 7 deletions

View File

@ -60,6 +60,27 @@ cmFileRC_t cmFileOpen( cmFileH_t* hp, const cmChar_t* fn, enum cmFileOpenFlag
if( cmIsFlag(flags,kUpdateFileFl) )
mode[1]='+';
// handle requests to use stdin,stdout,stderr
FILE* sfp = NULL;
if( cmIsFlag(flags,kStdoutFileFl) )
{
sfp = stdout;
fn = "stdout";
}
else
if( cmIsFlag(flags,kStderrFileFl) )
{
sfp = stderr;
fn = "stderr";
}
else
if( cmIsFlag(flags,kStdinFileFl) )
{
sfp = stdin;
fn = "stdin";
}
if( fn == NULL )
return cmErrMsg(&err,kObjAllocFailFileRC,"File object allocation failed due to empty file name.");
@ -73,7 +94,10 @@ cmFileRC_t cmFileOpen( cmFileH_t* hp, const cmChar_t* fn, enum cmFileOpenFlag
p->fnStr = (cmChar_t*)(p+1);
strcpy(p->fnStr,fn);
if( sfp != NULL )
p->fp = sfp;
else
{
errno = 0;
if((p->fp = fopen(fn,mode)) == NULL )
{
@ -81,6 +105,7 @@ cmFileRC_t cmFileOpen( cmFileH_t* hp, const cmChar_t* fn, enum cmFileOpenFlag
cmMemFree(p);
return rc;
}
}
hp->h = p;

View File

@ -42,7 +42,10 @@ extern "C" {
kWriteFileFl = 0x02, //< Create an empty file for writing
kAppendFileFl = 0x04, //< Open a file for writing at the end of the file.
kUpdateFileFl = 0x08, //< Open a file for reading and writing.
kBinaryFileFl = 0x10 //< Open a file for binary (not text) input/output.
kBinaryFileFl = 0x10, //< Open a file for binary (not text) input/output.
kStdoutFileFl = 0x20, //< Ignore fn use 'stdout'
kStderrFileFl = 0x40, //< Ignore fn use 'stderr'
kStdinFileFl = 0x80, //< Ignore fn use 'stdin'
};
// Open or create a file.
@ -51,6 +54,9 @@ extern "C" {
// be set to cmFileNullHandle prior to calling this function. If *hp is a valid handle
// then it is automatically finalized by an internal call to cmFileClose() prior to
// being re-iniitalized.
//
// If kStdoutFileFl, kStderrFileFl or kStdinFileFl are set then
// file name argument 'fn' is ignored.
cmFileRC_t cmFileOpen(
cmFileH_t* hp, // Pointer to a client supplied cmFileHandle_t to recieve the handle for the new object.
const cmChar_t* fn, // The name of the file to open or create.