VirtualBox

Changeset 589 in vbox for trunk/src/libs/xpcom18a4/xpcom


Ignore:
Timestamp:
Feb 4, 2007 12:25:57 PM (18 years ago)
Author:
vboxsync
Message:

Make it build and run on Mac OS X.

Location:
trunk/src/libs/xpcom18a4/xpcom
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/xpcom/MoreFiles/FSCopyObject.c

    r1 r589  
    4444        Copyright © 2002 Apple Computer, Inc., All Rights Reserved
    4545*/
     46
     47// Modified 2006-01-23 - added this comment.
    4648
    4749#include "FSCopyObject.h"
  • trunk/src/libs/xpcom18a4/xpcom/MoreFiles/FSCopyObject.h

    r1 r589  
    4242*/
    4343
     44// Modified 2006-01-23 - added this comment.
    4445
    4546#ifndef __FSCOPYOBJECT_H__
  • trunk/src/libs/xpcom18a4/xpcom/MoreFiles/MoreFilesX.c

    r1 r589  
    6969                 <1>     1/25/02        JL              MoreFilesX 1.0
    7070*/
     71
     72// Modified 2006-01-23 - added this comment.
    7173
    7274#if defined(__MACH__)
     
    21252127/*****************************************************************************/
    21262128
    2127 OSErr
    2128 FSLockRange(
     2129/* Renamed from FSLockRange to MFX_FSLockRange to avoid a conflict with
     2130 * the FSLockRange function present in the system library since Mac OS X
     2131 * 10.4. */
     2132
     2133OSErr
     2134MFX_FSLockRange(
    21292135        SInt16 refNum,
    21302136        SInt32 rangeLength,
     
    21482154/*****************************************************************************/
    21492155
    2150 OSErr
    2151 FSUnlockRange(
     2156/* Renamed from FSUnlockRange to MFX_FSUnlockRange to avoid a conflict with
     2157 * the FSUnlockRange function present in the system library since Mac OS X
     2158 * 10.4. */
     2159
     2160OSErr
     2161MFX_FSUnlockRange(
    21522162        SInt16 refNum,
    21532163        SInt32 rangeLength,
     
    23072317/*****************************************************************************/
    23082318
     2319// This function exists in Mac OS X 10.5, we cannot re-define it here.
     2320// We don't use this function, so just don't compile it.
     2321#if 0
    23092322OSErr
    23102323FSVolumeMount(
     
    23302343        return ( result );
    23312344}
     2345#endif
    23322346
    23332347/*****************************************************************************/
  • trunk/src/libs/xpcom18a4/xpcom/MoreFiles/MoreFilesX.h

    r1 r589  
    8484                                do less work.
    8585*/
     86
     87// Modified 2006-01-23 - added this comment.
    8688
    8789#ifndef __MOREFILESX__
     
    13331335/*****************************************************************************/
    13341336
    1335 #pragma mark FSLockRange
    1336 
    1337 OSErr
    1338 FSLockRange(
     1337#pragma mark MFX_FSLockRange
     1338/* Renamed from FSLockRange to MFX_FSLockRange to avoid a conflict with
     1339 * the FSLockRange function present in the system library since Mac OS X
     1340 * 10.4. */
     1341
     1342OSErr
     1343MFX_FSLockRange(
    13391344        SInt16 refNum,
    13401345        SInt32 rangeLength,
     
    13561361/*****************************************************************************/
    13571362
    1358 #pragma mark FSUnlockRange
    1359 
    1360 OSErr
    1361 FSUnlockRange(
     1363#pragma mark MFX_FSUnlockRange
     1364/* Renamed from FSUnlockRange to MFX_FSUnlockRange to avoid a conflict with
     1365 * the FSUnlockRange function present in the system library since Mac OS X
     1366 * 10.4. */
     1367
     1368OSErr
     1369MFX_FSUnlockRange(
    13621370        SInt16 refNum,
    13631371        SInt32 rangeLength,
     
    14831491#pragma mark FSVolumeMount
    14841492
     1493// This function exists in Mac OS X 10.5, we cannot re-define it here.
     1494// We don't use this function, so just don't compile it.
     1495#if 0
    14851496OSErr
    14861497FSVolumeMount(
    14871498        const void *volMountInfo,
    14881499        FSVolumeRefNum *volRefNum);
     1500#endif
    14891501
    14901502/*
  • trunk/src/libs/xpcom18a4/xpcom/io/nsILocalFileMac.idl

    r1 r589  
    2222 * Contributor(s):
    2323 *  Conrad Carlen <[email protected]>
     24 *  Mark Mentovai <[email protected]>
    2425 *
    2526 * Alternatively, the contents of this file may be used under the terms of
     
    5152      native CFURLRef(CFURLRef);
    5253
    53 [uuid(614c3010-1dd2-11b2-be04-bcd57a64ffc9)]
     54[scriptable, uuid(748f3ffe-27d9-4402-9de9-494badbeebf4)]
    5455interface nsILocalFileMac : nsILocalFile
    5556{
     
    6566    *
    6667    */
    67     void initWithCFURL(in CFURLRef aCFURL);
     68  [noscript] void initWithCFURL(in CFURLRef aCFURL);
    6869
    6970   /**
     
    7778    *
    7879    */
    79     void initWithFSRef([const] in FSRefPtr aFSRef);
     80  [noscript] void initWithFSRef([const] in FSRefPtr aFSRef);
    8081
    8182   /**
     
    8889    *
    8990    */
    90     void initWithFSSpec([const] in FSSpecPtr aFileSpec);
     91  [noscript] void initWithFSSpec([const] in FSSpecPtr aFileSpec);
    9192
    9293   /**
     
    100101    *
    101102    */
    102     void initToAppWithCreatorCode(in OSType aAppCreator);
     103  [noscript] void initToAppWithCreatorCode(in OSType aAppCreator);
    103104
    104105    /**
     
    116117    *
    117118    * @return
    118     * 
    119     */ 
    120     CFURLRef getCFURL();
    121  
     119    *
     120    */
     121  [noscript] CFURLRef getCFURL();
     122
    122123    /**
    123124    * getFSRef
     
    133134    *
    134135    * @return
    135     * 
    136     */ 
    137     FSRef getFSRef();
    138    
     136    *
     137    */
     138  [noscript] FSRef getFSRef();
     139
    139140   /**
    140141    * getFSSpec
     
    148149    *
    149150    * @return
    150     * 
    151     */ 
    152     FSSpec getFSSpec();
     151    *
     152    */
     153  [noscript] FSSpec getFSSpec();
    153154
    154155   /**
    155156    * fileSizeWithResFork
    156     * 
     157    *
    157158    * Returns the combined size of both the data fork and the resource
    158159    * fork (if present) rather than just the size of the data fork
     
    160161    *
    161162    */
    162     readonly attribute PRInt64 fileSizeWithResFork;
    163    
     163   readonly attribute PRInt64 fileSizeWithResFork;
     164
    164165   /**
    165166    * Use with SetFileType() to specify the signature of current process
    166167    */
    167     const unsigned long CURRENT_PROCESS_CREATOR = 0x8000000;
    168    
     168   const unsigned long CURRENT_PROCESS_CREATOR = 0x8000000;
     169
    169170   /**
    170171    * fileType, creator
     
    173174    *
    174175    */
    175     attribute OSType fileType;
    176     attribute OSType fileCreator;
    177    
     176   [noscript] attribute OSType fileType;
     177   [noscript] attribute OSType fileCreator;
     178
    178179   /**
    179180    * setFileTypeAndCreatorFromMIMEType
     
    185186    *
    186187    */
    187     void setFileTypeAndCreatorFromMIMEType(in string aMIMEType);
    188    
     188   void setFileTypeAndCreatorFromMIMEType(in string aMIMEType);
     189
    189190   /**
    190191    * setFileTypeAndCreatorFromExtension
     
    196197    *
    197198    */
    198     void setFileTypeAndCreatorFromExtension(in string aExtension);
    199    
     199   void setFileTypeAndCreatorFromExtension(in string aExtension);
     200
    200201   /**
    201202    * launchWithDoc
     
    207208    *
    208209    */
    209     void launchWithDoc(in nsILocalFile aDocToLoad, in boolean aLaunchInBackground);
     210   void launchWithDoc(in nsILocalFile aDocToLoad, in boolean aLaunchInBackground);
    210211
    211212   /**
     
    220221    *
    221222    */
    222     void openDocWithApp(in nsILocalFile aAppToOpenWith, in boolean aLaunchInBackground);
     223   void openDocWithApp(in nsILocalFile aAppToOpenWith, in boolean aLaunchInBackground);
    223224
    224225   /**
     
    228229    *
    229230    */
    230     boolean isPackage();
     231   boolean isPackage();
     232
     233   /**
     234    * bundleDisplayName
     235    *
     236    * returns the display name of the application bundle (usually the human
     237    * readable name of the application)
     238    */
     239   readonly attribute AString bundleDisplayName;
     240
     241   /**
     242    * bundleIdentifier
     243    *
     244    * returns the identifier of the bundle
     245    */
     246   readonly attribute AUTF8String bundleIdentifier;
    231247};
    232248
     
    240256
    241257NS_EXPORT nsresult NS_NewLocalFileWithFSSpec(const FSSpec* inSpec, PRBool followSymlinks, nsILocalFileMac* *result);
     258
     259// NS_NewLocalFileWithFSRef is available since Mozilla 1.8.1.
     260NS_EXPORT nsresult NS_NewLocalFileWithFSRef(const FSRef* aFSRef, PRBool aFollowSymlinks, nsILocalFileMac** result);
    242261}
    243262%}
  • trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileOSX.cpp

    r1 r589  
    2323 *  Conrad Carlen <[email protected]>
    2424 *  Jungshik Shin <[email protected]>
     25 *  Asaf Romano <[email protected]>
     26 *  Mark Mentovai <[email protected]>
    2527 *
    2628 * Alternatively, the contents of this file may be used under the terms of
     
    3941
    4042#include "nsLocalFile.h"
     43#include "nsDirectoryServiceDefs.h"
    4144
    4245#include "nsString.h"
    4346#include "nsReadableUtils.h"
     47#include "nsIDirectoryEnumerator.h"
    4448#include "nsISimpleEnumerator.h"
    4549#include "nsITimelineService.h"
     
    4953#include "prmem.h"
    5054#include "nsCRT.h"
     55#include "nsHashKeys.h"
    5156
    5257#include "MoreFilesX.h"
    5358#include "FSCopyObject.h"
    5459#include "nsAutoBuffer.h"
     60#include "nsTraceRefcntImpl.h"
    5561
    5662// Mac Includes
    57 #include <Aliases.h>
    58 #include <Gestalt.h>
    59 #include <AppleEvents.h>
    60 #include <AEDataModel.h>
    61 #include <Processes.h>
    6263#include <Carbon/Carbon.h>
    6364
    6465// Unix Includes
     66#include <unistd.h>
    6567#include <sys/stat.h>
     68#include <stdlib.h>
     69
     70#if !defined(MAC_OS_X_VERSION_10_4) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_4
     71#define GetAliasSizeFromRecord(aliasRecord) aliasRecord.aliasSize
     72#else
     73#define GetAliasSizeFromRecord(aliasRecord) GetAliasSizeFromPtr(&aliasRecord)
     74#endif
     75
     76#define CHECK_mBaseRef()                        \
     77    PR_BEGIN_MACRO                              \
     78        if (!mBaseRef)                          \
     79            return NS_ERROR_NOT_INITIALIZED;    \
     80    PR_END_MACRO
    6681
    6782//*****************************************************************************
     
    108123        mFile.SetFollowLinks(mSavedState);
    109124    }
    110    
     125
    111126  private:
    112127    nsLocalFile& mFile;
     
    117132#pragma mark [nsDirEnumerator]
    118133
    119 class nsDirEnumerator : public nsISimpleEnumerator
     134class nsDirEnumerator : public nsISimpleEnumerator,
     135                        public nsIDirectoryEnumerator
    120136{
    121137    public:
     
    130146        }
    131147
    132         nsresult Init(nsILocalFileMac* parent) 
     148        nsresult Init(nsILocalFileMac* parent)
    133149        {
    134150          NS_ENSURE_ARG(parent);
    135          
     151
    136152          OSErr err;
    137153          nsresult rv;
    138154          FSRef parentRef;
    139          
     155
    140156          rv = parent->GetFSRef(&parentRef);
    141157          if (NS_FAILED(rv))
    142158            return rv;
    143          
     159
    144160          mFSRefsArray = (FSRef *)nsMemory::Alloc(sizeof(FSRef)
    145161                                                  * kRequestCountPerIteration);
    146162          if (!mFSRefsArray)
    147163            return NS_ERROR_OUT_OF_MEMORY;
    148          
     164
    149165          err = ::FSOpenIterator(&parentRef, kFSIterateFlat, &mIterator);
    150166          if (err != noErr)
    151167            return MacErrorMapper(err);
    152                              
     168
    153169          return NS_OK;
    154170        }
    155171
    156         NS_IMETHOD HasMoreElements(PRBool *result) 
     172        NS_IMETHOD HasMoreElements(PRBool *result)
    157173        {
    158174          if (mNext == nsnull) {
     
    168184                                           nsnull,
    169185                                           nsnull);
    170            
     186
    171187              if (err == noErr || err == errFSNoMoreItems) {
    172188                mArrayCnt = actualCnt;
     
    183199              mArrayIndex++;
    184200              mNext = newFile;
    185             } 
     201            }
    186202          }
    187203          *result = mNext != nsnull;
     204          if (!*result)
     205            Close();
    188206          return NS_OK;
    189207        }
    190208
    191         NS_IMETHOD GetNext(nsISupports **result) 
     209        NS_IMETHOD GetNext(nsISupports **result)
    192210        {
    193211            NS_ENSURE_ARG_POINTER(result);
     
    206224        }
    207225
     226        NS_IMETHOD GetNextFile(nsIFile **result)
     227        {
     228            *result = nsnull;
     229            PRBool hasMore = PR_FALSE;
     230            nsresult rv = HasMoreElements(&hasMore);
     231            if (NS_FAILED(rv) || !hasMore)
     232                return rv;
     233            *result = mNext;
     234            NS_IF_ADDREF(*result);
     235            mNext = nsnull;
     236            return NS_OK;
     237        }
     238
     239        NS_IMETHOD Close()
     240        {
     241          if (mIterator) {
     242            ::FSCloseIterator(mIterator);
     243            mIterator = nsnull;
     244          }
     245          if (mFSRefsArray) {
     246            nsMemory::Free(mFSRefsArray);
     247            mFSRefsArray = nsnull;
     248          }
     249          return NS_OK;
     250        }
     251
    208252    private:
    209         ~nsDirEnumerator() 
     253        ~nsDirEnumerator()
    210254        {
    211           if (mIterator)
    212             ::FSCloseIterator(mIterator);
    213           if (mFSRefsArray)
    214             nsMemory::Free(mFSRefsArray);
     255          Close();
    215256        }
    216257
     
    221262          kRequestCountPerIteration = ((4096 * 4) / sizeof(FSRef))
    222263        };
    223        
     264
    224265        nsCOMPtr<nsILocalFileMac>   mNext;
    225        
     266
    226267        FSIterator              mIterator;
    227268        FSRef                   *mFSRefsArray;
     
    229270};
    230271
    231 NS_IMPL_ISUPPORTS1(nsDirEnumerator, nsISimpleEnumerator)
     272NS_IMPL_ISUPPORTS2(nsDirEnumerator, nsISimpleEnumerator, nsIDirectoryEnumerator)
    232273
    233274#pragma mark -
     
    242283      dataHandle = nil;
    243284    }
    244              
     285
    245286    ~StAEDesc()
    246287    {
     
    305346#pragma mark [nsISupports]
    306347
    307 NS_IMPL_THREADSAFE_ISUPPORTS3(nsLocalFile,
     348NS_IMPL_THREADSAFE_ISUPPORTS4(nsLocalFile,
    308349                              nsILocalFileMac,
    309350                              nsILocalFile,
    310                               nsIFile)
    311                              
     351                              nsIFile,
     352                              nsIHashable)
     353
    312354NS_METHOD nsLocalFile::nsLocalFileConstructor(nsISupports* outer, const nsIID& aIID, void* *aInstancePtr)
    313355{
     
    318360  if (inst == NULL)
    319361    return NS_ERROR_OUT_OF_MEMORY;
    320  
     362
    321363  nsresult rv = inst->QueryInterface(aIID, aInstancePtr);
    322364  if (NS_FAILED(rv))
     
    338380NS_IMETHODIMP nsLocalFile::Append(const nsAString& aNode)
    339381{
    340   return AppendNative(NS_ConvertUCS2toUTF8(aNode));
     382  return AppendNative(NS_ConvertUTF16toUTF8(aNode));
    341383}
    342384
     
    344386NS_IMETHODIMP nsLocalFile::AppendNative(const nsACString& aNode)
    345387{
    346   if (!mBaseRef)
    347     return NS_ERROR_NOT_INITIALIZED;
     388  // Check we are correctly initialized.
     389  CHECK_mBaseRef();
    348390
    349391  nsACString::const_iterator start, end;
     
    372414NS_IMETHODIMP nsLocalFile::Normalize()
    373415{
    374     return NS_OK;
     416  // Check we are correctly initialized.
     417  CHECK_mBaseRef();
     418
     419  // CFURL doesn't doesn't seem to resolve paths containing relative
     420  // components, so we'll nick the stdlib code from nsLocalFileUnix
     421  UInt8 path[PATH_MAX] = "";
     422  Boolean success;
     423  success = ::CFURLGetFileSystemRepresentation(mBaseRef, true, path, PATH_MAX);
     424  if (!success)
     425    return NS_ERROR_FAILURE;
     426
     427  char resolved_path[PATH_MAX] = "";
     428  char *resolved_path_ptr = nsnull;
     429  resolved_path_ptr = realpath((char*)path, resolved_path);
     430
     431  // if there is an error, the return is null.
     432  if (!resolved_path_ptr)
     433      return NSRESULT_FOR_ERRNO();
     434
     435  // Need to know whether we're a directory to create a new CFURLRef
     436  PRBool isDirectory;
     437  nsresult rv = IsDirectory(&isDirectory);
     438  NS_ENSURE_SUCCESS(rv, rv);
     439
     440  rv = NS_ERROR_FAILURE;
     441  CFStringRef pathStrRef =
     442    ::CFStringCreateWithCString(kCFAllocatorDefault,
     443                                resolved_path,
     444                                kCFStringEncodingUTF8);
     445  if (pathStrRef) {
     446    CFURLRef newURLRef =
     447      ::CFURLCreateWithFileSystemPath(kCFAllocatorDefault, pathStrRef,
     448                                      kCFURLPOSIXPathStyle, isDirectory);
     449    if (newURLRef) {
     450      SetBaseRef(newURLRef);
     451      ::CFRelease(newURLRef);
     452      rv = NS_OK;
     453    }
     454    ::CFRelease(pathStrRef);
     455  }
     456
     457  return rv;
    375458}
    376459
     
    380463  if (type != NORMAL_FILE_TYPE && type != DIRECTORY_TYPE)
    381464    return NS_ERROR_FILE_UNKNOWN_TYPE;
    382   if (!mBaseRef)
    383     return NS_ERROR_NOT_INITIALIZED;
    384  
     465
     466  // Check we are correctly initialized.
     467  CHECK_mBaseRef();
     468
    385469  nsStringArray nonExtantNodes;
    386470  CFURLRef pathURLRef = mBaseRef;
     
    389473  nsAutoBuffer<UniChar, FILENAME_BUFFER_SIZE> buffer;
    390474  Boolean success;
    391  
     475
    392476  // Work backwards through the path to find the last node which
    393477  // exists. Place the nodes which don't exist in an array and we'll
     
    405489    ::CFRelease(leafStrRef);
    406490    leafStrRef = nsnull;
    407    
     491
    408492    // Get the parent of the leaf for the next go round
    409493    CFURLRef parent = ::CFURLCreateCopyDeletingLastPathComponent(NULL, pathURLRef);
     
    423507  if (nodesToCreate == 0)
    424508    return NS_ERROR_FILE_ALREADY_EXISTS;
    425  
    426   OSErr err;   
     509
     510  OSErr err;
    427511  nsAutoString nextNodeName;
    428512  for (PRInt32 i = nodesToCreate - 1; i > 0; i--) {
     
    451535                                    nsnull, nsnull, nsnull, nsnull);
    452536  }
    453            
     537
    454538  return MacErrorMapper(err);
    455539}
     
    468552NS_IMETHODIMP nsLocalFile::SetLeafName(const nsAString& aLeafName)
    469553{
    470   return SetNativeLeafName(NS_ConvertUCS2toUTF8(aLeafName));
     554  return SetNativeLeafName(NS_ConvertUTF16toUTF8(aLeafName));
    471555}
    472556
     
    474558NS_IMETHODIMP nsLocalFile::GetNativeLeafName(nsACString& aNativeLeafName)
    475559{
    476   if (!mBaseRef)
    477     return NS_ERROR_NOT_INITIALIZED;
     560  // Check we are correctly initialized.
     561  CHECK_mBaseRef();
     562
    478563  nsresult rv = NS_ERROR_FAILURE;
    479564  CFStringRef leafStrRef = ::CFURLCopyLastPathComponent(mBaseRef);
     
    482567    ::CFRelease(leafStrRef);
    483568  }
    484   return rv;                                 
     569  return rv;
    485570}
    486571
    487572NS_IMETHODIMP nsLocalFile::SetNativeLeafName(const nsACString& aNativeLeafName)
    488573{
    489   if (!mBaseRef)
    490     return NS_ERROR_NOT_INITIALIZED;
     574  // Check we are correctly initialized.
     575  CHECK_mBaseRef();
     576
    491577  nsresult rv = NS_ERROR_FAILURE;
    492578  CFURLRef parentURLRef = ::CFURLCreateCopyDeletingLastPathComponent(kCFAllocatorDefault, mBaseRef);
     
    514600NS_IMETHODIMP nsLocalFile::CopyTo(nsIFile *newParentDir, const nsAString& newName)
    515601{
    516     return MoveCopy(newParentDir, newName, PR_TRUE, PR_FALSE);
     602  return CopyInternal(newParentDir, newName, PR_FALSE);
    517603}
    518604
     
    520606NS_IMETHODIMP nsLocalFile::CopyToNative(nsIFile *newParentDir, const nsACString& newName)
    521607{
    522     return MoveCopy(newParentDir, NS_ConvertUTF8toUCS2(newName), PR_TRUE, PR_FALSE);
     608  return CopyInternal(newParentDir, NS_ConvertUTF8toUTF16(newName), PR_FALSE);
    523609}
    524610
     
    526612NS_IMETHODIMP nsLocalFile::CopyToFollowingLinks(nsIFile *newParentDir, const nsAString& newName)
    527613{
    528     return MoveCopy(newParentDir, newName, PR_TRUE, PR_TRUE);
     614  return CopyInternal(newParentDir, newName, PR_TRUE);
    529615}
    530616
     
    532618NS_IMETHODIMP nsLocalFile::CopyToFollowingLinksNative(nsIFile *newParentDir, const nsACString& newName)
    533619{
    534     return MoveCopy(newParentDir, NS_ConvertUTF8toUCS2(newName), PR_TRUE, PR_TRUE);
     620  return CopyInternal(newParentDir, NS_ConvertUTF8toUTF16(newName), PR_TRUE);
    535621}
    536622
     
    538624NS_IMETHODIMP nsLocalFile::MoveTo(nsIFile *newParentDir, const nsAString& newName)
    539625{
    540     return MoveCopy(newParentDir, newName, FALSE, FALSE);
     626  return MoveToNative(newParentDir, NS_ConvertUTF16toUTF8(newName));
    541627}
    542628
     
    544630NS_IMETHODIMP nsLocalFile::MoveToNative(nsIFile *newParentDir, const nsACString& newName)
    545631{
    546     return MoveCopy(newParentDir, NS_ConvertUTF8toUCS2(newName), FALSE, FALSE);
     632  // Check we are correctly initialized.
     633  CHECK_mBaseRef();
     634
     635  StFollowLinksState followLinks(*this, PR_FALSE);
     636
     637  PRBool isDirectory;
     638  nsresult rv = IsDirectory(&isDirectory);
     639  if (NS_FAILED(rv))
     640    return rv;
     641
     642  // Get the source path.
     643  nsCAutoString srcPath;
     644  rv = GetNativePath(srcPath);
     645  if (NS_FAILED(rv))
     646    return rv;
     647
     648  // Build the destination path.
     649  nsCOMPtr<nsIFile> parentDir = newParentDir;
     650  if (!parentDir) {
     651    if (newName.IsEmpty())
     652      return NS_ERROR_INVALID_ARG;
     653    rv = GetParent(getter_AddRefs(parentDir));
     654    if (NS_FAILED(rv))
     655      return rv;
     656  }
     657  else {
     658    PRBool exists;
     659    rv = parentDir->Exists(&exists);
     660    if (NS_FAILED(rv))
     661      return rv;
     662    if (!exists) {
     663      rv = parentDir->Create(nsIFile::DIRECTORY_TYPE, 0777);
     664      if (NS_FAILED(rv))
     665        return rv;
     666    }
     667  }
     668
     669  nsCAutoString destPath;
     670  rv = parentDir->GetNativePath(destPath);
     671  if (NS_FAILED(rv))
     672    return rv;
     673
     674  if (!newName.IsEmpty())
     675    destPath.Append(NS_LITERAL_CSTRING("/") + newName);
     676  else {
     677    nsCAutoString leafName;
     678    rv = GetNativeLeafName(leafName);
     679    if (NS_FAILED(rv))
     680      return rv;
     681    destPath.Append(NS_LITERAL_CSTRING("/") + leafName);
     682  }
     683
     684  // Perform the move.
     685  if (rename(srcPath.get(), destPath.get()) != 0) {
     686    if (errno == EXDEV) {
     687      // Can't move across volume (device) boundaries.  Copy and remove.
     688      rv = CopyToNative(parentDir, newName);
     689      if (NS_SUCCEEDED(rv)) {
     690        // Permit removal failure.
     691        Remove(PR_TRUE);
     692      }
     693    }
     694    else
     695      rv = NSRESULT_FOR_ERRNO();
     696
     697    if (NS_FAILED(rv))
     698      return rv;
     699  }
     700
     701  // Update |this| to refer to the moved file.
     702  CFURLRef newBaseRef =
     703   ::CFURLCreateFromFileSystemRepresentation(NULL, (UInt8*)destPath.get(),
     704                                             destPath.Length(), isDirectory);
     705  if (!newBaseRef)
     706    return NS_ERROR_FAILURE;
     707  SetBaseRef(newBaseRef);
     708  ::CFRelease(newBaseRef);
     709
     710  return rv;
    547711}
    548712
     
    550714NS_IMETHODIMP nsLocalFile::Remove(PRBool recursive)
    551715{
    552   StFollowLinksState followLinks(*this, PR_FALSE); // XXX If we're an alias, never remove target
    553  
     716  // Check we are correctly initialized.
     717  CHECK_mBaseRef();
     718
     719  // XXX If we're an alias, never remove target
     720  StFollowLinksState followLinks(*this, PR_FALSE);
     721
     722  PRBool isDirectory;
     723  nsresult rv = IsDirectory(&isDirectory);
     724  if (NS_FAILED(rv))
     725    return rv;
     726
     727  if (recursive && isDirectory) {
     728    FSRef fsRef;
     729    rv = GetFSRefInternal(fsRef);
     730    if (NS_FAILED(rv))
     731      return rv;
     732
     733    // Call MoreFilesX to do a recursive removal.
     734    OSStatus err = ::FSDeleteContainer(&fsRef);
     735    rv = MacErrorMapper(err);
     736  }
     737  else {
     738    nsCAutoString path;
     739    rv = GetNativePath(path);
     740    if (NS_FAILED(rv))
     741      return rv;
     742
     743    const char* pathPtr = path.get();
     744    int status;
     745    if (isDirectory)
     746      status = rmdir(pathPtr);
     747    else
     748      status = unlink(pathPtr);
     749
     750    if (status != 0)
     751      rv = NSRESULT_FOR_ERRNO();
     752  }
     753
     754  mCachedFSRefValid = PR_FALSE;
     755  return rv;
     756}
     757
     758/* attribute unsigned long permissions; */
     759NS_IMETHODIMP nsLocalFile::GetPermissions(PRUint32 *aPermissions)
     760{
     761  NS_ENSURE_ARG_POINTER(aPermissions);
     762
    554763  FSRef fsRef;
    555764  nsresult rv = GetFSRefInternal(fsRef);
    556765  if (NS_FAILED(rv))
    557766    return rv;
    558    
    559   PRBool isDir;
    560   rv = IsDirectory(&isDir);
    561   if (NS_FAILED(rv))
    562     return rv;
    563  
    564   OSErr err;
    565   if (recursive && isDir)
    566     err = ::FSDeleteContainer(&fsRef);
    567   else
    568     err = ::FSDeleteObject(&fsRef);
    569  
    570   mCachedFSRefValid = PR_FALSE;
    571   return MacErrorMapper(err);
    572 }
    573 
    574 /* attribute unsigned long permissions; */
    575 NS_IMETHODIMP nsLocalFile::GetPermissions(PRUint32 *aPermissions)
    576 {
    577   NS_ENSURE_ARG_POINTER(aPermissions);
    578  
    579   FSRef fsRef;
    580   nsresult rv = GetFSRefInternal(fsRef);
    581   if (NS_FAILED(rv))
    582     return rv;
    583    
     767
    584768  FSCatalogInfo catalogInfo;
    585769  OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoPermissions, &catalogInfo,
     
    598782  if (NS_FAILED(rv))
    599783    return rv;
    600  
     784
    601785  FSCatalogInfo catalogInfo;
    602786  OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoPermissions, &catalogInfo,
     
    626810NS_IMETHODIMP nsLocalFile::GetLastModifiedTime(PRInt64 *aLastModifiedTime)
    627811{
     812  // Check we are correctly initialized.
     813  CHECK_mBaseRef();
     814
    628815  NS_ENSURE_ARG_POINTER(aLastModifiedTime);
    629  
     816
    630817  FSRef fsRef;
    631818  nsresult rv = GetFSRefInternal(fsRef);
    632819  if (NS_FAILED(rv))
    633820    return rv;
    634    
     821
    635822  FSCatalogInfo catalogInfo;
    636823  OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoContentMod, &catalogInfo,
     
    638825  if (err != noErr)
    639826    return MacErrorMapper(err);
    640   *aLastModifiedTime = HFSPlustoNSPRTime(catalogInfo.contentModDate); 
     827  *aLastModifiedTime = HFSPlustoNSPRTime(catalogInfo.contentModDate);
    641828  return NS_OK;
    642829}
     
    644831NS_IMETHODIMP nsLocalFile::SetLastModifiedTime(PRInt64 aLastModifiedTime)
    645832{
     833  // Check we are correctly initialized.
     834  CHECK_mBaseRef();
     835
    646836  OSErr err;
    647837  nsresult rv;
     
    661851  if (err != noErr)
    662852    return MacErrorMapper(err);
    663  
     853
    664854  /* Notify the parent if this is a file */
    665855  notifyParent = (0 == (catalogInfo.nodeFlags & kFSNodeIsDirectoryMask));
     
    695885  NS_ENSURE_ARG_POINTER(aFileSize);
    696886  *aFileSize = 0;
    697  
     887
    698888  FSRef fsRef;
    699889  nsresult rv = GetFSRefInternal(fsRef);
    700890  if (NS_FAILED(rv))
    701891    return rv;
    702      
     892
    703893  FSCatalogInfo catalogInfo;
    704894  OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags + kFSCatInfoDataSizes, &catalogInfo,
     
    706896  if (err != noErr)
    707897    return MacErrorMapper(err);
    708  
     898
    709899  // FSGetCatalogInfo can return a bogus size for directories sometimes, so only
    710900  // rely on the answer for files
     
    716906NS_IMETHODIMP nsLocalFile::SetFileSize(PRInt64 aFileSize)
    717907{
     908  // Check we are correctly initialized.
     909  CHECK_mBaseRef();
     910
    718911  FSRef fsRef;
    719912  nsresult rv = GetFSRefInternal(fsRef);
    720913  if (NS_FAILED(rv))
    721914    return rv;
    722  
    723   SInt16 refNum;   
     915
     916  SInt16 refNum;
    724917  OSErr err = ::FSOpenFork(&fsRef, 0, nsnull, fsWrPerm, &refNum);
    725918  if (err != noErr)
    726919    return MacErrorMapper(err);
    727920  err = ::FSSetForkSize(refNum, fsFromStart, aFileSize);
    728   ::FSCloseFork(refNum); 
    729  
     921  ::FSCloseFork(refNum);
     922
    730923  return MacErrorMapper(err);
    731924}
     
    734927NS_IMETHODIMP nsLocalFile::GetFileSizeOfLink(PRInt64 *aFileSizeOfLink)
    735928{
     929  // Check we are correctly initialized.
     930  CHECK_mBaseRef();
     931
    736932  NS_ENSURE_ARG_POINTER(aFileSizeOfLink);
    737  
     933
    738934  StFollowLinksState followLinks(*this, PR_FALSE);
    739935  return GetFileSize(aFileSizeOfLink);
     
    768964NS_IMETHODIMP nsLocalFile::GetNativePath(nsACString& aNativePath)
    769965{
    770   if (!mBaseRef)
    771     return NS_ERROR_NOT_INITIALIZED;
     966  // Check we are correctly initialized.
     967  CHECK_mBaseRef();
     968
    772969  nsresult rv = NS_ERROR_FAILURE;
    773970  CFStringRef pathStrRef = ::CFURLCopyFileSystemPath(mBaseRef, kCFURLPOSIXPathStyle);
     
    782979NS_IMETHODIMP nsLocalFile::Exists(PRBool *_retval)
    783980{
     981  // Check we are correctly initialized.
     982  CHECK_mBaseRef();
     983
    784984  NS_ENSURE_ARG_POINTER(_retval);
    785985  *_retval = PR_FALSE;
    786  
     986
    787987  FSRef fsRef;
    788988  if (NS_SUCCEEDED(GetFSRefInternal(fsRef, PR_TRUE))) {
    789989    *_retval = PR_TRUE;
    790990  }
    791  
     991
    792992  return NS_OK;
    793993}
     
    796996NS_IMETHODIMP nsLocalFile::IsWritable(PRBool *_retval)
    797997{
     998    // Check we are correctly initialized.
     999    CHECK_mBaseRef();
     1000
    7981001    NS_ENSURE_ARG_POINTER(_retval);
    7991002    *_retval = PR_FALSE;
    800    
     1003
    8011004    FSRef fsRef;
    8021005    nsresult rv = GetFSRefInternal(fsRef);
    8031006    if (NS_FAILED(rv))
    8041007      return rv;
    805     if (::FSCheckLock(&fsRef) == noErr) {     
     1008    if (::FSCheckLock(&fsRef) == noErr) {
    8061009      PRUint32 permissions;
    8071010      rv = GetPermissions(&permissions);
     
    8161019NS_IMETHODIMP nsLocalFile::IsReadable(PRBool *_retval)
    8171020{
     1021    // Check we are correctly initialized.
     1022    CHECK_mBaseRef();
     1023
    8181024    NS_ENSURE_ARG_POINTER(_retval);
    8191025    *_retval = PR_FALSE;
    820    
     1026
    8211027    PRUint32 permissions;
    8221028    nsresult rv = GetPermissions(&permissions);
     
    8301036NS_IMETHODIMP nsLocalFile::IsExecutable(PRBool *_retval)
    8311037{
     1038  // Check we are correctly initialized.
     1039  CHECK_mBaseRef();
     1040
    8321041  NS_ENSURE_ARG_POINTER(_retval);
    8331042  *_retval = PR_FALSE;
    834  
     1043
    8351044  FSRef fsRef;
    8361045  nsresult rv = GetFSRefInternal(fsRef);
    8371046  if (NS_FAILED(rv))
    8381047    return rv;
    839    
     1048
    8401049  LSRequestedInfo theInfoRequest = kLSRequestAllInfo;
    8411050  LSItemInfoRecord theInfo;
     
    8521061  NS_ENSURE_ARG_POINTER(_retval);
    8531062  *_retval = PR_FALSE;
    854  
     1063
    8551064  FSRef fsRef;
    8561065  nsresult rv = GetFSRefInternal(fsRef);
    8571066  if (NS_FAILED(rv))
    8581067    return rv;
    859  
     1068
    8601069  FSCatalogInfo catalogInfo;
    861   HFSUniStr255 leafName; 
    862   OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags, &catalogInfo,
     1070  HFSUniStr255 leafName;
     1071  OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoFinderInfo, &catalogInfo,
    8631072                                &leafName, nsnull, nsnull);
    8641073  if (err != noErr)
    8651074    return MacErrorMapper(err);
    866      
     1075
    8671076  FileInfo *fInfoPtr = (FileInfo *)(catalogInfo.finderInfo); // Finder flags are in the same place whether we use FileInfo or FolderInfo
    8681077  if ((fInfoPtr->finderFlags & kIsInvisible) != 0) {
     
    8821091  NS_ENSURE_ARG_POINTER(_retval);
    8831092  *_retval = PR_FALSE;
    884  
     1093
    8851094  FSRef fsRef;
    8861095  nsresult rv = GetFSRefInternal(fsRef, PR_FALSE);
    8871096  if (NS_FAILED(rv))
    8881097    return rv;
    889    
     1098
    8901099  FSCatalogInfo catalogInfo;
    8911100  OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags, &catalogInfo,
     
    9021111  NS_ENSURE_ARG_POINTER(_retval);
    9031112  *_retval = PR_FALSE;
    904  
     1113
    9051114  FSRef fsRef;
    9061115  nsresult rv = GetFSRefInternal(fsRef, PR_FALSE);
    9071116  if (NS_FAILED(rv))
    9081117    return rv;
    909    
     1118
    9101119  FSCatalogInfo catalogInfo;
    9111120  OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNodeFlags, &catalogInfo,
     
    9201129NS_IMETHODIMP nsLocalFile::IsSymlink(PRBool *_retval)
    9211130{
     1131  // Check we are correctly initialized.
     1132  CHECK_mBaseRef();
     1133
    9221134  NS_ENSURE_ARG(_retval);
    9231135  *_retval = PR_FALSE;
    924   if (!mBaseRef)
    925     return NS_ERROR_NOT_INITIALIZED;
    926  
     1136
     1137  // Check we are correctly initialized.
     1138  CHECK_mBaseRef();
     1139
    9271140  FSRef fsRef;
    9281141  if (::CFURLGetFSRef(mBaseRef, &fsRef)) {
     
    9501163
    9511164    NS_ADDREF(*_retval);
    952    
     1165
    9531166    return NS_OK;
    9541167}
     
    9571170NS_IMETHODIMP nsLocalFile::Equals(nsIFile *inFile, PRBool *_retval)
    9581171{
     1172    return EqualsInternal(inFile, PR_TRUE, _retval);
     1173}
     1174
     1175nsresult
     1176nsLocalFile::EqualsInternal(nsISupports* inFile, PRBool aUpdateCache,
     1177                            PRBool *_retval)
     1178{
    9591179  NS_ENSURE_ARG_POINTER(_retval);
    9601180  *_retval = PR_FALSE;
    961  
     1181
    9621182  nsCOMPtr<nsILocalFileMac> inMacFile(do_QueryInterface(inFile));
    9631183  if (!inFile)
    9641184    return NS_OK;
    965    
     1185
     1186  nsLocalFile* inLF =
     1187      NS_STATIC_CAST(nsLocalFile*, (nsILocalFileMac*) inMacFile);
     1188
    9661189  // If both exist, compare FSRefs
    9671190  FSRef thisFSRef, inFSRef;
    968   nsresult rv1 = GetFSRef(&thisFSRef);
    969   nsresult rv2 = inMacFile->GetFSRef(&inFSRef);
     1191  nsresult rv1 = GetFSRefInternal(thisFSRef, aUpdateCache);
     1192  nsresult rv2 = inLF->GetFSRefInternal(inFSRef, aUpdateCache);
    9701193  if (NS_SUCCEEDED(rv1) && NS_SUCCEEDED(rv2)) {
    9711194    *_retval = (thisFSRef == inFSRef);
    9721195    return NS_OK;
    9731196  }
    974   // If one exists and the other doesn't, not equal 
     1197  // If one exists and the other doesn't, not equal
    9751198  if (rv1 != rv2)
    9761199    return NS_OK;
    977    
     1200
    9781201  // Arg, we have to get their paths and compare
    9791202  nsCAutoString thisPath, inPath;
     
    9831206    return NS_ERROR_FAILURE;
    9841207  *_retval = thisPath.Equals(inPath);
    985  
     1208
    9861209  return NS_OK;
    9871210}
     
    9901213NS_IMETHODIMP nsLocalFile::Contains(nsIFile *inFile, PRBool recur, PRBool *_retval)
    9911214{
     1215  // Check we are correctly initialized.
     1216  CHECK_mBaseRef();
     1217
    9921218  NS_ENSURE_ARG_POINTER(_retval);
    9931219  *_retval = PR_FALSE;
     
    10091235    if (inPath[thisPathLen] == kPathSepChar)
    10101236      *_retval = PR_TRUE;
    1011   } 
     1237  }
    10121238  return NS_OK;
    10131239}
     
    10181244  NS_ENSURE_ARG_POINTER(aParent);
    10191245  *aParent = nsnull;
    1020   if (!mBaseRef)
    1021     return NS_ERROR_NOT_INITIALIZED;
    1022  
     1246
     1247  // Check we are correctly initialized.
     1248  CHECK_mBaseRef();
     1249
    10231250  nsLocalFile *newFile = nsnull;
    10241251
     
    10391266    }
    10401267    ::CFRelease(parentURLRef);
    1041   } 
     1268  }
    10421269  return rv;
    10431270}
     
    10521279  PRBool isDir;
    10531280  rv = IsDirectory(&isDir);
    1054   if (NS_FAILED(rv)) 
     1281  if (NS_FAILED(rv))
    10551282    return rv;
    10561283  if (!isDir)
     
    10671294  }
    10681295  *aDirectoryEntries = dirEnum;
    1069  
     1296
    10701297  return NS_OK;
    10711298}
     
    10811308NS_IMETHODIMP nsLocalFile::InitWithPath(const nsAString& filePath)
    10821309{
    1083   return InitWithNativePath(NS_ConvertUCS2toUTF8(filePath));
     1310  return InitWithNativePath(NS_ConvertUTF16toUTF8(filePath));
    10841311}
    10851312
     
    10871314NS_IMETHODIMP nsLocalFile::InitWithNativePath(const nsACString& filePath)
    10881315{
    1089   if (filePath.IsEmpty() || filePath.First() != '/')
     1316  nsCAutoString fixedPath;
     1317  if (Substring(filePath, 0, 2).EqualsLiteral("~/")) {
     1318    nsCOMPtr<nsIFile> homeDir;
     1319    nsCAutoString homePath;
     1320    nsresult rv = NS_GetSpecialDirectory(NS_OS_HOME_DIR,
     1321                                        getter_AddRefs(homeDir));
     1322    NS_ENSURE_SUCCESS(rv, rv);
     1323    rv = homeDir->GetNativePath(homePath);
     1324    NS_ENSURE_SUCCESS(rv, rv);
     1325
     1326    fixedPath = homePath + Substring(filePath, 1, filePath.Length() - 1);
     1327  }
     1328  else if (filePath.IsEmpty() || filePath.First() != '/')
    10901329    return NS_ERROR_FILE_UNRECOGNIZED_PATH;
    1091   // On 10.2, huge paths crash CFURLGetFSRef()
    1092   if (filePath.Length() > PATH_MAX)
    1093     return NS_ERROR_FILE_NAME_TOO_LONG;
    1094   // And, a path with consecutive '/'s which are not between
    1095   // nodes also crashes CFURLGetFSRef(). Consecutive '/'s which
     1330  else
     1331    fixedPath.Assign(filePath);
     1332
     1333  // A path with consecutive '/'s which are not between
     1334  // nodes crashes CFURLGetFSRef(). Consecutive '/'s which
    10961335  // are between actual nodes are OK. So, convert consecutive
    10971336  // '/'s to a single one.
    1098   nsCAutoString fixedPath;
    1099   fixedPath.Assign(filePath);
    11001337  fixedPath.ReplaceSubstring("//", "/");
     1338
     1339  // On 10.2, huge paths also crash CFURLGetFSRef()
     1340  if (fixedPath.Length() > PATH_MAX)
     1341    return NS_ERROR_FILE_NAME_TOO_LONG;
    11011342
    11021343  CFStringRef pathAsCFString;
     
    11131354  SetBaseRef(pathAsCFURL);
    11141355  ::CFRelease(pathAsCFURL);
     1356  ::CFRelease(pathAsCFString);
    11151357  return NS_OK;
    11161358}
     
    11201362{
    11211363  NS_ENSURE_ARG(aFile);
    1122  
     1364
    11231365  nsCOMPtr<nsILocalFileMac> aFileMac(do_QueryInterface(aFile));
    11241366  if (!aFileMac)
     
    11371379{
    11381380  NS_ENSURE_ARG_POINTER(aFollowLinks);
    1139  
     1381
    11401382  *aFollowLinks = mFollowLinks;
    11411383  return NS_OK;
     
    11601402  if (NS_FAILED(rv))
    11611403    return rv;
    1162    
     1404
    11631405  *_retval = PR_Open(path.get(), flags, mode);
    11641406  if (! *_retval)
     
    11771419  if (NS_FAILED(rv))
    11781420    return rv;
    1179    
     1421
    11801422  *_retval = fopen(path.get(), mode);
    11811423  if (! *_retval)
     
    11881430NS_IMETHODIMP nsLocalFile::Load(PRLibrary **_retval)
    11891431{
     1432  // Check we are correctly initialized.
     1433  CHECK_mBaseRef();
     1434
    11901435  NS_ENSURE_ARG_POINTER(_retval);
    11911436
     
    11971442    return rv;
    11981443
     1444#ifdef NS_BUILD_REFCNT_LOGGING
     1445  nsTraceRefcntImpl::SetActivityIsLegal(PR_FALSE);
     1446#endif
     1447
    11991448  *_retval = PR_LoadLibrary(path.get());
     1449
     1450#ifdef NS_BUILD_REFCNT_LOGGING
     1451  nsTraceRefcntImpl::SetActivityIsLegal(PR_TRUE);
     1452#endif
    12001453
    12011454  NS_TIMELINE_STOP_TIMER("PR_LoadLibrary");
     
    12041457  if (!*_retval)
    12051458    return NS_ERROR_FAILURE;
    1206  
     1459
    12071460  return NS_OK;
    12081461}
     
    12111464NS_IMETHODIMP nsLocalFile::GetDiskSpaceAvailable(PRInt64 *aDiskSpaceAvailable)
    12121465{
     1466  // Check we are correctly initialized.
     1467  CHECK_mBaseRef();
     1468
    12131469  NS_ENSURE_ARG_POINTER(aDiskSpaceAvailable);
    1214  
     1470
    12151471  FSRef fsRef;
    12161472  nsresult rv = GetFSRefInternal(fsRef);
    12171473  if (NS_FAILED(rv))
    12181474    return rv;
    1219    
     1475
    12201476  OSErr err;
    12211477  FSCatalogInfo catalogInfo;
     
    12241480  if (err != noErr)
    12251481    return MacErrorMapper(err);
    1226  
    1227   FSVolumeInfo volumeInfo; 
     1482
     1483  FSVolumeInfo volumeInfo;
    12281484  err = ::FSGetVolumeInfo(catalogInfo.volume, 0, nsnull, kFSVolInfoSizes,
    12291485                          &volumeInfo, nsnull, nsnull);
    12301486  if (err != noErr)
    12311487    return MacErrorMapper(err);
    1232    
     1488
    12331489  *aDiskSpaceAvailable = volumeInfo.freeBytes;
    12341490  return NS_OK;
     
    12381494NS_IMETHODIMP nsLocalFile::AppendRelativePath(const nsAString& relativeFilePath)
    12391495{
    1240   return AppendRelativeNativePath(NS_ConvertUCS2toUTF8(relativeFilePath));
     1496  return AppendRelativeNativePath(NS_ConvertUTF16toUTF8(relativeFilePath));
    12411497}
    12421498
    12431499/* [noscript] void appendRelativeNativePath (in ACString relativeFilePath); */
    12441500NS_IMETHODIMP nsLocalFile::AppendRelativeNativePath(const nsACString& relativeFilePath)
    1245 { 
     1501{
    12461502  if (relativeFilePath.IsEmpty())
    12471503    return NS_OK;
    1248   // No leading '/' 
     1504  // No leading '/'
    12491505  if (relativeFilePath.First() == '/')
    12501506    return NS_ERROR_FILE_UNRECOGNIZED_PATH;
     
    12551511  relativeFilePath.EndReading(pathEnd);
    12561512  nsACString::const_iterator nodeEnd(nodeBegin);
    1257  
     1513
    12581514  while (nodeEnd != pathEnd) {
    12591515    FindCharInReadable(kPathSepChar, nodeEnd, pathEnd);
     
    12751531  if (NS_FAILED(rv))
    12761532    return rv;
    1277    
     1533
    12781534  AliasHandle aliasH;
    12791535  OSErr err = ::FSNewAlias(nsnull, &fsRef, &aliasH);
    12801536  if (err != noErr)
    12811537    return MacErrorMapper(err);
    1282    
     1538
    12831539   PRUint32 bytes = ::GetHandleSize((Handle) aliasH);
    12841540   ::HLock((Handle) aliasH);
     
    12871543   ::DisposeHandle((Handle) aliasH);
    12881544   NS_ENSURE_TRUE(buf, NS_ERROR_OUT_OF_MEMORY);
    1289    
     1545
    12901546   aPersistentDescriptor = buf;
    12911547   PR_Free(buf);
     
    12991555    return NS_ERROR_INVALID_ARG;
    13001556
     1557  // Support pathnames as user-supplied descriptors if they begin with '/'
     1558  // or '~'.  These characters do not collide with the base64 set used for
     1559  // encoding alias records.
     1560  char first = aPersistentDescriptor.First();
     1561  if (first == '/' || first == '~')
     1562    return InitWithNativePath(aPersistentDescriptor);
     1563
    13011564  nsresult rv = NS_OK;
    1302  
    1303   PRUint32 dataSize = aPersistentDescriptor.Length();   
     1565
     1566  PRUint32 dataSize = aPersistentDescriptor.Length();
    13041567  char* decodedData = PL_Base64Decode(PromiseFlatCString(aPersistentDescriptor).get(), dataSize, nsnull);
    13051568  if (!decodedData) {
     
    13071570    return NS_ERROR_FAILURE;
    13081571  }
    1309  
     1572
    13101573  // Cast to an alias record and resolve.
    1311   PRInt32               aliasSize = (dataSize * 3) / 4;
    1312   AliasRecord   aliasHeader = *(AliasPtr)decodedData;
    1313   if (aliasHeader.aliasSize > aliasSize) {              // be paranoid about having too few data
     1574  AliasRecord aliasHeader = *(AliasPtr)decodedData;
     1575  PRInt32 aliasSize = GetAliasSizeFromRecord(aliasHeader);
     1576  if (aliasSize > (dataSize * 3) / 4) { // be paranoid about having too few data
    13141577    PR_Free(decodedData);
    13151578    return NS_ERROR_FAILURE;
    13161579  }
    1317  
    1318   aliasSize = aliasHeader.aliasSize;
    1319  
     1580
    13201581  // Move the now-decoded data into the Handle.
    13211582  // The size of the decoded data is 3/4 the size of the encoded data. See plbase64.h
     
    13301591  FSRef resolvedFSRef;
    13311592  OSErr err = ::FSResolveAlias(nsnull, (AliasHandle)newHandle, &resolvedFSRef, &changed);
    1332    
     1593
    13331594  rv = MacErrorMapper(err);
    13341595  DisposeHandle(newHandle);
    13351596  if (NS_FAILED(rv))
    13361597    return rv;
    1337  
     1598
    13381599  return InitWithFSRef(&resolvedFSRef);
    13391600}
     
    13481609  OSErr             err;
    13491610  ProcessSerialNumber   process;
    1350    
     1611
    13511612  nsresult rv = GetFSRefInternal(fsRefToReveal);
    13521613  if (NS_FAILED(rv))
    13531614    return rv;
    1354  
     1615
    13551616  err = ::FindRunningAppBySignature ('MACS', process);
    1356   if (err == noErr) { 
     1617  if (err == noErr) {
    13571618    err = ::AECreateDesc(typeProcessSerialNumber, (Ptr)&process, sizeof(process), &myAddressDesc);
    13581619    if (err == noErr) {
    13591620      // Create the FinderEvent
    13601621      err = ::AECreateAppleEvent(kAEMiscStandards, kAEMakeObjectsVisible, &myAddressDesc,
    1361                         kAutoGenerateReturnID, kAnyTransactionID, &aeEvent);   
     1622                        kAutoGenerateReturnID, kAnyTransactionID, &aeEvent);
    13621623      if (err == noErr) {
    13631624        // Create the file list
     
    13811642    }
    13821643  }
    1383    
     1644
    13841645  return NS_OK;
    13851646}
     
    14081669{
    14091670  NS_ENSURE_ARG(aCFURL);
    1410  
     1671
    14111672  SetBaseRef(aCFURL);
    14121673  return NS_OK;
     
    14181679  NS_ENSURE_ARG(aFSRef);
    14191680  nsresult rv = NS_ERROR_FAILURE;
    1420  
     1681
    14211682  CFURLRef newURLRef = ::CFURLCreateFromFSRef(kCFAllocatorDefault, aFSRef);
    14221683  if (newURLRef) {
     
    14321693{
    14331694  NS_ENSURE_ARG(aFileSpec);
    1434  
     1695
    14351696  FSRef fsRef;
    14361697  OSErr err = ::FSpMakeFSRef(aFileSpec, &fsRef);
     
    14401701    CInfoPBRec  pBlock;
    14411702    FSSpec parentDirSpec;
    1442    
     1703
    14431704    memset(&pBlock, 0, sizeof(CInfoPBRec));
    14441705    parentDirSpec.name[0] = 0;
     
    14501711    if (err != noErr)
    14511712      return MacErrorMapper(err);
    1452    
     1713
    14531714    parentDirSpec.vRefNum = aFileSpec->vRefNum;
    14541715    parentDirSpec.parID = pBlock.dirInfo.ioDrParID;
     
    14631724    if (NS_FAILED(rv))
    14641725      return rv;
    1465     return Append(nsDependentString(unicodeName.unicode, unicodeName.length)); 
     1726    return Append(nsDependentString(unicodeName.unicode, unicodeName.length));
    14661727  }
    14671728  return MacErrorMapper(err);
     
    15001761{
    15011762  NS_ENSURE_ARG_POINTER(_retval);
    1502   if (!mBaseRef)
    1503     return NS_ERROR_NOT_INITIALIZED;
    1504  
     1763
     1764  // Check we are correctly initialized.
     1765  CHECK_mBaseRef();
     1766
    15051767  OSErr err;
    15061768  FSRef fsRef;
     
    15101772    err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoNone,
    15111773              nsnull, nsnull, _retval, nsnull);
    1512     return MacErrorMapper(err); 
     1774    return MacErrorMapper(err);
    15131775  }
    15141776  else if (rv == NS_ERROR_FILE_NOT_FOUND) {
     
    15321794                          catalogInfo.nodeID == fsRtDirID,
    15331795                          hfsName)) == noErr)
    1534             err = ::FSMakeFSSpec(catalogInfo.volume, catalogInfo.nodeID, hfsName, _retval);       
     1796            err = ::FSMakeFSSpec(catalogInfo.volume, catalogInfo.nodeID, hfsName, _retval);
    15351797        }
    15361798      }
     
    15461808{
    15471809  NS_ENSURE_ARG_POINTER(aFileSizeWithResFork);
    1548  
     1810
    15491811  FSRef fsRef;
    15501812  nsresult rv = GetFSRefInternal(fsRef);
    15511813  if (NS_FAILED(rv))
    15521814    return rv;
    1553      
     1815
    15541816  FSCatalogInfo catalogInfo;
    15551817  OSErr err = ::FSGetCatalogInfo(&fsRef, kFSCatInfoDataSizes + kFSCatInfoRsrcSizes,
     
    15571819  if (err != noErr)
    15581820    return MacErrorMapper(err);
    1559    
     1821
    15601822  *aFileSizeWithResFork = catalogInfo.dataLogicalSize + catalogInfo.rsrcLogicalSize;
    15611823  return NS_OK;
     
    15661828{
    15671829  NS_ENSURE_ARG_POINTER(aFileType);
    1568  
     1830
    15691831  FSRef fsRef;
    15701832  nsresult rv = GetFSRefInternal(fsRef);
    15711833  if (NS_FAILED(rv))
    15721834    return rv;
    1573  
    1574   FinderInfo fInfo; 
     1835
     1836  FinderInfo fInfo;
    15751837  OSErr err = ::FSGetFinderInfo(&fsRef, &fInfo, nsnull, nsnull);
    15761838  if (err != noErr)
     
    15861848  if (NS_FAILED(rv))
    15871849    return rv;
    1588    
     1850
    15891851  OSErr err = ::FSChangeCreatorType(&fsRef, 0, aFileType);
    15901852  return MacErrorMapper(err);
     
    15951857{
    15961858  NS_ENSURE_ARG_POINTER(aFileCreator);
    1597  
     1859
    15981860  FSRef fsRef;
    15991861  nsresult rv = GetFSRefInternal(fsRef);
    16001862  if (NS_FAILED(rv))
    16011863    return rv;
    1602  
    1603   FinderInfo fInfo; 
     1864
     1865  FinderInfo fInfo;
    16041866  OSErr err = ::FSGetFinderInfo(&fsRef, &fInfo, nsnull, nsnull);
    16051867  if (err != noErr)
     
    16151877  if (NS_FAILED(rv))
    16161878    return rv;
    1617    
     1879
    16181880  OSErr err = ::FSChangeCreatorType(&fsRef, aFileCreator, 0);
    16191881  return MacErrorMapper(err);
     
    16571919      return rv;
    16581920  }
    1659  
     1921
    16601922  LSLaunchFlags       theLaunchFlags = kLSLaunchDefaults;
    16611923  LSLaunchFSRefSpec   thelaunchSpec;
     
    17011963    if (!isExecutable)
    17021964      return NS_ERROR_FILE_EXECUTION_FAILED;
    1703    
     1965
    17041966    rv = appFileMac->GetFSRef(&appFSRef);
    17051967    if (NS_FAILED(rv))
     
    17161978      return MacErrorMapper(err);
    17171979  }
    1718  
     1980
    17191981  LSLaunchFlags       theLaunchFlags = kLSLaunchDefaults;
    17201982  LSLaunchFSRefSpec   thelaunchSpec;
     
    17412003  NS_ENSURE_ARG(_retval);
    17422004  *_retval = PR_FALSE;
    1743  
     2005
    17442006  FSRef fsRef;
    17452007  nsresult rv = GetFSRefInternal(fsRef);
     
    17732035}
    17742036
     2037NS_IMETHODIMP
     2038nsLocalFile::GetBundleDisplayName(nsAString& outBundleName)
     2039{
     2040  PRBool isPackage = PR_FALSE;
     2041  nsresult rv = IsPackage(&isPackage);
     2042  if (NS_FAILED(rv) || !isPackage)
     2043    return NS_ERROR_FAILURE;
     2044
     2045  nsAutoString name;
     2046  rv = GetLeafName(name);
     2047  if (NS_FAILED(rv))
     2048    return rv;
     2049
     2050  PRInt32 length = name.Length();
     2051  if (Substring(name, length - 4, length).EqualsLiteral(".app")) {
     2052    // 4 characters in ".app"
     2053    outBundleName = Substring(name, 0, length - 4);
     2054  }
     2055  else
     2056    outBundleName = name;
     2057
     2058  return NS_OK;
     2059}
     2060
     2061NS_IMETHODIMP
     2062nsLocalFile::GetBundleIdentifier(nsACString& outBundleIdentifier)
     2063{
     2064  nsresult rv = NS_ERROR_FAILURE;
     2065
     2066  CFURLRef urlRef;
     2067  if (NS_SUCCEEDED(GetCFURL(&urlRef))) {
     2068    CFBundleRef bundle = ::CFBundleCreate(NULL, urlRef);
     2069    if (bundle) {
     2070      CFStringRef bundleIdentifier = ::CFBundleGetIdentifier(bundle);
     2071      if (bundleIdentifier)
     2072        rv = CFStringReftoUTF8(bundleIdentifier, outBundleIdentifier);
     2073
     2074      ::CFRelease(bundle);
     2075    }
     2076    ::CFRelease(urlRef);
     2077  }
     2078
     2079  return rv;
     2080}
     2081
    17752082
    17762083//*****************************************************************************
     
    17832090{
    17842091  NS_ENSURE_ARG(aCFURLRef);
    1785  
     2092
    17862093  ::CFRetain(aCFURLRef);
    17872094  if (mBaseRef)
     
    17892096  mBaseRef = aCFURLRef;
    17902097
    1791   mFollowLinksDirty = PR_TRUE; 
     2098  mFollowLinksDirty = PR_TRUE;
    17922099  UpdateTargetRef();
    17932100  mCachedFSRefValid = PR_FALSE;
     
    17972104nsresult nsLocalFile::UpdateTargetRef()
    17982105{
    1799   if (!mBaseRef)
    1800     return NS_ERROR_NOT_INITIALIZED;
    1801  
     2106  // Check we are correctly initialized.
     2107  CHECK_mBaseRef();
     2108
    18022109  if (mFollowLinksDirty) {
    18032110    if (mTargetRef) {
     
    18122119      if (::CFURLGetFSRef(mBaseRef, &fsRef)) {
    18132120        Boolean targetIsFolder, wasAliased;
    1814         if (FSResolveAliasFile(&fsRef, true /*resolveAliasChains*/, 
     2121        if (FSResolveAliasFile(&fsRef, true /*resolveAliasChains*/,
    18152122            &targetIsFolder, &wasAliased) == noErr && wasAliased) {
    18162123          ::CFRelease(mTargetRef);
     
    18482155{
    18492156  nsresult rv = NS_ERROR_FAILURE;
    1850  
     2157
    18512158  CFURLRef whichURLRef = mFollowLinks ? mTargetRef : mBaseRef;
    18522159  NS_ENSURE_TRUE(whichURLRef, NS_ERROR_NULL_POINTER);
    1853    
     2160
    18542161  CFStringRef pathStrRef = ::CFURLCopyFileSystemPath(whichURLRef, kCFURLPOSIXPathStyle);
    18552162  if (pathStrRef) {
     
    18602167}
    18612168
    1862 nsresult nsLocalFile::MoveCopy(nsIFile* aParentDir, const nsAString& newName, PRBool isCopy, PRBool followLinks)
    1863 {
     2169nsresult nsLocalFile::CopyInternal(nsIFile* aParentDir,
     2170                                   const nsAString& newName,
     2171                                   PRBool followLinks)
     2172{
     2173  // Check we are correctly initialized.
     2174  CHECK_mBaseRef();
     2175
    18642176  StFollowLinksState srcFollowState(*this, followLinks);
    18652177
     
    18672179  OSErr err;
    18682180  FSRef srcFSRef, newFSRef;
    1869  
     2181
    18702182  rv = GetFSRefInternal(srcFSRef);
    18712183  if (NS_FAILED(rv))
    18722184    return rv;
    1873    
     2185
    18742186  nsCOMPtr<nsIFile> newParentDir = aParentDir;
    1875   CFURLRef newBaseURLRef;
    18762187
    18772188  if (!newParentDir) {
     
    18802191    rv = GetParent(getter_AddRefs(newParentDir));
    18812192    if (NS_FAILED(rv))
    1882       return rv;   
    1883   }
    1884  
     2193      return rv;
     2194  }
     2195
    18852196  // If newParentDir does not exist, create it
    18862197  PRBool exists;
     
    18892200    return rv;
    18902201  if (!exists) {
    1891     rv = newParentDir->Create(nsIFile::DIRECTORY_TYPE, 0666);
     2202    rv = newParentDir->Create(nsIFile::DIRECTORY_TYPE, 0777);
    18922203    if (NS_FAILED(rv))
    18932204      return rv;
    18942205  }
    1895    
     2206
    18962207  FSRef destFSRef;
    18972208  nsCOMPtr<nsILocalFileMac> newParentDirMac(do_QueryInterface(newParentDir));
     
    19012212  if (NS_FAILED(rv))
    19022213    return rv;
    1903    
    1904   if (isCopy) {
    1905     err = ::FSCopyObject(&srcFSRef, &destFSRef,
    1906                          newName.Length(), newName.Length() ? PromiseFlatString(newName).get() : nsnull,
    1907                          0, kFSCatInfoNone, false, false, nsnull, nsnull, &newFSRef);
    1908     // don't update ourselves on a copy
    1909   }
    1910   else {
    1911     // According to the API: "If 'this' is a file, and the destination file already
    1912     // exists, moveTo will replace the old file."
    1913     FSCatalogInfo catalogInfo;
    1914     HFSUniStr255 leafName;
    1915     err = ::FSGetCatalogInfo(&srcFSRef, kFSCatInfoNodeFlags, &catalogInfo,
    1916                              newName.IsEmpty() ? &leafName : nsnull, nsnull, nsnull);
    1917     if (err == noErr) {     
    1918       if (!(catalogInfo.nodeFlags & kFSNodeIsDirectoryMask)) {
    1919         FSRef oldFileRef;
    1920         if (newName.IsEmpty())
    1921           err = ::FSMakeFSRefUnicode(&destFSRef, leafName.length, leafName.unicode,
    1922                     kTextEncodingUnknown, &oldFileRef);
    1923         else
    1924           err = ::FSMakeFSRefUnicode(&destFSRef, newName.Length(), PromiseFlatString(newName).get(),
    1925                     kTextEncodingUnknown, &oldFileRef);
    1926         if (err == noErr)
    1927           ::FSDeleteObject(&oldFileRef);
    1928       }
    1929     }
    1930     // First, try the quick way which works only within the same volume
    1931     err = ::FSMoveRenameObjectUnicode(&srcFSRef, &destFSRef,
    1932               newName.Length(), newName.Length() ? PromiseFlatString(newName).get() : nsnull,
    1933               kTextEncodingUnknown, &newFSRef);
    1934              
    1935     if (err == diffVolErr) {
    1936       // If on different volumes, resort to copy & delete
    1937       err = ::FSCopyObject(&srcFSRef, &destFSRef,
    1938                            newName.Length(), newName.Length() ? PromiseFlatString(newName).get() : nsnull,
    1939                            0, kFSCatInfoNone, false, false, nsnull, nsnull, &newFSRef);
    1940       ::FSDeleteObjects(&srcFSRef);
    1941     }
    1942     if (err == noErr) {
    1943       newBaseURLRef = ::CFURLCreateFromFSRef(kCFAllocatorDefault, &newFSRef);
    1944       if (!newBaseURLRef)
    1945         return NS_ERROR_FAILURE;
    1946       SetBaseRef(newBaseURLRef);
    1947       ::CFRelease(newBaseURLRef);
    1948     }
    1949   }
     2214
     2215  err =
     2216   ::FSCopyObject(&srcFSRef, &destFSRef, newName.Length(),
     2217                  newName.Length() ? PromiseFlatString(newName).get() : NULL,
     2218                  0, kFSCatInfoNone, false, false, NULL, NULL, &newFSRef);
     2219
    19502220  return MacErrorMapper(err);
    19512221}
    19522222
    1953 const PRInt64 kMilisecsPerSec = 1000LL;
     2223const PRInt64 kMillisecsPerSec = 1000LL;
    19542224const PRInt64 kUTCDateTimeFractionDivisor = 65535LL;
    19552225
     
    19572227{
    19582228  // Start with seconds since Jan. 1, 1904 GMT
    1959   PRInt64 result = ((PRInt64)utcTime.highSeconds << 32) + (PRInt64)utcTime.lowSeconds; 
     2229  PRInt64 result = ((PRInt64)utcTime.highSeconds << 32) + (PRInt64)utcTime.lowSeconds;
    19602230  // Subtract to convert to NSPR epoch of 1970
    19612231  result -= kJanuaryFirst1970Seconds;
    1962   // Convert to milisecs
    1963   result *= kMilisecsPerSec;
    1964   // Convert the fraction to milisecs and add it
    1965   result += ((PRInt64)utcTime.fraction * kMilisecsPerSec) / kUTCDateTimeFractionDivisor;
     2232  // Convert to millisecs
     2233  result *= kMillisecsPerSec;
     2234  // Convert the fraction to millisecs and add it
     2235  result += ((PRInt64)utcTime.fraction * kMillisecsPerSec) / kUTCDateTimeFractionDivisor;
    19662236
    19672237  return result;
     
    19702240void nsLocalFile::NSPRtoHFSPlusTime(PRInt64 nsprTime, UTCDateTime& utcTime)
    19712241{
    1972   PRInt64 fraction = nsprTime % kMilisecsPerSec;
    1973   PRInt64 seconds = (nsprTime / kMilisecsPerSec) + kJanuaryFirst1970Seconds;
     2242  PRInt64 fraction = nsprTime % kMillisecsPerSec;
     2243  PRInt64 seconds = (nsprTime / kMillisecsPerSec) + kJanuaryFirst1970Seconds;
    19742244  utcTime.highSeconds = (UInt16)((PRUint64)seconds >> 32);
    19752245  utcTime.lowSeconds = (UInt32)seconds;
    1976   utcTime.fraction = (UInt16)((fraction * kUTCDateTimeFractionDivisor) / kMilisecsPerSec);
     2246  utcTime.fraction = (UInt16)((fraction * kUTCDateTimeFractionDivisor) / kMillisecsPerSec);
    19772247}
    19782248
     
    19842254                              kCFStringEncodingUTF8, 0, PR_FALSE, nsnull, 0, &usedBufLen);
    19852255  if (charsConverted == inStrLen) {
     2256#if 0 /* bird: too new? */
     2257    aOutStr.SetLength(usedBufLen);
     2258    if (aOutStr.Length() != usedBufLen)
     2259      return NS_ERROR_OUT_OF_MEMORY;
     2260    UInt8 *buffer = (UInt8*) aOutStr.BeginWriting();
     2261
     2262    ::CFStringGetBytes(aInStrRef, CFRangeMake(0, inStrLen),
     2263                       kCFStringEncodingUTF8, 0, false, buffer, usedBufLen, &usedBufLen);
     2264    rv = NS_OK;
     2265#else
    19862266    nsAutoBuffer<UInt8, FILENAME_BUFFER_SIZE> buffer;
    19872267    if (buffer.EnsureElemCapacity(usedBufLen + 1)) {
     
    19922272      rv = NS_OK;
    19932273    }
     2274#endif
    19942275  }
    19952276  return rv;
     2277}
     2278
     2279// nsIHashable
     2280
     2281NS_IMETHODIMP
     2282nsLocalFile::Equals(nsIHashable* aOther, PRBool *aResult)
     2283{
     2284    return EqualsInternal(aOther, PR_FALSE, aResult);
     2285}
     2286
     2287NS_IMETHODIMP
     2288nsLocalFile::GetHashCode(PRUint32 *aResult)
     2289{
     2290    CFStringRef pathStrRef = ::CFURLCopyFileSystemPath(mBaseRef, kCFURLPOSIXPathStyle);
     2291    nsCAutoString path;
     2292    CFStringReftoUTF8(pathStrRef, path);
     2293    *aResult = HashString(path);
     2294    return NS_OK;
    19962295}
    19972296
     
    20322331nsresult NS_NewNativeLocalFile(const nsACString& path, PRBool followLinks, nsILocalFile **result)
    20332332{
    2034     return NS_NewLocalFile(NS_ConvertUTF8toUCS2(path), followLinks, result);
     2333    return NS_NewLocalFile(NS_ConvertUTF8toUTF16(path), followLinks, result);
    20352334}
    20362335
     
    20532352}
    20542353
     2354nsresult NS_NewLocalFileWithFSRef(const FSRef* aFSRef, PRBool aFollowLinks, nsILocalFileMac** result)
     2355{
     2356    nsLocalFile* file = new nsLocalFile();
     2357    if (file == nsnull)
     2358        return NS_ERROR_OUT_OF_MEMORY;
     2359    NS_ADDREF(file);
     2360
     2361    file->SetFollowLinks(aFollowLinks);
     2362
     2363    nsresult rv = file->InitWithFSRef(aFSRef);
     2364    if (NS_FAILED(rv)) {
     2365        NS_RELEASE(file);
     2366        return rv;
     2367    }
     2368    *result = file;
     2369    return NS_OK;
     2370}
     2371
    20552372//*****************************************************************************
    20562373//  Static Functions
     
    20602377{
    20612378    nsresult outErr;
    2062    
     2379
    20632380    switch (inErr)
    20642381    {
     
    20742391            outErr = NS_ERROR_FILE_ALREADY_EXISTS;
    20752392            break;
    2076        
     2393
    20772394        case dskFulErr:
    20782395            outErr = NS_ERROR_FILE_DISK_FULL;
    20792396            break;
    2080        
     2397
    20812398        case fLckdErr:
    20822399            outErr = NS_ERROR_FILE_IS_LOCKED;
    20832400            break;
    2084        
     2401
    20852402        // Can't find good map for some
    20862403        case bdNamErr:
     
    20882405            break;
    20892406
    2090         default:   
     2407        default:
    20912408            outErr = NS_ERROR_FAILURE;
    20922409            break;
     
    20992416  ProcessInfoRec info;
    21002417  OSErr err = noErr;
    2101  
     2418
    21022419  outPsn.highLongOfPSN = 0;
    21032420  outPsn.lowLongOfPSN  = kNoProcess;
    2104  
     2421
    21052422  while (PR_TRUE)
    21062423  {
     
    21162433    if (err != noErr)
    21172434      return err;
    2118    
     2435
    21192436    if (info.processSignature == aAppSig)
    21202437      return noErr;
     
    21472464    if (!sUnicodeNormalizer) {  // OS X 10.2 or earlier
    21482465        CopyUTF8toUTF16(aSrc, aResult);
    2149         return; 
     2466        return;
    21502467    }
    21512468
     
    21592476    if (!inStr) {
    21602477        CopyUTF8toUTF16(aSrc, aResult);
    2161         return; 
    2162     }
    2163      
    2164     ::CFStringAppendCString(inStr, inFlatSrc.get(), kCFStringEncodingUTF8); 
     2478        return;
     2479    }
     2480
     2481    ::CFStringAppendCString(inStr, inFlatSrc.get(), kCFStringEncodingUTF8);
    21652482
    21662483    sUnicodeNormalizer(inStr, kCFStringNormalizationFormC);
     
    21692486    const UniChar* chars = CFStringGetCharactersPtr(inStr);
    21702487
    2171     if (chars) 
     2488    if (chars)
    21722489        aResult.Assign(chars, length);
    21732490    else {
  • trunk/src/libs/xpcom18a4/xpcom/io/nsLocalFileOSX.h

    r1 r589  
    4242#include "nsILocalFileMac.h"
    4343#include "nsString.h"
     44#include "nsIHashable.h"
    4445
    4546class nsDirEnumerator;
     
    5657//*****************************************************************************
    5758
    58 class NS_COM nsLocalFile : public nsILocalFileMac
     59class NS_COM nsLocalFile : public nsILocalFileMac,
     60                           public nsIHashable
    5961{
    6062    friend class nsDirEnumerator;
     
    7173    NS_DECL_NSILOCALFILE
    7274    NS_DECL_NSILOCALFILEMAC
     75    NS_DECL_NSIHASHABLE
    7376
    7477public:
     
    8891    nsresult            GetFSRefInternal(FSRef& aFSSpec, PRBool bForceUpdateCache = PR_TRUE);
    8992    nsresult            GetPathInternal(nsACString& path);  // Returns path WRT mFollowLinks
     93    nsresult            EqualsInternal(nsISupports* inFile,
     94                                       PRBool aUpdateCache, PRBool *_retval);
    9095
    91     nsresult            MoveCopy(nsIFile* newParentDir, const nsAString &newName, PRBool isCopy, PRBool followLinks);
     96    nsresult            CopyInternal(nsIFile* newParentDir,
     97                                     const nsAString& newName,
     98                                     PRBool followLinks);
    9299
    93100    static PRInt64      HFSPlustoNSPRTime(const UTCDateTime& utcTime);
  • trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_unixish_x86.cpp

    r1 r589  
    2121 *
    2222 * Contributor(s):
     23 *   Mark Mentovai <[email protected]>
    2324 *
    2425 * Alternatively, the contents of this file may be used under the terms of
     
    7980#ifdef __GNUC__            /* Gnu compiler. */
    8081  PRUint32 result;
    81   // Each param takes at most 2, 4-byte words
    82   // It doesn't matter if we push too many words, and calculating the exact
    83   // ammount takes time.
     82  /* Each param takes at most 2, 4-byte words
     83    It doesn't matter if we push too many words, and calculating the exact
     84     amount takes time. */
    8485  PRUint32 n = paramCount << 3;
    8586  void (*fn_copy) (unsigned int, nsXPTCVariant *, PRUint32 *) = invoke_copy_to_stack;
    86   int temp1, temp2, temp3;
    87  
     87  int temp1, temp2;
     88
     89  /* These are only significant when KEEP_STACK_16_BYTE_ALIGNED is
     90     defined.  Otherwise, they're just placeholders to keep the parameter
     91     indices the same for aligned and unaligned users in the inline asm
     92     block. */
     93  unsigned int saved_esp;
     94
    8895 __asm__ __volatile__(
     96#ifdef KEEP_STACK_16_BYTE_ALIGNED
     97    "movl  %%esp, %3\n\t"
     98#endif
    8999    "subl  %8, %%esp\n\t" /* make room for params */
     100#ifdef KEEP_STACK_16_BYTE_ALIGNED
     101    /* For the second CALL, there will be one parameter before the ones
     102       copied by invoke_copy_to_stack.  Make sure that the stack will be
     103       aligned for that CALL. */
     104    "subl  $4, %%esp\n\t"
     105    "andl  $0xfffffff0, %%esp\n\t"
     106    /* For the first CALL, there are three parameters.  Leave padding to
     107       ensure alignment. */
     108    "subl  $4, %%esp\n\t"
     109    /* The third parameter to invoke_copy_to_stack is the destination pointer.
     110       It needs to point into the parameter area prepared for the second CALL,
     111       leaving room for the |that| parameter.  This reuses |n|, which was
     112       the stack space to reserve, but that's OK because it's no longer needed
     113       if the stack is being kept aligned. */
     114    "leal  8(%%esp), %8\n\t"
     115    "pushl %8\n\t"
     116#else
    90117    "pushl %%esp\n\t"
     118#endif
    91119    "pushl %7\n\t"
    92120    "pushl %6\n\t"
    93     "call  *%0\n\t"       /* copy params */
     121    "call  *%9\n\t"       /* copy params */
     122#ifdef KEEP_STACK_16_BYTE_ALIGNED
     123    /* The stack is still aligned from the first CALL.  Keep it aligned for
     124       the next one by popping past the parameters from the first CALL and
     125       leaving space for the first (|that|) parameter for the second CALL. */
     126    "addl  $0x14, %%esp\n\t"
     127#else
    94128    "addl  $0xc, %%esp\n\t"
     129#endif
    95130    "movl  %4, %%ecx\n\t"
    96131#ifdef CFRONT_STYLE_THIS_ADJUST
     
    115150#endif
    116151    "call  *(%%edx)\n\t"    /* safe to not cleanup esp */
     152#ifdef KEEP_STACK_16_BYTE_ALIGNED
     153    "movl  %3, %%esp\n\t"
     154#else
    117155    "addl  $4, %%esp\n\t"
    118156    "addl  %8, %%esp"
     157#endif
    119158    : "=a" (result),        /* %0 */
    120159      "=c" (temp1),         /* %1 */
    121160      "=d" (temp2),         /* %2 */
    122       "=g" (temp3)          /* %3 */
     161#ifdef KEEP_STACK_16_BYTE_ALIGNED
     162      "=&g" (saved_esp)     /* %3 */
     163#else
     164      /* Don't waste a register, this isn't used if alignment is unimportant */
     165      "=m" (saved_esp)      /* %3 */
     166#endif
    123167    : "g" (that),           /* %4 */
    124168      "g" (methodIndex),    /* %5 */
    125169      "1" (paramCount),     /* %6 */
    126170      "2" (params),         /* %7 */
     171#ifdef KEEP_STACK_16_BYTE_ALIGNED
     172      /* Must be in a register, it's the target of an LEA instruction */
     173      "r" (n),              /* %8 */
     174#else
    127175      "g" (n),              /* %8 */
    128       "0" (fn_copy)         /* %3 */
     176#endif
     177      "0" (fn_copy)         /* %9 */
    129178    : "memory"
    130179    );
    131    
     180
    132181  return result;
    133182
     
    136185#endif /* __GNUC__ */
    137186
    138 }   
     187}
  • trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/src/md/unix/xptcstubs_unixish_x86.cpp

    r1 r589  
    4040#include "xptcprivate.h"
    4141#include "xptc_platforms_unixish_x86.h"
     42/*#include "xptiprivate.h"*/
    4243
    4344static nsresult
     
    104105
    105106#ifdef __GNUC__         /* Gnu Compiler. */
     107
     108#ifdef KEEP_STACK_16_BYTE_ALIGNED
     109/* Make sure the stack is 16-byte aligned.  Do that by aligning to 16 bytes and
     110 * then subtracting 4 so the three subsequent pushes result in a 16-byte aligned
     111 * stack. */
     112#define ALIGN_STACK_DECL \
     113  unsigned int saved_esp;
     114
     115#define ALIGN_STACK_SAVE \
     116  "movl %%esp, %3\n\t"
     117
     118#define ALIGN_STACK_ALIGN \
     119  "addl $0x4, %%esp\n\t" \
     120  "andl $0xfffffff0, %%esp\n\t" \
     121  "subl $0x4, %%esp\n\t"
     122
     123#define STACK_RESTORE \
     124  "movl %3, %%esp\n"
     125
     126#define ALIGN_STACK_REGS_IN \
     127  , "=r"(saved_esp) /* 3 */
     128
     129#define ALIGN_STACK_REGS_OUT \
     130  , "3"(saved_esp)
     131
     132#else
     133#define ALIGN_STACK_DECL
     134#define ALIGN_STACK_SAVE
     135#define ALIGN_STACK_ALIGN
     136#define STACK_RESTORE \
     137  "addl $12, %%esp\n"
     138#define ALIGN_STACK_REGS_IN
     139#define ALIGN_STACK_REGS_OUT
     140#endif
     141
    106142#define STUB_ENTRY(n) \
    107143nsresult nsXPTCStubBase::Stub##n() \
     
    110146  int temp0, temp1; \
    111147  register nsresult result; \
     148  ALIGN_STACK_DECL \
    112149  __asm__ __volatile__( \
     150    ALIGN_STACK_SAVE \
     151    ALIGN_STACK_ALIGN \
    113152    "leal   0x0c(%%ebp), %%ecx\n\t"    /* args */ \
    114153    "pushl  %%ecx\n\t" \
     
    117156    "pushl  %%ecx\n\t" \
    118157    "call   *%%edx\n\t"                /* PrepareAndDispatch */ \
    119     "addl   $12, %%esp" \
     158    STACK_RESTORE                      /* "addl $12, %%esp" or restore saved */ \
    120159    : "=a" (result),    /* %0 */ \
    121160      "=&c" (temp0),    /* %1 */ \
    122161      "=d" (temp1)      /* %2 */ \
     162      ALIGN_STACK_REGS_IN \
    123163    : "2" (method)      /* %2 */ \
    124     : "memory" ); \
     164      ALIGN_STACK_REGS_OUT \
     165    : "memory" \
     166        ); \
    125167    return result; \
    126168}
  • trunk/src/libs/xpcom18a4/xpcom/tests/nsIFileTest.cpp

    r1 r589  
    11#include "nsILocalFile.h"
     2#if 0 /* too new */
     3#include "nsStringGlue.h"
     4#else
    25#include "nsString.h"
     6#endif
    37
    48#include <stdio.h>
     
    812#include "nsIServiceManager.h"
    913#include "nsIMemory.h"
    10 #include "nsXPIDLString.h"
     14
     15#include "nsComponentManagerUtils.h"
     16#include "nsCOMPtr.h"
    1117
    1218void Passed();
     
    6369    rv = file->GetNativePath(pathName);
    6470    VerifyResult(rv);
    65    
     71
    6672    printf("filepath: %s\n", pathName.get());
    6773}
     
    7076{
    7177    nsILocalFile* file = nsnull;
    72     nsresult rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID,
    73                                               nsnull,
    74                                               NS_GET_IID(nsILocalFile),
    75                                               (void**)&file);
    76    
    77     if (NS_FAILED(rv) || (!file))
     78    nsresult rv = CallCreateInstance(NS_LOCAL_FILE_CONTRACTID, &file);
     79
     80
     81    if (NS_FAILED(rv) || (!file))
    7882    {
    7983        printf("create nsILocalFile failed\n");
     
    8892    rv = file->InitWithNativePath(nsDependentCString(creationPath));
    8993    VerifyResult(rv);
    90    
     94
    9195    printf("Getting Filename\n");
    9296    rv = file->GetNativeLeafName(leafName);
     
    105109    GetPaths(file);
    106110
    107    
     111
    108112    printf("Check For Existence\n");
    109113
     
    121125                  PRInt32 whatToCreate, PRInt32 perm)
    122126{
    123     nsCOMPtr<nsILocalFile> file;
    124     nsresult rv =
    125     nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID,
    126                                               nsnull,
    127                                               NS_GET_IID(nsILocalFile),
    128                                               (void **)getter_AddRefs(file));
    129 
    130     if (NS_FAILED(rv) || (!file))
     127    nsresult rv;
     128    nsCOMPtr<nsILocalFile> file =
     129        do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
     130
     131    if (NS_FAILED(rv) || (!file))
    131132    {
    132133        printf("create nsILocalFile failed\n");
     
    139140    rv = file->InitWithNativePath(nsDependentCString(creationPath));
    140141    VerifyResult(rv);
    141  
     142
    142143    printf("Appending %s\n", appendPath);
    143144    rv = file->AppendRelativeNativePath(nsDependentCString(appendPath));
    144145    VerifyResult(rv);
    145    
     146
    146147    printf("Check For Existence\n");
    147148
     
    155156
    156157
    157     rv = file->Create(whatToCreate, perm); 
     158    rv = file->Create(whatToCreate, perm);
    158159    VerifyResult(rv);
    159160
     
    161162    VerifyResult(rv);
    162163
    163    
     164
    164165    if (!exists)
    165166    {
     
    167168        return;
    168169    }
    169    
    170 }   
     170
     171}
    171172
    172173void CreateUniqueTest(const char* creationPath, const char* appendPath,
    173174                 PRInt32 whatToCreate, PRInt32 perm)
    174175{
    175     nsCOMPtr<nsILocalFile> file;
    176     nsresult rv =
    177     nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID,
    178                                               nsnull,
    179                                               NS_GET_IID(nsILocalFile),
    180                                               (void **)getter_AddRefs(file));
    181 
    182     if (NS_FAILED(rv) || (!file))
     176    nsresult rv;
     177    nsCOMPtr<nsILocalFile> file =
     178        do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
     179
     180    if (NS_FAILED(rv) || (!file))
    183181    {
    184182        printf("create nsILocalFile failed\n");
     
    191189    rv = file->InitWithNativePath(nsDependentCString(creationPath));
    192190    VerifyResult(rv);
    193  
     191
    194192    printf("Appending %s\n", appendPath);
    195193    rv = file->AppendNative(nsDependentCString(appendPath));
    196194    VerifyResult(rv);
    197    
     195
    198196    printf("Check For Existence\n");
    199197
     
    207205
    208206
    209     rv = file->CreateUnique(whatToCreate, perm); 
     207    rv = file->CreateUnique(whatToCreate, perm);
    210208    VerifyResult(rv);
    211209
     
    213211    VerifyResult(rv);
    214212
    215    
     213
    216214    if (!exists)
    217215    {
     
    219217        return;
    220218    }
    221    
    222 }   
     219
     220}
    223221
    224222
     
    226224CopyTest(const char *testFile, const char *targetDir)
    227225{
    228   nsCOMPtr<nsILocalFile> file;
    229   nsCOMPtr<nsILocalFile> dir;
    230 
    231226  printf("start copy test\n");
    232227
    233   nsresult rv =
    234     nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, NULL,
    235                                        NS_GET_IID(nsILocalFile),
    236                                        (void**)getter_AddRefs(file));
    237    
    238   if (NS_FAILED(rv) || (!file))
     228  nsresult rv;
     229  nsCOMPtr<nsILocalFile> file =
     230      do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
     231
     232  if (NS_FAILED(rv) || (!file))
    239233  {
    240234    printf("create nsILocalFile failed\n");
     
    244238  rv = file->InitWithNativePath(nsDependentCString(testFile));
    245239  VerifyResult(rv);
    246  
    247   rv = nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, NULL,
    248                                           NS_GET_IID(nsILocalFile),
    249                                           (void**)getter_AddRefs(dir));
    250 
    251   if (NS_FAILED(rv) || (!dir))
     240
     241  nsCOMPtr<nsILocalFile> dir =
     242      do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
     243
     244  if (NS_FAILED(rv) || (!dir))
    252245  {
    253246    printf("create nsILocalFile failed\n");
     
    263256  printf("end copy test\n");
    264257}
    265    
     258
    266259void
    267260DeletionTest(const char* creationPath, const char* appendPath, PRBool recursive)
    268261{
    269     nsCOMPtr<nsILocalFile> file;
    270     nsresult rv =
    271       nsComponentManager::CreateInstance(NS_LOCAL_FILE_CONTRACTID, NULL,
    272                                          NS_GET_IID(nsILocalFile),
    273                                          (void**)getter_AddRefs(file));
    274    
    275     if (NS_FAILED(rv) || (!file))
     262    nsresult rv;
     263    nsCOMPtr<nsILocalFile> file =
     264            do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv);
     265
     266    if (NS_FAILED(rv) || (!file))
    276267    {
    277268        printf("create nsILocalFile failed\n");
     
    284275    rv = file->InitWithNativePath(nsDependentCString(creationPath));
    285276    VerifyResult(rv);
    286  
     277
    287278    printf("Appending %s\n", appendPath);
    288279    rv = file->AppendNative(nsDependentCString(appendPath));
    289280    VerifyResult(rv);
    290    
     281
    291282    printf("Check For Existance\n");
    292283
     
    299290        printf("no.\n");
    300291
    301     rv = file->Remove(recursive); 
     292    rv = file->Remove(recursive);
    302293    VerifyResult(rv);
    303294
    304295    rv = file->Exists(&exists);
    305296    VerifyResult(rv);
    306    
     297
    307298    if (exists)
    308299    {
     
    310301        return;
    311302    }
    312    
    313 }
    314 
    315 void 
     303
     304}
     305
     306void
    316307MoveTest(const char *testFile, const char *targetDir)
    317308{
     
    322313  nsresult rv;
    323314  nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
    324      
    325   if (!file) 
     315
     316  if (!file)
    326317  {
    327318    printf("create nsILocalFile failed\n");
     
    331322  rv = file->InitWithNativePath(nsDependentCString(testFile));
    332323  VerifyResult(rv);
    333  
     324
    334325  nsCOMPtr<nsILocalFile> dir(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
    335  
    336   if (!dir) 
     326
     327  if (!dir)
    337328  {
    338329    printf("create nsILocalFile failed\n");
     
    352343}
    353344
    354 
     345// move up the number of directories in moveUpCount, then append "foo/bar"
     346void
     347NormalizeTest(const char *testPath, int moveUpCount,
     348              const char *expected)
     349{
     350  Banner("Normalize Test");
     351
     352  nsresult rv;
     353  nsCOMPtr<nsILocalFile> file(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
     354
     355  if (!file)
     356  {
     357    printf("create nsILocalFile failed\n");
     358    return;
     359  }
     360
     361  rv = file->InitWithNativePath(nsDependentCString(testPath));
     362  VerifyResult(rv);
     363
     364  nsCOMPtr<nsIFile> parent;
     365  nsAutoString path;
     366  for (int i=0; i < moveUpCount; i++)
     367  {
     368    rv = file->GetParent(getter_AddRefs(parent));
     369    VerifyResult(rv);
     370    rv = parent->GetPath(path);
     371    VerifyResult(rv);
     372    rv = file->InitWithPath(path);
     373    VerifyResult(rv);
     374  }
     375
     376  if (!parent) {
     377    printf("Getting parent failed!\n");
     378    return;
     379  }
     380
     381  rv = parent->Append(NS_LITERAL_STRING("foo"));
     382  VerifyResult(rv);
     383  rv = parent->Append(NS_LITERAL_STRING("bar"));
     384  VerifyResult(rv);
     385
     386  rv = parent->Normalize();
     387  VerifyResult(rv);
     388
     389  nsCAutoString newPath;
     390  rv = parent->GetNativePath(newPath);
     391  VerifyResult(rv);
     392
     393  nsCOMPtr<nsILocalFile>
     394    expectedFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
     395
     396  if (!expectedFile)
     397  {
     398    printf("create nsILocalFile failed\n");
     399    return;
     400  }
     401  rv = expectedFile->InitWithNativePath(nsDependentCString(expected));
     402  VerifyResult(rv);
     403
     404  rv = expectedFile->Normalize();
     405  VerifyResult(rv);
     406
     407  nsCAutoString expectedPath;
     408  rv = expectedFile->GetNativePath(expectedPath);
     409  VerifyResult(rv);
     410
     411  if (!newPath.Equals(expectedPath)) {
     412    printf("ERROR: Normalize() test Failed!\n");
     413    printf("     Got: %s\n", newPath.get());
     414    printf("Expected: %s\n", expectedPath);
     415  }
     416
     417  printf("end normalize test.\n");
     418}
    355419
    356420int main(void)
     
    361425    NS_ASSERTION(registrar, "Null nsIComponentRegistrar");
    362426    registrar->AutoRegister(nsnull);
    363  
     427
    364428#if defined(XP_WIN) || defined(XP_OS2)
    365     InitTest("c:\\temp\\", "sub1/sub2/");
    366     InitTest("d:\\temp\\", "sub1\\sub2\\");
     429    InitTest("c:\\temp\\", "sub1/sub2/"); // expect failure
     430    InitTest("d:\\temp\\", "sub1\\sub2\\"); // expect failure
    367431
    368432    CreationTest("c:\\temp\\", "file.txt", nsIFile::NORMAL_FILE_TYPE, 0644);
     
    385449#else
    386450#ifdef XP_UNIX
    387     InitTest("/tmp/", "sub1/sub2/");
    388    
     451    InitTest("/tmp/", "sub1/sub2/"); // expect failure
     452
    389453    CreationTest("/tmp", "file.txt", nsIFile::NORMAL_FILE_TYPE, 0644);
    390454    DeletionTest("/tmp/", "file.txt", PR_FALSE);
    391    
     455
    392456    CreationTest("/tmp", "mumble/a/b/c/d/e/f/g/h/i/j/k/", nsIFile::DIRECTORY_TYPE, 0644);
    393457    DeletionTest("/tmp", "mumble", PR_TRUE);
    394     CopyTest("/tmp/test.txt", "/tmp/foo");
     458
     459    CreationTest("/tmp", "file", nsIFile::NORMAL_FILE_TYPE, 0644);
     460    CopyTest("/tmp/file", "/tmp/newDir");
     461    MoveTest("/tmp/file", "/tmp/newDir/anotherNewDir");
     462    DeletionTest("/tmp", "newDir", PR_TRUE);
     463
     464    CreationTest("/tmp", "qux/quux", nsIFile::NORMAL_FILE_TYPE, 0644);
     465    CreationTest("/tmp", "foo/bar", nsIFile::NORMAL_FILE_TYPE, 0644);
     466    NormalizeTest("/tmp/qux/quux/..", 1, "/tmp/foo/bar");
     467    DeletionTest("/tmp", "qux", PR_TRUE);
     468    DeletionTest("/tmp", "foo", PR_TRUE);
    395469
    396470#endif /* XP_UNIX */
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette