Skip to content

Commit

Permalink
FIXME removal...appBinaryPath() returns a malloc()'d string, that cal…
Browse files Browse the repository at this point in the history
…ler must

 free(). This lets us handle pathological cases where people have a really
 deep directory hierarchy for the app's location that would overflow a static
 buffer passed by the caller, and prevents having to free a saved buffer
 in the platform layer.
  • Loading branch information
icculus committed Dec 9, 2006
1 parent 145d03d commit 95b1a16
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
4 changes: 2 additions & 2 deletions fileio.c
Expand Up @@ -447,13 +447,13 @@ MojoArchive *MojoArchive_initBaseArchive(void)
const char *basepath = MojoPlatform_appBinaryPath();
MojoInput *io = MojoInput_newFromFile(basepath);

STUBBED("chdir to path of binary");

if (io != NULL)
GBaseArchive = MojoArchive_newFromInput(io, basepath);

if (GBaseArchive == NULL)
GBaseArchive = MojoArchive_newFromDirectory(".");

free(basepath); // caller free()s this string.
} // else

return GBaseArchive;
Expand Down
4 changes: 1 addition & 3 deletions platform.h
Expand Up @@ -10,9 +10,7 @@ extern "C" {
// this is called by your mainline.
int MojoSetup_main(int argc, char **argv);

// Caller should _NOT_ free returned string...it's calculated on the first
// call and reused for future calls.
// !!! FIXME: is that a good idea?
// Caller must free returned string!
const char *MojoPlatform_appBinaryPath(void);

uint32 MojoPlatform_ticks(void);
Expand Down
5 changes: 1 addition & 4 deletions platform/unix.c
Expand Up @@ -86,10 +86,7 @@ const char *MojoPlatform_appBinaryPath(void)
{
const char *argv0 = GArgv[0];
char resolved[PATH_MAX];

static char *retval = NULL;
if (retval != NULL)
return retval;
char *retval = NULL;

if (realpath("/proc/self/exe", resolved) != NULL)
retval = xstrdup(resolved); // fast path for Linux.
Expand Down

0 comments on commit 95b1a16

Please sign in to comment.