1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/pkg/landfall-examples/dl_test/dl_test.c Sun May 27 22:08:58 2018 +0200
1.3 @@ -0,0 +1,52 @@
1.4 +/*
1.5 + * Test dynamic loading.
1.6 + *
1.7 + * (c) 2018 Paul Boddie <paul@boddie.org.uk>
1.8 + *
1.9 + * This program is free software; you can redistribute it and/or
1.10 + * modify it under the terms of the GNU General Public License as
1.11 + * published by the Free Software Foundation; either version 2 of
1.12 + * the License, or (at your option) any later version.
1.13 + *
1.14 + * This program is distributed in the hope that it will be useful,
1.15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.17 + * GNU General Public License for more details.
1.18 + *
1.19 + * You should have received a copy of the GNU General Public License
1.20 + * along with this program; if not, write to the Free Software
1.21 + * Foundation, Inc., 51 Franklin Street, Fifth Floor,
1.22 + * Boston, MA 02110-1301, USA
1.23 + */
1.24 +
1.25 +#include <l4/util/util.h>
1.26 +#include <dlfcn.h>
1.27 +#include <stdio.h>
1.28 +
1.29 +static const char *libname = "rom/libdl_test_data.so";
1.30 +
1.31 +int main(void)
1.32 +{
1.33 + const char *buffer;
1.34 +
1.35 + /* Obtain the linked data. */
1.36 +
1.37 + void *handle = dlopen(libname, RTLD_NOW);
1.38 + const char *(*get_data)(void);
1.39 +
1.40 + if (handle == NULL)
1.41 + {
1.42 + printf("Could not open %s\n", libname);
1.43 + return 1;
1.44 + }
1.45 +
1.46 + get_data = dlsym(handle, "get_data");
1.47 +
1.48 + /* Load and show the data. */
1.49 +
1.50 + buffer = get_data();
1.51 + puts(buffer);
1.52 +
1.53 + l4_sleep_forever();
1.54 + return 0;
1.55 +}