Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Attributes
nsTempfilePS Class Reference

#include <nsTempfilePS.h>

Collaboration diagram for nsTempfilePS:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsTempfilePS ()
 ~nsTempfilePS ()
nsresult CreateTempFile (nsILocalFile **aFile)
 Create a temporary file and return an nsILocalFile object for accessing it.
nsresult CreateTempFile (nsILocalFile **aFile, FILE **aHandle, const char *aMode)
 Like |CreateTempFile(nsILocalFile**)|, but also initialize a stdio file handle for the file.

Private Attributes

nsCOMPtr< nsIFilemTempDir
PRUint32 mCount

Detailed Description

Definition at line 51 of file nsTempfilePS.h.


Constructor & Destructor Documentation

Definition at line 49 of file nsTempfilePS.cpp.

{
    nsresult rv;
    
    // Get the standard temporary directory.
    rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(mTempDir));
    if (NS_FAILED(rv))
        return;

    // Grab some low-order bits from the current time for use in temporary
    // filenames.
    LL_L2UI(mCount, PR_Now());

    // Append an arbitrary subdirectory name to the temp dir...
    rv = mTempDir->Append(
            NS_ConvertASCIItoUCS2(nsPrintfCString("%lx.tmp", mCount++)));
    if (NS_FAILED(rv)) {
        mTempDir = nsnull;
        return;
    }
    // and try to create it as a private directory for our temp files. Note
    // CreateUnique() may adjust the subdirectory name we just appended.
    rv = mTempDir->CreateUnique(nsIFile::DIRECTORY_TYPE, 0700);
    if (NS_FAILED(rv))
        mTempDir = nsnull;
}

Here is the call graph for this function:

Definition at line 76 of file nsTempfilePS.cpp.

{
    if (nsnull != mTempDir)
        mTempDir->Remove(PR_TRUE);
}

Member Function Documentation

Create a temporary file and return an nsILocalFile object for accessing it.

Parameters:
aFileNameAfter a successful return, this will be filled in with an nsILocalFile object for a newly-created temporary file. There are no open file descriptors to the file.
Returns:
NS_OK on success, or a suitable error value.

Definition at line 83 of file nsTempfilePS.cpp.

{
    NS_PRECONDITION(nsnull != aFile, "aFile argument is NULL");
    NS_ENSURE_TRUE(nsnull != mTempDir, NS_ERROR_NOT_INITIALIZED);

    // Get the temporary directory path
    nsresult rv;
    nsAutoString tmpdir;
    rv = mTempDir->GetPath(tmpdir);
    NS_ENSURE_SUCCESS(rv, rv);

    // Create a new object for the temporary file
    nsCOMPtr<nsILocalFile> tmpfile;
    rv = NS_NewLocalFile(tmpdir, PR_FALSE, getter_AddRefs(tmpfile));
    NS_ENSURE_SUCCESS(rv, rv);
    NS_POSTCONDITION(nsnull != tmpfile,
            "NS_NewLocalFile succeeded but tmpfile is invalid");

    rv = tmpfile->Append(
            NS_ConvertASCIItoUCS2(nsPrintfCString("%lx.tmp", mCount++)));
    NS_ENSURE_SUCCESS(rv, rv);

    // Create the temporary file. This may adjust the file's basename.
    rv = tmpfile->CreateUnique(nsIFile::NORMAL_FILE_TYPE, 0600);
    NS_ENSURE_SUCCESS(rv, rv);

    *aFile = tmpfile.get();
    NS_ADDREF(*aFile);
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsTempfilePS::CreateTempFile ( nsILocalFile **  aFile,
FILE **  aHandle,
const char *  aMode 
)

Like |CreateTempFile(nsILocalFile**)|, but also initialize a stdio file handle for the file.

Parameters:
aFileNameAfter a successful return, this will be filled in with an nsILocalFile object for a newly-created temporary file.
aHandleAfter a successful return, this will be filled in with a file handle that may be used to access the file, opened according to the specified mode.
aModeStdio mode string for opening the temporary file. See fopen(3).
Returns:
NS_OK on success, or a suitable error value.

Definition at line 116 of file nsTempfilePS.cpp.

{
    NS_PRECONDITION(nsnull != aHandle, "aHandle is invalid");
    NS_PRECONDITION(nsnull != aMode, "aMode is invalid");

    nsresult rv = CreateTempFile(aFile);
    NS_ENSURE_SUCCESS(rv, rv);
    NS_POSTCONDITION(nsnull != *aFile,
            "CreateTempFile() succeeded but *aFile is invalid");

    rv = (*aFile)->OpenANSIFileDesc(aMode, aHandle);
    if (NS_FAILED(rv)) {
        (*aFile)->Remove(PR_FALSE);
        NS_RELEASE(*aFile);
    }
    return rv;
}

Here is the call graph for this function:


Member Data Documentation

Definition at line 88 of file nsTempfilePS.h.

Definition at line 87 of file nsTempfilePS.h.


The documentation for this class was generated from the following files: