Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 3ds-libdl. #101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions 3ds/libdl/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Contributor: Teddy Astie <[email protected]>
# Maintainer:

pkgname=3ds-libdl
pkgver=1.0.0
pkgrel=1
pkgdesc='Extensible libdl library for projects that needs it.'
arch=('any')
options=(!strip)
makedepends=('devkitpro-pkgbuild-helpers')
source=('dlfcn.c' 'dlfcn.h')
sha256sums=('561e4031eab33c95eceae4fea7b617fc4c2f7d39606e910d077830b36ef4963d' '37c16bc645be27cad69904a53973a8862c37890f7327f6b26998794c62527336')
groups=('3ds-portlibs')

build() {
source /opt/devkitpro/3dsvars.sh

${TOOL_PREFIX}gcc ${CFLAGS} -c -o dlfcn.o dlfcn.c
${AR} rcu libdl.a dlfcn.o
}

package() {
source /opt/devkitpro/3dsvars.sh

mkdir -p ${pkgdir}${PORTLIBS_PREFIX}/lib/ ${pkgdir}${PORTLIBS_PREFIX}/include/
cp libdl.a ${pkgdir}${PORTLIBS_PREFIX}/lib/
cp dlfcn.h ${pkgdir}${PORTLIBS_PREFIX}/include/
}
36 changes: 36 additions & 0 deletions 3ds/libdl/dlfcn.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "dlfcn.h"

#include <stddef.h>

static dl_open g_open;
static dl_error g_error;
static dl_sym g_sym;
static dl_close g_close;

void dl_setfn(dl_open new_open, dl_error new_error, dl_sym new_sym, dl_close new_close)
{
g_open = new_open;
g_error = new_error;
g_sym = new_sym;
g_close = new_close;
}

void *dlopen(const char *module, int flag)
{
return g_open ? g_open(module, flag) : NULL;
}

char *dlerror(void)
{
return g_error ? g_error() : "";
}

void *dlsym(void *handle, const char *name)
{
return g_sym ? g_sym(handle, name) : NULL;
}

int dlclose(void *handle)
{
return g_close ? g_close(handle) : 0;
}
25 changes: 25 additions & 0 deletions 3ds/libdl/dlfcn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef __DLFCN_H__
#define __DLFCN_H__

#define RTLD_LAZY 0
#define RTLD_NOW 1
#define RTLD_GLOBAL 2
#define RTLD_LOCAL 3

/* Defines a dlfcn.h compatible API. */
void *dlopen(const char *module, int flag);
char *dlerror(void);
void *dlsym(void *handle, const char *name);
int dlclose(void *handle);

/* Add a custom API to change builtin functions with user-provided ones.
* This is useful to expand dlfcn to something working when needed (e.g LuaJIT FFI).
*/
typedef void *(*dl_open)(const char *, int);
typedef char *(*dl_error)(void);
typedef void *(*dl_sym)(void *, const char *);
typedef int (*dl_close)(void *);

void dl_setfn(dl_open open, dl_error error, dl_sym sym, dl_close close);

#endif /* __DLFCN_H__ */