Changeset 1750 for trunk/dll/srchpath.c


Ignore:
Timestamp:
Mar 1, 2014, 2:55:57 PM (11 years ago)
Author:
John Small
Message:

Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.

So calls to these functions, direct and indirect, had to be changed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/srchpath.c

    r1673 r1750  
    1414  04 Oct 08 JBS Make searchapath non-static
    1515  17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
     16  01 Mar 14 JBS Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.
    1617
    1718***********************************************************************/
     
    2122#define INCL_WIN
    2223#define INCL_DOS
     24#define INCL_DOSERRORS
    2325#define INCL_LONGLONG                   // dircnrs.h
    2426
     
    102104
    103105/**
    104  * Search for file in name PATH env variable
    105  * 23 Aug 07 SHL fixme to be MT safe
     106 * SearchPathForFile: Search for a file along a path
     107 *
     108 * @param pPathname: the name of a path environment variable (input)
     109 *    Used only if pFilename has no directory separators or ':' for a drive sepcification
     110 *
     111 * @param pFilename: the name of a file to search for (input)
     112 *    If the file name includes a directory separator or the ':' for a drive specification then
     113 *        DosQueryPathInfo is used for the search
     114 *    else
     115 *        DosSearchPath is used, along with the pPathname parameter
     116 *
     117 * @param pFullFilename: address of where to place fully-qulified name if search succeeds (output)
     118 *    This parameter may be NULL if the fully-qualified filename is not desired.
     119 *
     120 * @return Return code from call to DosQueryPathInfo/DosSearchPath
     121 *
    106122 */
     123APIRET SearchPathForFile(PCSZ pPathname,
     124                         PCSZ pFilename,
     125                         PCHAR pFullFilename)
     126{
     127  APIRET rc;
     128  CHAR szFullFilename[CCHMAXPATH];
    107129
    108 CHAR *searchapath(PCSZ pathvar, PCSZ filename)
    109 {
    110   static CHAR fbuf[CCHMAXPATH];
     130  if (!pPathname || !*pPathname || !pFilename || !*pFilename)
     131    return ERROR_INVALID_PARAMETER;
    111132
    112   if (strchr(filename, '\\') || strchr(filename, '/')
    113       || strchr(filename, ':')) {
    114 
    115     FILESTATUS3 fsa;
    116 
    117     strcpy(fbuf, filename);
    118     if (!DosQueryPathInfo(fbuf, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa)))
    119       return fbuf;
    120     *fbuf = 0;
    121     return fbuf;
     133  if (strchr(pFilename, '\\') || strchr(pFilename, '/')
     134      || strchr(pFilename, ':')) {
     135    rc = DosQueryPathInfo(pFilename, FIL_QUERYFULLNAME,
     136                          (PVOID)szFullFilename, (ULONG) CCHMAXPATH-1);
    122137  }
    123   *fbuf = 0;
    124   if (DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
    125                     SEARCH_CUR_DIRECTORY,
    126                     (CHAR *) pathvar, (CHAR *) filename, (PBYTE)fbuf, CCHMAXPATH - 1))
    127     *fbuf = 0;
    128   return fbuf;
     138  else {
     139   rc = DosSearchPath(SEARCH_IGNORENETERRS | SEARCH_ENVIRONMENT |
     140                      SEARCH_CUR_DIRECTORY,
     141                      (CHAR *) pPathname,
     142                      (CHAR *) pFilename,
     143                      (PBYTE) szFullFilename,
     144                      CCHMAXPATH - 1);
     145  }
     146  if (!rc && pFullFilename) {
     147    strcpy(pFullFilename, szFullFilename);
     148  }
     149  return rc;
    129150}
    130151
    131 CHAR *searchpath(PCSZ filename)
     152/**
     153 * SearchMultiplePathsForFile: Search for a file along multiple paths.
     154 *   Currently these paths are hard-coded to: PATH, DPATH and XPATH.
     155 *
     156 * @param pFilename: the name of a file to search for (input)
     157 *
     158 * @param pFullFilename: address of where to place fully-qulified name if search succeeds (output)
     159 *    This parameter may be NULL if the fully-qualified filename is not desired.
     160 *
     161 * @return Return code from call to SearchPathForFile (DosQueryPathInfo/DosSearchPath)
     162 *
     163 * @note: The code uses DosSearchPathForFile for all searches. First it searches PATH.
     164 *        If this fails it searches DPATH. If this fails it seaches XPATH.
     165 *
     166 */
     167APIRET SearchMultiplePathsForFile(PCSZ pFilename,
     168                                  PSZ pFullFilename)
    132169{
    133   CHAR *found;
     170  APIRET rc;
    134171
    135   if (!filename)
    136     return NullStr;
    137   found = searchapath(PCSZ_PATH, filename);
    138   if (!*found) {
    139     found = searchapath("DPATH", filename);
    140     if (!*found)
    141       found = searchapath("XPATH", filename);
     172  rc = SearchPathForFile(PCSZ_PATH,
     173                         pFilename,
     174                         pFullFilename);
     175  if (rc && rc != ERROR_INVALID_PARAMETER) {
     176    rc = SearchPathForFile("DPATH",
     177                           pFilename,
     178                           pFullFilename);
     179    if (rc && rc != ERROR_INVALID_PARAMETER)
     180      rc = SearchPathForFile("XPATH",
     181                             pFilename,
     182                             pFullFilename);
    142183  }
    143   return found;
     184  return rc;
    144185}
    145186
    146 #pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
     187//#pragma alloc_text(MISC9,first_path,searchapath,searchpath,RunFM2Util)
     188// jbs: first_path seems to be unused
     189#pragma alloc_text(MISC9,first_path,SearchPathForFile,SearchMultiplePathsForFile,RunFM2Util)
Note: See TracChangeset for help on using the changeset viewer.