27 #ifndef __SB_LIBRARYLOADERUTILS__
28 #define __SB_LIBRARYLOADERUTILS__
31 #include <nsIProperties.h>
32 #include <nsStringGlue.h>
33 #include <nsServiceManagerUtils.h>
34 #include <nsILineInputStream.h>
35 #include <nsNetUtil.h>
41 #include <mach-o/dyld.h>
46 #define LOAD_LIBRARIES_LOG(args) PR_LOG(loadLibrariesLog, PR_LOG_WARN, args)
51 NS_ENSURE_ARG_POINTER(aManifest);
56 PRLogModuleInfo* loadLibrariesLog = PR_NewLogModule(
"sbLoadLibraries");
59 nsCOMPtr<nsIProperties> directorySvc =
60 do_GetService(
"@mozilla.org/file/directory_service;1", &rv);
61 NS_ENSURE_SUCCESS(rv, rv);
63 nsCOMPtr<nsIFile> appDir;
64 rv = directorySvc->Get(
"resource:app",
66 getter_AddRefs(appDir));
67 NS_ENSURE_SUCCESS(rv, rv);
69 nsCOMPtr<nsIInputStream> fis;
70 rv = NS_NewLocalFileInputStream(getter_AddRefs(fis), aManifest);
71 NS_ENSURE_SUCCESS(rv, rv);
73 nsCOMPtr<nsILineInputStream> lis = do_QueryInterface(fis, &rv);
74 NS_ENSURE_SUCCESS(rv, rv);
79 rv = lis->ReadLine(line, &moreLines);
80 NS_ENSURE_SUCCESS(rv, rv);
82 if (!line.IsEmpty() && line.CharAt(0) !=
'#') {
87 nsCOMPtr<nsILocalFile> libLocal;
88 if (line.CharAt(0) ==
'@') {
89 nsCOMPtr<nsIFile> clone;
90 rv = appDir->Clone(getter_AddRefs(clone));
91 NS_ENSURE_SUCCESS(rv, rv);
93 libLocal = do_QueryInterface(clone, &rv);
94 NS_ENSURE_SUCCESS(rv, rv);
96 nsDependentCSubstring
path(line.BeginReading() + 1, line.Length() - 1);
97 rv = libLocal->AppendRelativeNativePath(
path);
98 NS_ENSURE_SUCCESS(rv, rv);
101 nsCOMPtr<nsIFile> parent;
102 rv = aManifest->GetParent(getter_AddRefs(parent));
103 NS_ENSURE_SUCCESS(rv, rv);
105 while (StringBeginsWith(line, NS_LITERAL_CSTRING(
".."))) {
106 nsCOMPtr<nsIFile> newParent;
111 rv = parent->GetParent(getter_AddRefs(newParent));
112 NS_ENSURE_SUCCESS(rv, rv);
114 newParent.swap(parent);
117 libLocal = do_QueryInterface(parent, &rv);
118 NS_ENSURE_SUCCESS(rv, rv);
120 rv = libLocal->AppendRelativePath(NS_ConvertASCIItoUTF16(line));
121 NS_ENSURE_SUCCESS(rv, rv);
129 libLocal->GetNativePath(_path);
131 _path.BeginReading()));
137 libLocal->GetNativePath(filePath);
138 const struct mach_header*
header = NSAddImage(filePath.get(),
139 NSADDIMAGE_OPTION_MATCH_FILENAME_BY_INSTALLNAME |
140 NSADDIMAGE_OPTION_WITH_SEARCHING);
143 NSLinkEditErrors linkEditError;
145 const char *errorString;
146 const char *fileName;
148 NSLinkEditError(&linkEditError, &errorNum, &fileName, &errorString);
150 "SB_LoadLibraries: ERROR %d:%d for file %s\n%s",
151 linkEditError, errorNum, fileName, errorString);
154 PR_smprintf_free(message);
157 success = (header != nsnull);
160 rv = libLocal->Load(&library);
162 success = NS_SUCCEEDED(rv);
167 libLocal->GetNativePath(libPath);
168 char*
message = PR_smprintf(
"SB_LoadLibraries: Error loading library: %s, OS error was: %i",
169 libPath.get(), PR_GetOSError());
171 PR_smprintf_free(message);
178 NS_ENSURE_SUCCESS(rv, rv);
static nsresult SB_LoadLibraries(nsIFile *aManifest)
#define LOAD_LIBRARIES_LOG(args)