nsILocalFile:openANSIFileDesc
From MDC
Contents |
[edit] Summary
This method is used for opening the file corresponding to this nsILocalFile.
[noscript] FILEStar openANSIFileDesc( in string aMode );
[edit] Parameters
- aMode
- [in] ANSI file open mode string, which will be passed to fopen.
[edit] Return Values
FILEStar is a typedef for a pointer to the ANSI FILE type.
[edit] Example Code
#include <stdio.h>
#include "nsError.h"
#include "nsILocalFile.h"
// Read the contents of a nsILocalFile...
nsresult ReadLocalFile(nsILocalFile *aLocalFile)
{
FILE *fp;
nsresult rv = aLocalFile->OpenANSIFileDesc("r", &fp);
if (NS_FAILED(rv))
return rv;
char buf[512];
size_t n;
while ((n = fread(buf, sizeof(buf), 1, fp)) > 0)
{
// Do something with n-byte block of data from file...
}
if (ferror(fp) != 0)
rv = NS_ERROR_UNEXPECTED;
fclose(fp);
return rv;
}