Skip to content

Commit

Permalink
Date: Sat, 5 Apr 2008 19:54:28 -0700
Browse files Browse the repository at this point in the history
From: "Chris Peterson"
To: sdl@lists.libsdl.org
Subject: [SDL] [PATCH] SDLMain.m: fix a bug and some warnings for Mac OS X

Here are some small fixes for the src/main/macosx/SDLMain.m source
file used by Mac OS X apps:

1. setupWorkingDirectory() called chdir() within an assert(), which
gets compiled out in non-debug builds.

2. When some of gcc's optional warnings are enabled, it complains
about some implicit casts and the use of #import in SDLMain.m.
  • Loading branch information
slouken committed Apr 13, 2008
1 parent 56e48a1 commit 9cb048f
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/main/macosx/SDLMain.m
Expand Up @@ -5,10 +5,10 @@
Feel free to customize this file to suit your needs
*/

#import "SDL.h"
#import "SDLMain.h"
#import <sys/param.h> /* for MAXPATHLEN */
#import <unistd.h>
#include "SDL.h"
#include "SDLMain.h"
#include <sys/param.h> /* for MAXPATHLEN */
#include <unistd.h>

/* For some reaon, Apple removed setAppleMenu from the headers in 10.4,
but the method still is there and works. To avoid warnings, we declare
Expand Down Expand Up @@ -43,11 +43,11 @@ - (void)setAppleMenu:(NSMenu *)menu;

static NSString *getApplicationName(void)
{
NSDictionary *dict;
const NSDictionary *dict;
NSString *appName = 0;

/* Determine the application name */
dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
if (dict)
appName = [dict objectForKey: @"CFBundleName"];

Expand Down Expand Up @@ -87,15 +87,14 @@ - (void) setupWorkingDirectory:(BOOL)shouldChdir
if (shouldChdir)
{
char parentdir[MAXPATHLEN];
CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
if (CFURLGetFileSystemRepresentation(url2, true, (UInt8 *)parentdir, MAXPATHLEN)) {
assert ( chdir (parentdir) == 0 ); /* chdir to the binary app's parent */
}
CFRelease(url);
CFRelease(url2);
}

CFURLRef url = CFBundleCopyBundleURL(CFBundleGetMainBundle());
CFURLRef url2 = CFURLCreateCopyDeletingLastPathComponent(0, url);
if (CFURLGetFileSystemRepresentation(url2, 1, (UInt8 *)parentdir, MAXPATHLEN)) {
chdir(parentdir); /* chdir to the binary app's parent */
}
CFRelease(url);
CFRelease(url2);
}
}

#if SDL_USE_NIB_FILE
Expand Down Expand Up @@ -319,7 +318,7 @@ - (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
NSString *result;

bufferSize = selfLen + aStringLen - aRange.length;
buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));

/* Get first part into buffer */
localRange.location = 0;
Expand Down

0 comments on commit 9cb048f

Please sign in to comment.