File: dll_mac.cpp

package info (click to toggle)
falconpl 0.9.6.9-git20120606-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,176 kB
  • sloc: cpp: 181,389; ansic: 109,025; yacc: 2,310; xml: 1,218; sh: 403; objc: 245; makefile: 82; sql: 20
file content (88 lines) | stat: -rw-r--r-- 1,823 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
   FALCON - The Falcon Programming Language.
   FILE: dll_mac.cpp

   Implementation of darwin specific DLL system
   -------------------------------------------------------------------
   Author: Giancarlo Niccolai:
   Modified for darwin by: Francesco Guerra
   Begin: mar ago 3 2004

   -------------------------------------------------------------------
   (C) Copyright 2004: the FALCON developers (see list in AUTHORS file)

   See LICENSE file for licensing details.
*/

#include <falcon/dll_mac.h>
#include <falcon/autocstring.h>

namespace Falcon
{

DllLoader_Mac::~DllLoader_Mac()
{
   close();
}

bool DllLoader_Mac::open( const String &dll_name )
{
   if( m_module != 0 )
      if ( ! dlclose( m_module ) )
         return false;
   
   AutoCString name( dll_name );
   m_module = dlopen( name.c_str(), RTLD_NOW );
   if ( m_module == 0 )
      return false;
   return true;
}

bool DllLoader_Mac::close()
{
   if ( m_module != 0 ) {
      if ( dlclose( m_module ) ) {
         m_module = 0;
         return true;
      }
   }
   return false;
}

void DllLoader_Mac::assign( DllLoader_Mac &other )
{
   if ( m_module != 0 )
      close();

   m_module = other.m_module;
   other.m_module = 0;
}


DllFunc DllLoader_Mac::getSymbol( const String &sym_name ) const
{
   AutoCString name(sym_name);
   if ( m_module != 0 )
      return DllFunc( dlsym( m_module, name.c_str() ) );
   return DllFunc( 0 );
}

bool DllLoader_Mac::isDllMark( unsigned char ch1, unsigned char ch2 )
{
   if ( ch1 == 0xfe && ch2 == 0xed || ch1 == 0xca && ch2 == 0xfe ) return true;
   // Magic for Mach-O and Mach-O Fat binaries
   return false;
}

void DllLoader_Mac::getErrorDescription( String &descr ) const
{
   const char *le = dlerror();
   if ( le == 0 )
      return;
   descr.bufferize( le );
}

}


/* end of dll_mac.cpp */