~ubuntu-branches/ubuntu/precise/netatalk/precise

« back to all changes in this revision

Viewing changes to libatalk/util/module.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Rittau
  • Date: 2004-01-19 12:43:49 UTC
  • Revision ID: james.westby@ubuntu.com-20040119124349-es563jbp0hk0ae51
Tags: upstream-1.6.4
ImportĀ upstreamĀ versionĀ 1.6.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: module.c,v 1.4 2001/06/20 18:33:04 rufustfirefly Exp $
 
3
 */
 
4
 
 
5
#ifdef HAVE_CONFIG_H
 
6
#include "config.h"
 
7
#endif /* HAVE_CONFIG_H */
 
8
 
 
9
#include <stdlib.h>
 
10
#include <string.h>
 
11
#include <atalk/util.h>
 
12
 
 
13
static int _mod_dummy;
 
14
 
 
15
#ifndef HAVE_DLFCN_H
 
16
#ifdef MACOSX_SERVER
 
17
#include <mach-o/dyld.h>
 
18
 
 
19
void *mod_open(const char *path)
 
20
{
 
21
  NSObjectFileImage file;
 
22
 
 
23
  if (NSCreateObjectFileImageFromFile(path, &file) != 
 
24
      NSObjectFileImageSuccess)
 
25
    return NULL;
 
26
  return NSLinkModule(file, path, TRUE);
 
27
}
 
28
 
 
29
void *mod_symbol(void *module, const char *name)
 
30
{
 
31
   NSSymbol symbol;
 
32
   char *underscore;
 
33
 
 
34
   if ((underscore = (char *) malloc(strlen(name) + 2)) == NULL)
 
35
     return NULL;
 
36
   strcpy(underscore, "_");
 
37
   strcat(underscore, name);
 
38
   symbol = NSLookupAndBindSymbol(underscore);
 
39
   free(underscore);
 
40
 
 
41
   return NSAddressOfSymbol(symbol);
 
42
}
 
43
 
 
44
void mod_close(void *module)
 
45
{
 
46
  NSUnLinkModule(module, FALSE);
 
47
}
 
48
#endif /* MACOSX_SERVER */
 
49
 
 
50
#else /* HAVE_DLFCN_H */
 
51
 
 
52
#include <dlfcn.h>
 
53
 
 
54
#ifdef DLSYM_PREPEND_UNDERSCORE
 
55
void *mod_symbol(void *module, const char *name)
 
56
{
 
57
   void *symbol;
 
58
   char *underscore;
 
59
 
 
60
   if (!module)
 
61
     return NULL;
 
62
 
 
63
   if ((underscore = (char *) malloc(strlen(name) + 2)) == NULL)
 
64
     return NULL;
 
65
 
 
66
   strcpy(underscore, "_");
 
67
   strcat(underscore, name);
 
68
   symbol = dlsym(module, underscore);
 
69
   free(underscore);
 
70
 
 
71
   return symbol;
 
72
}
 
73
#endif /* DLSYM_PREPEND_UNDERSCORE */
 
74
#endif /* HAVE_DLFCN_H */