lullaby/examples/example_app/port/sdl2/main.cc
// Attempts to change the working dir to |target|.  Continuously scans up the
// current working dir one folder at a time until the target is found.
Attempts to change the working dir to |target|.  Continuously scans up the
current working dir one folder at a time until the target is found.
Attempts to change the working dir to |target| . Continuously scans up the current working dir one folder at a time until the target is found .
static bool ChangeWorkingDir(const char* const target) {
  static constexpr int kMaxPathLength = 1024;
  static constexpr int kMaxTreeDepth = 64;
  char curr_dir[kMaxPathLength] = ".";
#if defined(__APPLE__)
  CFBundleRef main_bundle = CFBundleGetMainBundle();
  CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL(main_bundle);
  if (!CFURLGetFileSystemRepresentation(resources_url, true,
                                        reinterpret_cast<UInt8*>(curr_dir),
                                        sizeof(curr_dir))) {
    LOG(ERROR) << "Could not get the bundle directory";
    return false;
  }
  CFRelease(resources_url);
  if (chdir(curr_dir) != 0) {
    return false;
  }
#else
  getcwd(curr_dir, sizeof(curr_dir));
#endif
  for (int i = 0; i < kMaxTreeDepth; ++i) {
    const int retval = chdir(target);
    if (retval == 0) {
      return true;
    }
    chdir("..");
  }
  return false;
}
static bool ChangeWorkingDir ( const char * const target ) { static constexpr int kMaxPathLength = 1024 ; static constexpr int kMaxTreeDepth = 64 ; char curr_dir [ kMaxPathLength ] = " " ; #if defined ( __APPLE__ ) CFBundleRef main_bundle = CFBundleGetMainBundle ( ) ; CFURLRef resources_url = CFBundleCopyResourcesDirectoryURL ( main_bundle ) ; if ( ! CFURLGetFileSystemRepresentation ( resources_url , true , reinterpret_cast < UInt8 * > ( curr_dir ) , sizeof ( curr_dir ) ) ) { LOG ( ERROR ) << " " ; return false ; } CFRelease ( resources_url ) ; if ( chdir ( curr_dir ) != 0 ) { return false ; } #else getcwd ( curr_dir , sizeof ( curr_dir ) ) ; #endif for ( int i = 0 ; i < kMaxTreeDepth ; ++ i ) { const int retval = chdir ( target ) ; if ( retval == 0 ) { return true ; } chdir ( " " ) ; } return false ; }
Attempts to change the working dir to |target|.
Attempts to change the working dir to |target| .
// Get the root of the target directory from the Bundle instead of using the // directory specified by the client. // Scan "up" the directory structure until we find the first path that // contains our target directory.