ResKnife/External/MoreFiles/FileCopy.c

1 line
19 KiB
C
Raw Normal View History

2002-03-29 14:59:03 +00:00
/* File: FileCopy.c Contains: A robust, general purpose file copy routine. Version: MoreFiles Copyright: <09> 1992-2001 by Apple Computer, Inc., all rights reserved. You may incorporate this sample code into your applications without restriction, though the sample code has been provided "AS IS" and the responsibility for its operation is 100% yours. However, what you are not permitted to do is to redistribute the source as "DSC Sample Code" after having made changes. If you're going to re-distribute the source, we require that you make it clear in the source that the code was descended from Apple Sample Code, but that you've made changes. File Ownership: DRI: Apple Macintosh Developer Technical Support Other Contact: Apple Macintosh Developer Technical Support <http://developer.apple.com/bugreporter/> Technology: DTS Sample Code Writers: (JL) Jim Luther Change History (most recent first): <2> 2/7/01 JL Added standard header. Updated names of includes. Updated various routines to use new calling convention of the MoreFilesExtras accessor functions. <1> 12/06/99 JL MoreFiles 1.5. */ #include <MacTypes.h> #include <MacErrors.h> #include <MacMemory.h> #include <Files.h> #include <Math64.h> #define __COMPILINGMOREFILES #include "MoreFiles.h" #include "MoreFilesExtras.h" #include "MoreDesktopMgr.h" #include "FileCopy.h" /*****************************************************************************/ /* local constants */ /* The deny-mode privileges to use when opening the source and destination files. */ enum { srcCopyMode = dmRdDenyWr, dstCopyMode = dmWrDenyRdWr }; /* The largest (16K) and smallest (.5K) copy buffer to use if the caller doesn't supply ** their own copy buffer. */ enum { bigCopyBuffSize = 0x00004000, minCopyBuffSize = 0x00000200 }; /*****************************************************************************/ /* static prototypes */ static OSErr GetDestinationDirInfo(short vRefNum, long dirID, ConstStr255Param name, long *theDirID, Boolean *isDirectory, Boolean *isDropBox); /* GetDestinationDirInfo tells us if the destination is a directory, it's directory ID, and if it's an AppleShare drop box (write privileges only -- no read or search privileges). vRefNum input: Volume specification. dirID input: Directory ID. name input: Pointer to object name, or nil when dirID specifies a directory that's the object. theDirID output: If the object is a file, then its parent directory ID. If the object is a directory, then its ID. isDirectory output: True if object is a directory; false if object is a file. isDropBox output: True if directory is an AppleShare drop box. */ static OSErr CheckForForks(short vRefNum, long dirID, ConstStr255Param name, Boolean *hasDataFork, Boolean *hasResourceFork); /* CheckForForks tells us if there is a data or resource fork to copy. vRefNum input: Volume specification of the file's current location. dirID input: Directory ID of the file's current location. name input: The name of the file. */ static OSErr PreflightFileCopySpace(short srcVRefNum, long srcDirID, ConstStr255Param srcName, ConstStr255Param dstVolName, short dstVRefNum, Boolean *spaceOK); /* PreflightFileCopySpace determines if there's enough space on a volume to copy the specified file to that volume. Note: The results of this routine are not perfect. For example if the volume's catalog or extents overflow file grows when the new file is created, more allocation blocks may be needed beyond those needed for the file's data and resource forks. srcVRefNum input: Volume specification of the file's current location. srcDirID input: Directory ID of the file's current location. srcName input: The name of the file. dstVolName input: A pointer to the name of the volume where the file will be copied or NULL. dstVRefNum inp