root/src/getdir_darwin.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. get_install_dir

   1 /*
   2  * getdir_darwin.c - get the library directory at runtime
   3  *                   for MacOSX Framework build.
   4  *  included from paths.c
   5  *
   6  * $Id: getdir_darwin.c,v 1.1 2005/10/24 01:37:21 shirok Exp $
   7  */
   8 
   9 /* NB: This is used only if --enable-framework is given to the
  10    configure script.   Otherwise, the absolute paths determined at
  11    configuration time are embedded in the binary. */
  12 
  13 #include <libgen.h>
  14 #include <CoreFoundation/CoreFoundation.h>
  15 
  16 /* Must match the id in Info.plist */
  17 #define LIBGAUCHE_ID  "com.schemearts.gauche"
  18 
  19 /* Subdirs appended to the bundle path */
  20 #define SUBDIR   "/Versions/Current/"
  21 
  22 static int get_install_dir(char *buf, int buflen,
  23                            void (*errfn)(const char *, ...))
  24 {
  25     CFBundleRef bundle;
  26     CFURLRef bundleURL;
  27     CFStringRef bundlePath;
  28 
  29     bundle = CFBundleGetBundleWithIdentifier(CFSTR(LIBGAUCHE_ID));
  30     if (bundle == NULL) {
  31         /* This call fails when gosh is called during the build process
  32            (thus, the framework hasn't been created).  For the time
  33            being, we just return a dummy directory. */
  34         strcpy(buf, ".");
  35         return 1;
  36     }
  37     bundleURL = CFBundleCopyBundleURL(bundle);
  38     if (bundleURL == NULL) {
  39         errfn("CFBundleCopyBundleURL failed");
  40     }
  41     bundlePath = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
  42     if (bundlePath == NULL) {
  43         errfn("CFURLCopyFileSystemPath failed");
  44     }
  45     if (!CFStringGetCString(bundlePath, buf, buflen, kCFStringEncodingUTF8)) {
  46         errfn("CFStringGetCString failed");
  47     }
  48     if (strlen(buf) + strlen(SUBDIR) + 1 >= buflen) {
  49         errfn("pathname too long");
  50     }
  51     strcat(buf, SUBDIR);
  52     CFRelease(bundlePath);
  53     CFRelease(bundleURL);
  54     CFRelease(bundle);
  55     return strlen(buf);
  56 }
  57 

/* [<][>][^][v][top][bottom][index][help] */