Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
nsLocalFileOSX.cpp File Reference
#include "nsLocalFile.h"
#include "nsDirectoryServiceDefs.h"
#include "nsString.h"
#include "nsReadableUtils.h"
#include "nsIDirectoryEnumerator.h"
#include "nsISimpleEnumerator.h"
#include "nsITimelineService.h"
#include "nsVoidArray.h"
#include "plbase64.h"
#include "prmem.h"
#include "nsCRT.h"
#include "MoreFilesX.h"
#include "FSCopyObject.h"
#include "nsAutoBuffer.h"
#include <Carbon/Carbon.h>
#include <unistd.h>
#include <sys/stat.h>

Go to the source code of this file.

Classes

class  StFollowLinksState
class  nsDirEnumerator
class  StAEDesc

Defines

#define GetAliasSizeFromRecord(aliasRecord)   aliasRecord.aliasSize
#define FILENAME_BUFFER_SIZE   512

Typedefs

typedef void(* UnicodeNormalizer )(CFMutableStringRef, CFStringNormalizationForm)

Functions

static nsresult MacErrorMapper (OSErr inErr)
static OSErr FindRunningAppBySignature (OSType aAppSig, ProcessSerialNumber &outPsn)
static void CopyUTF8toUTF16NFC (const nsACString &aSrc, nsAString &aResult)
bool operator== (const FSRef &lhs, const FSRef &rhs)
 NS_IMPL_THREADSAFE_ISUPPORTS4 (nsLocalFile, nsILocalFileMac, nsILocalFile, nsIFile, nsILocalFileMac_MOZILLA_1_8_BRANCH) NS_METHOD nsLocalFile
nsresult NS_NewLocalFile (const nsAString &path, PRBool followLinks, nsILocalFile **result)
 Public Method to create an instance of a nsILocalFile.
nsresult NS_NewNativeLocalFile (const nsACString &path, PRBool followLinks, nsILocalFile **result)
nsresult NS_NewLocalFileWithFSSpec (const FSSpec *inSpec, PRBool followLinks, nsILocalFileMac **result)

Variables

const PRInt64 kMilisecsPerSec = 1000LL
const PRInt64 kUTCDateTimeFractionDivisor = 65535LL

Define Documentation

Definition at line 283 of file nsLocalFileOSX.cpp.

#define GetAliasSizeFromRecord (   aliasRecord)    aliasRecord.aliasSize

Definition at line 68 of file nsLocalFileOSX.cpp.


Typedef Documentation

typedef void(* UnicodeNormalizer)(CFMutableStringRef, CFStringNormalizationForm)

Definition at line 2258 of file nsLocalFileOSX.cpp.


Function Documentation

static void CopyUTF8toUTF16NFC ( const nsACString &  aSrc,
nsAString &  aResult 
) [static]

Definition at line 2259 of file nsLocalFileOSX.cpp.

{
    static PRBool sChecked = PR_FALSE;
    static UnicodeNormalizer sUnicodeNormalizer = NULL;

    // CFStringNormalize was not introduced until Mac OS 10.2
    if (!sChecked) {
        CFBundleRef carbonBundle =
            CFBundleGetBundleWithIdentifier(CFSTR("com.apple.Carbon"));
        if (carbonBundle)
            sUnicodeNormalizer = (UnicodeNormalizer)
                ::CFBundleGetFunctionPointerForName(carbonBundle,
                                                    CFSTR("CFStringNormalize"));
        sChecked = PR_TRUE;
    }

    if (!sUnicodeNormalizer) {  // OS X 10.2 or earlier
        CopyUTF8toUTF16(aSrc, aResult);
        return;  
    }

    const nsAFlatCString &inFlatSrc = PromiseFlatCString(aSrc);

    // The number of 16bit code units in a UTF-16 string will never be
    // larger than the number of bytes in the corresponding UTF-8 string.
    CFMutableStringRef inStr =
        ::CFStringCreateMutable(NULL, inFlatSrc.Length());

    if (!inStr) {
        CopyUTF8toUTF16(aSrc, aResult);
        return;  
    }
     
    ::CFStringAppendCString(inStr, inFlatSrc.get(), kCFStringEncodingUTF8); 

    sUnicodeNormalizer(inStr, kCFStringNormalizationFormC);

    CFIndex length = CFStringGetLength(inStr);
    const UniChar* chars = CFStringGetCharactersPtr(inStr);

    if (chars) 
        aResult.Assign(chars, length);
    else {
        nsAutoBuffer<UniChar, FILENAME_BUFFER_SIZE> buffer;
        if (!buffer.EnsureElemCapacity(length))
            CopyUTF8toUTF16(aSrc, aResult);
        else {
            CFStringGetCharacters(inStr, CFRangeMake(0, length), buffer.get());
            aResult.Assign(buffer.get(), length);
        }
    }
    CFRelease(inStr);
}

Here is the call graph for this function:

static OSErr FindRunningAppBySignature ( OSType  aAppSig,
ProcessSerialNumber &  outPsn 
) [static]

Definition at line 2225 of file nsLocalFileOSX.cpp.

{
  ProcessInfoRec info;
  OSErr err = noErr;
  
  outPsn.highLongOfPSN = 0;
  outPsn.lowLongOfPSN  = kNoProcess;
  
  while (PR_TRUE)
  {
    err = ::GetNextProcess(&outPsn);
    if (err == procNotFound)
      break;
    if (err != noErr)
      return err;
    info.processInfoLength = sizeof(ProcessInfoRec);
    info.processName = nil;
    info.processAppSpec = nil;
    err = ::GetProcessInformation(&outPsn, &info);
    if (err != noErr)
      return err;
    
    if (info.processSignature == aAppSig)
      return noErr;
  }
  return procNotFound;
}

Here is the caller graph for this function:

static nsresult MacErrorMapper ( OSErr  inErr) [static]

Definition at line 2187 of file nsLocalFileOSX.cpp.

{
    nsresult outErr;
    
    switch (inErr)
    {
        case noErr:
            outErr = NS_OK;
            break;

        case fnfErr:
            outErr = NS_ERROR_FILE_NOT_FOUND;
            break;

        case dupFNErr:
            outErr = NS_ERROR_FILE_ALREADY_EXISTS;
            break;
        
        case dskFulErr:
            outErr = NS_ERROR_FILE_DISK_FULL;
            break;
        
        case fLckdErr:
            outErr = NS_ERROR_FILE_IS_LOCKED;
            break;
        
        // Can't find good map for some
        case bdNamErr:
            outErr = NS_ERROR_FAILURE;
            break;

        default:    
            outErr = NS_ERROR_FAILURE;
            break;
    }
    return outErr;
}

Here is the caller graph for this function:

Definition at line 339 of file nsLocalFileOSX.cpp.

{
  NS_ENSURE_ARG_POINTER(aInstancePtr);
  NS_ENSURE_NO_AGGREGATION(outer);

  nsLocalFile* inst = new nsLocalFile();
  if (inst == NULL)
    return NS_ERROR_OUT_OF_MEMORY;
  
  nsresult rv = inst->QueryInterface(aIID, aInstancePtr);
  if (NS_FAILED(rv))
  {
    delete inst;
    return rv;
  }
  return NS_OK;
}
nsresult NS_NewLocalFile ( const nsAString &  path,
PRBool  followLinks,
nsILocalFile **  result 
)

Public Method to create an instance of a nsILocalFile.

This function may be called prior to NS_InitXPCOM.

FROZEN

Parameters:
pathA string which specifies a full file path to a location. Relative paths will be treated as an error (NS_ERROR_FILE_UNRECOGNIZED_PATH). |NS_NewNativeLocalFile|'s path must be in the filesystem charset.
followLinksThis attribute will determine if the nsLocalFile will auto resolve symbolic links. By default, this value will be false on all non unix systems. On unix, this attribute is effectively a noop.
resultInterface pointer to a new instance of an nsILocalFile
Returns:
NS_OK for success; other error codes indicate a failure.

Definition at line 2140 of file nsLocalFileOSX.cpp.

{
    nsLocalFile* file = new nsLocalFile;
    if (file == nsnull)
        return NS_ERROR_OUT_OF_MEMORY;
    NS_ADDREF(file);

    file->SetFollowLinks(followLinks);

    if (!path.IsEmpty()) {
        nsresult rv = file->InitWithPath(path);
        if (NS_FAILED(rv)) {
            NS_RELEASE(file);
            return rv;
        }
    }
    *result = file;
    return NS_OK;
}

Here is the call graph for this function:

nsresult NS_NewLocalFileWithFSSpec ( const FSSpec inSpec,
PRBool  followLinks,
nsILocalFileMac **  result 
)

Definition at line 2165 of file nsLocalFileOSX.cpp.

{
    nsLocalFile* file = new nsLocalFile();
    if (file == nsnull)
        return NS_ERROR_OUT_OF_MEMORY;
    NS_ADDREF(file);

    file->SetFollowLinks(followLinks);

    nsresult rv = file->InitWithFSSpec(inSpec);
    if (NS_FAILED(rv)) {
        NS_RELEASE(file);
        return rv;
    }
    *result = file;
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult NS_NewNativeLocalFile ( const nsACString &  path,
PRBool  followLinks,
nsILocalFile **  result 
)

Definition at line 2160 of file nsLocalFileOSX.cpp.

{
    return NS_NewLocalFile(NS_ConvertUTF8toUCS2(path), followLinks, result);
}

Here is the call graph for this function:

bool operator== ( const FSRef lhs,
const FSRef rhs 
)

Definition at line 88 of file nsLocalFileOSX.cpp.

{
  return (::FSCompareFSRefs(&lhs, &rhs) == noErr);
}

Variable Documentation

Definition at line 2081 of file nsLocalFileOSX.cpp.

Definition at line 2082 of file nsLocalFileOSX.cpp.