Skip to content

Commit

Permalink
FIXME removal: abstract out some Unixy things.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Dec 9, 2006
1 parent fb44896 commit 7823472
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
18 changes: 8 additions & 10 deletions gui.c
@@ -1,9 +1,8 @@
#include "gui.h"
#include "platform.h"
#include "fileio.h"

// !!! FIXME: None of these should be here.
#include <dlfcn.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>

Expand Down Expand Up @@ -83,9 +82,9 @@ static void deleteGuiPlugin(PluginList *plugin)
if (plugin->gui)
plugin->gui->deinit();
if (plugin->lib)
dlclose(plugin->lib);
MojoPlatform_dlclose(plugin->lib);
if (plugin->filename)
unlink(plugin->filename);
MojoPlatform_unlink(plugin->filename);
free(plugin->filename);
free(plugin);
} // if
Expand Down Expand Up @@ -143,12 +142,11 @@ static boolean loadDynamicGuiPlugin(PluginList *plugins, MojoArchive *ar)
if (rc)
{
rc = false;
lib = dlopen(fname, RTLD_NOW | RTLD_GLOBAL);
STUBBED("abstract out dlopen!");
lib = MojoPlatform_dlopen(fname);
if (lib != NULL)
{
MojoGuiEntryPoint entry;
entry = (MojoGuiEntryPoint) dlsym(lib, MOJOGUI_ENTRY_POINT_STR);
void *addr = MojoPlatform_dlsym(lib, MOJOGUI_ENTRY_POINT_STR);
MojoGuiEntryPoint entry = (MojoGuiEntryPoint) addr;
if (entry != NULL)
rc = tryGuiPlugin(plugins, entry);
} // if
Expand All @@ -157,9 +155,9 @@ static boolean loadDynamicGuiPlugin(PluginList *plugins, MojoArchive *ar)
if (!rc)
{
if (lib != NULL)
dlclose(lib);
MojoPlatform_dlclose(lib);
if (fname[0])
unlink(fname);
MojoPlatform_unlink(fname);
} // if

return rc;
Expand Down
9 changes: 9 additions & 0 deletions platform.h
Expand Up @@ -22,6 +22,15 @@ uint32 MojoPlatform_ticks(void);
// avoid calling this.
void MojoPlatform_die(void);

// Delete a file from the physical filesystem. Returns true on success, false
// on failure.
boolean MojoPlatform_unlink(const char *fname);

// Wrappers for Unix dlopen/dlsym/dlclose ...
void *MojoPlatform_dlopen(const char *fname);
void *MojoPlatform_dlsym(void *lib, const char *sym);
void MojoPlatform_dlclose(void *lib);

// Get the current locale, in the format "xx_YY" where "xx" is the language
// (en, fr, de...) and "_YY" is the country. (_US, _CA, etc). The country
// can be omitted. Don't include encoding, it's always UTF-8 at this time.
Expand Down
42 changes: 42 additions & 0 deletions platform/unix.c
Expand Up @@ -10,6 +10,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <dlfcn.h>

#include "../platform.h"

Expand Down Expand Up @@ -190,5 +191,46 @@ void MojoPlatform_die(void)
_exit(86);
} // MojoPlatform_die


boolean MojoPlatform_unlink(const char *fname)
{
return (unlink(fname) == 0);
} // MojoPlatform_unlink



// pre-10.4 Mac OS X doesn't have dlopen(), etc. So on PowerPC Mac OS X, which
// can be an older version of the OS, we use Carbon calls instead.
// The Intel architecture switch started with 10.4.
#if PLATFORM_MACOSX && defined(__POWERPC__)
#define USE_LEGACY_MACOSX_DLOPEN 1
#endif

void *MojoPlatform_dlopen(const char *fname)
{
#if USE_LEGACY_MACOSX_DLOPEN
#error !!! FIXME Write me.
#endif
return dlopen(fname, RTLD_NOW | RTLD_GLOBAL);
} // MojoPlatform_dlopen


void *MojoPlatform_dlsym(void *lib, const char *sym)
{
#if USE_LEGACY_MACOSX_DLOPEN
#error !!! FIXME Write me.
#endif
return dlsym(lib, sym);
} // MojoPlatform_dlsym


void MojoPlatform_dlclose(void *lib)
{
#if USE_LEGACY_MACOSX_DLOPEN
#error !!! FIXME Write me.
#endif
dlclose(lib);
} // MojoPlatform_dlclose

// end of unix.c ...

0 comments on commit 7823472

Please sign in to comment.