cmFile.h/c: Added ability to use stdin,stdout,stderr.
This commit is contained in:
parent
8f09079fe0
commit
c9a0a1b2dc
37
cmFile.c
37
cmFile.c
@ -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,13 +94,17 @@ cmFileRC_t cmFileOpen( cmFileH_t* hp, const cmChar_t* fn, enum cmFileOpenFlag
|
||||
p->fnStr = (cmChar_t*)(p+1);
|
||||
strcpy(p->fnStr,fn);
|
||||
|
||||
|
||||
errno = 0;
|
||||
if((p->fp = fopen(fn,mode)) == NULL )
|
||||
if( sfp != NULL )
|
||||
p->fp = sfp;
|
||||
else
|
||||
{
|
||||
cmFileRC_t rc = _cmFileError(p,kOpenFailFileRC,errno,"File open failed");
|
||||
cmMemFree(p);
|
||||
return rc;
|
||||
errno = 0;
|
||||
if((p->fp = fopen(fn,mode)) == NULL )
|
||||
{
|
||||
cmFileRC_t rc = _cmFileError(p,kOpenFailFileRC,errno,"File open failed");
|
||||
cmMemFree(p);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
hp->h = p;
|
||||
|
8
cmFile.h
8
cmFile.h
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user