📄 macdll.c
字号:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- *//* * The contents of this file are subject to the Mozilla Public * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. * * The Original Code is the Netscape Portable Runtime (NSPR). * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998-2000 Netscape Communications Corporation. All * Rights Reserved. * * Contributor(s): * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL"), in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your * version of this file only under the terms of the GPL and not to * allow others to use your version of this file under the MPL, * indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient * may use your version of this file under either the MPL or the * GPL. */#include <string.h>#include <Files.h>#include <Errors.h>#include <Folders.h>#include <CodeFragments.h>#include <Aliases.h>#include <Resources.h>#include "IterateDirectory.h" /* MoreFiles */#include "MacErrorHandling.h"#include "macdll.h"#include "mdmac.h"#include "macio.h"#include "primpl.h"#include "plstr.h"/* turds used to iterate through the directories looking for the desired library.*/struct GetSharedLibraryFilterProcData{ Boolean inRecursive; StringPtr inName; Boolean outFound; CFragConnectionID outID; Ptr outAddress; OSErr outError;};typedef struct GetSharedLibraryFilterProcData GetSharedLibraryFilterProcData;static pascal voidGetSharedLibraryFilterProc(const CInfoPBRec* const inCpb, Boolean* inWantQuit, void *inFilterData);/* NSGetSharedLibrary Unfortunately CFM doesn't support user specified loader paths, so we emulate the behavior. Effectively this is a GetSharedLibrary where the loader path is user defined.*/OSErrNSGetSharedLibrary(Str255 inLibName, CFragConnectionID* outID, Ptr* outMainAddr){ char* curLibPath; char* freeCurLibPath; OSErr tempErr; Boolean recursive; FSSpec curFolder; GetSharedLibraryFilterProcData filterData; char *endCurLibPath; Boolean done; filterData.outFound = false; filterData.outID = (CFragConnectionID)(-1); filterData.outAddress = NULL; filterData.inName = inLibName; freeCurLibPath = curLibPath = PR_GetLibraryPath(); if (curLibPath == NULL) return (cfragNoLibraryErr); tempErr = cfragNoLibraryErr; do { endCurLibPath = PL_strchr(curLibPath, PR_PATH_SEPARATOR); done = (endCurLibPath == NULL);#if 0 // we overload the first character of a path if it's : // then we want to recursively search that path // see if path should be recursive if (*curLibPath == ':') { // ':' is an illegal character in the name of a file // if we start any path with this, we want to allow // search recursively curLibPath++; recursive = true; } else#endif { recursive = false; } if (!done) *endCurLibPath = '\0'; // NULL terminate the string // convert to FSSpec tempErr = ConvertUnixPathToFSSpec(curLibPath, &curFolder); // now look in this directory if (noErr == tempErr) { filterData.inRecursive = recursive; FSpIterateDirectory(&curFolder, recursive ? 0 : 1, &GetSharedLibraryFilterProc, &filterData); if (filterData.outFound) { *outID = filterData.outID; *outMainAddr = filterData.outAddress; tempErr = noErr; break; } else { tempErr = cfragNoLibraryErr; } } curLibPath = endCurLibPath + 1; // skip to next path (past the '\0'); } while (!done); free(freeCurLibPath); return (tempErr);}static BooleanLibInPefContainer(const FSSpec* inSpec, StringPtr inName, UInt32* outCodeOffset, UInt32* outCodeLength);/* GetSharedLibraryFilterProc Callback to FSpIterateDirectory, finds a library with the name matching the data in inFilterData (of type GetSharedLibraryFilterProcData). Forces a quit when a match is found.*/static pascal voidGetSharedLibraryFilterProc(const CInfoPBRec* const inCpb, Boolean* inWantQuit, void *inFilterData){ GetSharedLibraryFilterProcData* pFilterData = (GetSharedLibraryFilterProcData*) inFilterData; if ((inCpb->hFileInfo.ioFlAttrib & (1 << ioDirFlg)) == 0) { FSSpec fragSpec; OSErr tempErr; Str255 errName; Boolean crap; UInt32 codeOffset; UInt32 codeLength; // it's a file //
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -