1/* 2 * Copyright (c) 2001-2007 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 * BLLoadFile.c 25 * bless 26 * 27 * Created by Shantonu Sen <ssen@apple.com> on Tue Apr 30 2002. 28 * Copyright (c) 2002-2007 Apple Inc. All Rights Reserved. 29 * 30 * $Id: BLLoadFile.c,v 1.15 2006/02/20 22:49:56 ssen Exp $ 31 * 32 */ 33 34#include <CoreFoundation/CoreFoundation.h> 35#include <string.h> 36 37#include <sys/paths.h> 38#include <sys/param.h> 39 40#include "bless.h" 41#include "bless_private.h" 42 43 44int BLLoadFile(BLContextPtr context, const char * src, int useRsrcFork, 45 CFDataRef* data) { 46 47 int err = 0; 48 int isHFS = 0; 49 CFDataRef output = NULL; 50 CFURLRef loadSrc; 51 char rsrcpath[MAXPATHLEN]; 52 53 54 if(useRsrcFork) { 55 err = BLIsMountHFS(context, src, &isHFS); 56 if(err) return 2; 57 58 if(isHFS) { 59 snprintf(rsrcpath, MAXPATHLEN-1, "%s"_PATH_RSRCFORKSPEC, src); 60 } else { 61 strncpy(rsrcpath, src, MAXPATHLEN-1); 62 } 63 } else { 64 strncpy(rsrcpath, src, MAXPATHLEN-1); 65 } 66 67 rsrcpath[MAXPATHLEN-1] = '\0'; 68 69 loadSrc = CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault, 70 (UInt8 *)rsrcpath, 71 strlen(rsrcpath), 0); 72 73 if(loadSrc == NULL) { 74 return 1; 75 } 76 77 if(!CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, 78 loadSrc, 79 &output, 80 NULL, 81 NULL, 82 NULL)) { 83 contextprintf(context, kBLLogLevelError, "Can't load %s\n", rsrcpath ); 84 CFRelease(loadSrc); 85 return 2; 86 } 87 88 CFRelease(loadSrc); loadSrc = NULL; 89 90 *data = (void *)output; 91 92 return 0; 93} 94