(file) Return to shlib.c CVS log (file) (dir) Up to [OMI] / omi / pal

 1 krisbash 1.1 #include "shlib.h"
 2              #include "config.h"
 3              #include <pal/strings.h>
 4              
 5              Shlib* Shlib_Open_Injected(
 6                  _In_z_ const PAL_Char* path,
 7                  NitsCallSite cs)
 8              {
 9                  if (NitsShouldFault(cs, NitsAutomatic))
10                  {
11              #if defined(_MSC_VER)
12                      /* Caller may call Shlib_Err(). */
13                      SetLastError(ERROR_OUTOFMEMORY);
14              #endif
15                      return NULL;
16                  }
17              
18                  if(path == NULL)
19                      return NULL;
20                  
21              #if defined(_MSC_VER)
22 krisbash 1.1     return (Shlib*)LoadLibraryEx(path, NULL, 0);
23              #else
24                  const char *temp = NULL;
25              
26              #if defined(CONFIG_ENABLE_WCHAR)
27                  char buffer[PAL_MAX_PATH_SIZE];
28                  StrWcslcpy(buffer, path, PAL_MAX_PATH_SIZE);
29                  temp = buffer;
30              #else
31                  temp = path;
32              #endif
33              
34                  return (Shlib*)dlopen(temp, PAL_DLOPEN_FLAGS);
35              #endif
36              }
37              
38              PAL_Char* Shlib_Err()
39              {
40              #if defined(_MSC_VER)
41                  PAL_Char* err = NULL;
42                  
43 krisbash 1.1     FormatMessage(
44                      FORMAT_MESSAGE_ALLOCATE_BUFFER|
45                      FORMAT_MESSAGE_FROM_SYSTEM|
46                      FORMAT_MESSAGE_IGNORE_INSERTS, 
47                      NULL, 
48                      GetLastError(), 
49                      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 
50                      (LPTSTR)&err, 
51                      0, 
52                      NULL);
53                  return err;
54              #else
55                  char* err = dlerror();
56                  size_t len = strlen(err) + 1;
57                  PAL_Char* copy = PAL_Malloc(len * sizeof(PAL_Char));
58                  TcsStrlcpy(copy, err, len);
59                  return copy;
60              #endif
61              }
62              
63              _Use_decl_annotations_
64 krisbash 1.1 void Shlib_Format(
65                  TChar path[PAL_MAX_PATH_SIZE],
66                  const char* dirName, 
67                  const char* shortName)
68              {
69                  *path = '\0';
70              
71                  /* Directory */
72                  if (dirName && dirName[0] != '\0')
73                  {
74                      TcsStrlcat(path, dirName, PAL_MAX_PATH_SIZE);
75                      TcsStrlcat(path, "/", PAL_MAX_PATH_SIZE);
76                  }
77              
78                  /* Prefix */
79              #if !defined(CONFIG_OS_WINDOWS)
80                  TcsStrlcat(path, "lib", PAL_MAX_PATH_SIZE);
81              #endif
82              
83                  /* Library name */
84                  TcsStrlcat(path, shortName, PAL_MAX_PATH_SIZE);
85 krisbash 1.1 
86                  /* Suffix */
87                  TcsStrlcat(path, ".", PAL_MAX_PATH_SIZE);
88                  TcsStrlcat(path, CONFIG_SHLIBEXT, PAL_MAX_PATH_SIZE);
89              }

ViewCVS 0.9.2