Ticket #19130: patch-Copy-filecopy.c.diff

File patch-Copy-filecopy.c.diff, 2.9 KB (added by ghosthound, 15 years ago)

test patch for p5-macosx-file for Tiger

  • Copy/filecopy.c

    old new  
    33 */
    44
    55#undef I_POLL
     6// #include <libgen.h>
    67#include <Files.h>
    78#include "common/util.c"
    89
     10#ifndef kPOSIXErrorBase
     11# define        kPOSIXErrorBase 100000L
     12#endif  /* kPOSIXErrorBase */
     13
     14#ifndef kPOSIXErrorERANGE
     15# define        kPOSIXErrorERANGE 100034L
     16#endif  /* kPOSIXErrorERANGE */
     17
    918#ifdef _INC_PERL_XSUB_H
    1019static int
    1120setcopyerr(int err, char *filename, int line)
     
    166175
    167176#define min(x, y) ((x) < y) ? (x) : (y)
    168177
    169 static OSErr
    170 filecopy(char *src, char *dst, UInt64 maxbufsize, int preserve){
    171     OSErr err;
    172     FSCatalogInfo srcCat, dstCat;
    173     FSRef srcFS, dstFS;
    174     HFSUniStr255 forkName;
    175     UTCDateTime  now;
    176    
    177     if (err = FSPathMakeRef(src, &srcFS, NULL))
    178     { return err; }
    179    
    180     if (err = FSGetCatalogInfo(&srcFS, kFSCatInfoGettableInfo, &srcCat,
    181                                NULL, NULL, NULL))
    182     { return err; }
    183 
    184     bcopy(&srcCat, &dstCat, sizeof(FSCatalogInfo));
    185 
    186     if (err = newfile(dst, &dstFS, &dstCat)){
    187         fpf(stderr, "Cannot Create File %s\n", dst);
    188         return err;
    189     }
    190     if (srcCat.dataLogicalSize){
    191         setbufsiz(min(srcCat.dataPhysicalSize, maxbufsize));
    192         FSGetDataForkName(&forkName);
    193         if (err = copyfork(&forkName, &srcFS, &dstFS))
    194         { return err; }
    195     }
    196     if (srcCat.rsrcLogicalSize){
    197         setbufsiz(min(srcCat.rsrcPhysicalSize, maxbufsize));
    198         FSGetResourceForkName(&forkName);
    199         if (err = copyfork(&forkName, &srcFS, &dstFS))
    200         { return err; }
    201     }
    202     freebuf();
    203     if (preserve){
    204         err =  FSSetCatalogInfo(&dstFS, kFSCatInfoSettableInfo, &srcCat);
    205     }
    206     return err;
     178static OSStatus
     179filecopy(char *src, char *dst, UInt64 maxbufsize, int preserve)
     180{
     181        OSStatus status;
     182        char                    *destDir = NULL;
     183        CFStringRef             destFname;
     184        char                    *lastSlash = NULL;
     185        char                    *tmpString = NULL;
     186       
     187        if (NULL == dst || NULL == src) {
     188                return -1;
     189        }
     190        /* split the dst into the dir and the filename */
     191        if (NULL == (tmpString = dirname(dst))) {
     192                /* dirname() failed... */
     193                return errno + kPOSIXErrorBase;
     194        }
     195        destDir = calloc((strlen(tmpString) + 2), sizeof(char));
     196        if (NULL == destDir) {
     197                /* failed to allocate mem */
     198                return errno + kPOSIXErrorBase;
     199        }
     200        if (strlcpy(destDir, tmpString, (strlen(tmpString) + 1)) > (strlen(tmpString))) {
     201                /* argh! */
     202                return kPOSIXErrorERANGE;
     203        }
     204        if (NULL == (tmpString = basename(dst))) {
     205                /* basename() failed... */
     206                return errno + kPOSIXErrorBase;
     207        }
     208        destFname = CFStringCreateWithCString(kCFAllocatorDefault, tmpString, kCFStringEncodingMacRoman);
     209
     210        status = FSPathCopyObjectSync(src, destDir, destFname, NULL, kFSFileOperationSkipPreflight);
     211       
     212        // fprintf(stderr, "FSPathCOpyObjectSync(%s, %s, %s,...) status is \"%d\"\n", (NULL != src ? src : "<NULL>"), (NULL != destDir ? destDir: "<NULL>"), (NULL != tmpString ? tmpString: "<NULL>"), status);
     213       
     214        return status;
    207215}
    208216
     217
    209218/*
    210219static OSErr
    211220filemove(char *src, char *dst){