Changeset 1750


Ignore:
Timestamp:
Mar 1, 2014, 2:55:57 PM (12 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.

Location:
trunk/dll
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/avl.c

    r1625 r1750  
    4343  26 Aug 11 GKY Add the code to correctly format the date time strings for tar.gz archives
    4444                viewed using tar 1.15+
     45  01 Mar 14 JBS Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.
     46                So calls to these functions had to be changed.
    4547
    4648***********************************************************************/
     
    7678#include "wrappers.h"                   // xfgets
    7779#include "strips.h"                     // bstrip
    78 #include "srchpath.h"                   // searchpath
     80#include "srchpath.h"                   // Search*Path*ForFile
    7981#include "stristr.h"                    // stristr
    8082#include "delims.h"                     // to_delim
     
    376378  arcsigs_trailer_line_num = 0;
    377379
    378   //DosEnterCritSec(); //GKY 11-29-08
    379   DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
    380   psz = searchpath(PCSZ_ARCHIVERBB2);
    381   if (!psz || !*psz) {
     380  {
     381    CHAR szFullFilename[CCHMAXPATH];
     382
     383    DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
     384    if (SearchMultiplePathsForFile(PCSZ_ARCHIVERBB2, szFullFilename)) {
     385      DosReleaseMutexSem(hmtxFM2Globals);
     386      return -1;
     387    }
     388    stat(szFullFilename, &Archiverbb2Stats);
     389    fp = xfsopen(szFullFilename, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
    382390    DosReleaseMutexSem(hmtxFM2Globals);
    383     //DosExitCritSec();
    384     return -1;
     391    if (!fp)
     392      return -2;
     393    strcpy(archiverbb2, szFullFilename);                // Remember full path
    385394  }
    386   stat(psz, &Archiverbb2Stats);
    387   fp = xfsopen(psz, moder, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
    388   DosReleaseMutexSem(hmtxFM2Globals);
    389   //DosExitCritSec();
    390   if (!fp)
    391     return -2;
    392   strcpy(archiverbb2, psz);             // Remember full path
    393395
    394396  cur_line_num = 0;
     
    790792      struct stat Buffer;
    791793
    792       stat(searchpath(PCSZ_ARCHIVERBB2), &Buffer);
     794//      stat(searchpath(PCSZ_ARCHIVERBB2), &Buffer);
     795      stat(archiverbb2, &Buffer);   // jbs: Re-use full name set by load_achivers
    793796      if (Archiverbb2Stats.st_size != Buffer.st_size ||
    794           Archiverbb2Stats.st_mtime != Buffer.st_mtime)       
    795         if (saymsg(MB_YESNO,                                   
     797          Archiverbb2Stats.st_mtime != Buffer.st_mtime)
     798        if (saymsg(MB_YESNO,
    796799                   hwnd,
    797800                   GetPString(IDS_ADCHANGESONDISKTEXT),
     
    887890                   GetPString(IDS_ADCHANGESINMEMTEXT),
    888891                   GetPString(IDS_ADREWRITETEXT), NullStr) == MBID_YES) {
    889           PSZ ab2 = searchpath(PCSZ_ARCHIVERBB2);       // Rewrite without prompting
    890 
    891           rewrite_archiverbb2(ab2);
     892// 524    PSZ ab2 = searchpath(PCSZ_ARCHIVERBB2);       // Rewrite without prompting
     893
     894          rewrite_archiverbb2(archiverbb2);  // jbs: Re-use full path set by load_archivers
    892895        }
    893896      }
  • trunk/dll/avv.c

    r1746 r1750  
    3434  24 Feb 14 JBS Ticket #517: Replaced a call to DosQueryAppType to a call to the wrapped xDosQueryApptType
    3535  24 Feb 14 JBS Ticket #523: Stop considering missing "list", "create" or "extract" commands as errors
     36  01 Mar 14 JBS Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.
     37                So calls to these functions had to be changed and checkfile's signature was changed.
    3638
    3739***********************************************************************/
     
    6466#include "strips.h"                     // bstrip
    6567#include "misc.h"                       // CheckDriveSpaceAvail
    66 #include "srchpath.h"                   // searchpath
     68#include "srchpath.h"                   // Search*Path*ForFile
    6769#include "systemf.h"                    // runemf2
    6870#include "fortify.h"
     
    7375static PSZ pszSrcFile = __FILE__;
    7476
    75 static PSZ checkfile(PSZ file, INT * error);
     77static ULONG checkfile(PSZ file);
    7678static BOOL check_archiver(HWND hwnd, ARC_TYPE * info);
    7779static INT get_int_from_window(HWND hwnd, USHORT id);
     
    393395}
    394396
    395 static PSZ checkfile(PSZ file, INT * error)
    396 {
    397   CHAR *p, *pp = NULL;
    398   INT ret;
     397/**
     398 * checkfile: Determine if a program is reachable and of an acceptable type.
     399 *
     400 * @param pFilename: the name of a program file to check (input)
     401 *
     402 * @return 0 if the program reachable and of an acceptable type
     403 *         1 if the program is unreachable (or pFilename is invalid)
     404 *         2 if the program is of an unacceptable type
     405 *         3 if pFilename is null or points to a null string
     406 *
     407 */
     408static ULONG checkfile(PSZ file)
     409{
     410  CHAR szFullFilename[CCHMAXPATH], *pp = NULL;
     411  ULONG ret;
    399412  ULONG apptype;
    400413
    401414  if (!file || !*file) {
    402     *error = 3;
    403     return NULL;
     415    return 3;
    404416  }
    405417  pp = strchr(file, ' ');
    406418  if (pp)
    407419    *pp = 0;
    408   p = searchpath(file);
    409   if (!p || !*p)
    410     *error = 1;
     420  if (SearchPathForFile(PCSZ_PATH, file, szFullFilename)) {
     421    ret = 1;
     422  }
    411423  else {
    412     ret = (INT) xDosQueryAppType(p, &apptype);
     424    ret = xDosQueryAppType(szFullFilename, &apptype);
    413425    apptype &= (~FAPPTYP_32BIT);
    414426    if (!apptype ||
     
    417429        (apptype & FAPPTYP_BOUND) ||
    418430        (apptype & FAPPTYP_WINDOWAPI) || (apptype & FAPPTYP_DOS)) {
    419        *error = 0;
     431       ret = 0;
    420432     }
    421433     else
    422        *error = 2;
     434       ret = 2;
    423435  }
    424436  if (pp)
    425437    *pp = ' ';
    426   return p;
     438  return ret;
    427439}
    428440
     
    444456    badPos = TRUE;
    445457  if (info->list)
    446     checkfile(info->list, &badList);
     458    badList = checkfile(info->list);
    447459  if (info->create)
    448     checkfile(info->create, &badCreate);
     460    badCreate = checkfile(info->create);
    449461  if (info->extract)
    450     checkfile(info->extract, &badExtract);
     462    badExtract = checkfile(info->extract);
    451463  if (!noStart && !noEnd && !badPos && !badList && !badCreate && !badExtract)
    452464    return TRUE;                        // OK
     
    927939            MBID_YES) {
    928940
    929           PSZ ab2;
    930 
    931           ab2 = searchpath(PCSZ_ARCHIVERBB2);   // Rewrite without alerting
    932           rewrite_archiverbb2(ab2);
     941//        PSZ ab2;
     942
     943//        ab2 = searchpath(PCSZ_ARCHIVERBB2);   // Rewrite without alerting
     944          rewrite_archiverbb2(archiverbb2);  // jbs: Re-use path set by load_archivers
    933945        }
    934946      }
  • trunk/dll/cmdline.c

    r1749 r1750  
    437437          *p = 0;
    438438        if (IsFile(executable) == -1) {
    439           p = searchpath(executable);
    440           if (*p)
    441             strcpy(executable, p);
    442           else {
     439//        p = searchpath(executable);
     440//        if (*p)
     441          if (SearchPathForFile(PCSZ_PATH, executable, executable))     // jbs: OK to have same source and destination?
     442//          strcpy(executable, p);
     443//        else {
    443444            WinSetDlgItemText(hwnd,
    444445                              EXEC_WARNING2,
    445446                              (CHAR *) GetPString(IDS_CANTFINDFILETEXT));
    446447            break;
    447           }
     448//        }
    448449        }
    449450      }
  • trunk/dll/init.c

    r1743 r1750  
    124124  23 Feb 14 JBS Ticket #515: Corrected a mis-coded call to strtol which was causing the traps
    125125                described in this ticket. (Also changed it to strtoul.)
     126  01 Mar 14 JBS Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.
     127                So calls to these functions had to be changed.
    126128
    127129***********************************************************************/
     
    196198#include "strips.h"                     // bstrip
    197199#include "killproc.h"                   // GetDosPgmName
    198 #include "srchpath.h"                   // searchpath
     200#include "srchpath.h"                   // Search*Path*ForFile
    199201#include "fortify.h"
    200202#include "excputil.h"                   // xbeginthread
     
    898900    }
    899901    else {
    900       env = searchpath(profile);
    901       if (!env)
    902         env = profile;
    903       strcpy(inipath, env);
     902      CHAR szFullFilename[CCHMAXPATH];
     903      if (!SearchMultiplePathsForFile(profile, szFullFilename)) {
     904        strcpy(inipath, szFullFilename);
     905      } else {
     906        strcpy(inipath, profile);
     907      }
    904908    } //fixme the DosCopies probably fail if the INI isn't in the FM2 directory GKY 06 Aug 11
    905909    if (!*inipath)
     
    12111215  }
    12121216  { // Check for the existance of various partitioning tools to set up menu items
    1213     CHAR *FullPath;
    12141217    ULONG ulAppType;
    12151218
    1216     FullPath = searchapath(PCSZ_PATH, PCSZ_LVMGUICMD);
    1217     if (*FullPath)
     1219    if (!SearchPathForFile(PCSZ_PATH, PCSZ_LVMGUICMD, NULL))
    12181220      fLVMGui = TRUE;
    12191221    if (!xDosQueryAppType(PCSZ_DFSOS2EXE, &ulAppType))
  • trunk/dll/pathutil.c

    r1699 r1750  
    1919  23 Oct 10 GKY Add ForwardslashToBackslash function to streamline code
    2020  17 Sep 11 GKY Fix commandline quoting issues
     21  01 Mar 14 JBS Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.
     22                So calls to these functions had to be changed.
    2123
    2224***********************************************************************/
     
    3335#include "init.h"                       // Data declaration(s)
    3436#include "fm3str.h"
    35 #include "srchpath.h"                   // searchapath
     37#include "srchpath.h"                   // Search*Path*ForFile
    3638#include "pathutil.h"
    3739#include "strips.h"                     // remove_first_occurence_of_character
     
    157159  ULONG ulAppType;
    158160  char *pszChar;
    159   char *FullPath;
    160161  PSZ pszNewCmdLine = pszWorkBuf;
    161162
     
    210211               pszCmdLine_);
    211212      if (!offsetexe && !offsetcom) {
    212         FullPath = searchapath(PCSZ_PATH, szCmdLine);
    213         if (*FullPath)
    214           ret = 0;
     213        if (!SearchPathForFile(PCSZ_PATH, szCmdLine, NULL))
     214          ret = 0;
    215215      }
    216216      else
     
    257257            *offset = 0;
    258258            strcat(szCmdLine, PCSZ_DOTCMD);
    259             FullPath = searchapath(PCSZ_PATH, szCmdLine);
    260             if (*FullPath)
     259            if (!SearchPathForFile(PCSZ_PATH, szCmdLine, NULL))
    261260              ret = 0;
    262261            else {
    263262              *offset = 0;
    264263              strcat(szCmdLine, PCSZ_DOTBAT);
    265               FullPath = searchapath(PCSZ_PATH, szCmdLine);
    266               if (*FullPath)
     264              if (!SearchPathForFile(PCSZ_PATH, szCmdLine, NULL))
    267265                ret = 0;
    268266              else {
    269267                *offset = 0;
    270268                strcat(szCmdLine, PCSZ_DOTBTM);
    271                 FullPath = searchapath(PCSZ_PATH, szCmdLine);
    272                 if (*FullPath)
     269                if (!SearchPathForFile(PCSZ_PATH, szCmdLine, NULL))
    273270                  ret = 0;
    274271              }
     
    296293                *offset = 0;
    297294                strcat(szCmdLine, PCSZ_DOTCMD);
    298                 FullPath = searchapath(PCSZ_PATH, szCmdLine);
    299                 if (*FullPath) {
     295                if (!SearchPathForFile(PCSZ_PATH, szCmdLine, NULL)) {
    300296                  ret = 0;
    301297                  break;
     
    304300                  *offset = 0;
    305301                  strcat(szCmdLine, PCSZ_DOTBAT);
    306                   FullPath = searchapath(PCSZ_PATH, szCmdLine);
    307                   if (*FullPath) {
     302                  if (!SearchPathForFile(PCSZ_PATH, szCmdLine, NULL)) {
    308303                    ret = 0;
    309304                    break;
     
    312307                    *offset = 0;
    313308                    strcat(szCmdLine, PCSZ_DOTBTM);
    314                     FullPath = searchapath(PCSZ_PATH, szCmdLine);
    315                     if (*FullPath) {
     309                    if (!SearchPathForFile(PCSZ_PATH, szCmdLine, NULL)) {
    316310                      ret = 0;
    317311                      break;
     
    372366             GetPString(IDS_QUOTESINARGSTEXT),
    373367             pszCmdLine_);
    374     FullPath = searchapath(PCSZ_PATH, szCmdLine);
    375368    BldQuotedFileName(pszNewCmdLine, szCmdLine);
    376     if (!*FullPath) {
     369    if (SearchPathForFile(PCSZ_PATH, szCmdLine, NULL)) {
    377370      ret = saymsg(MB_YESNO,
    378371                   HWND_DESKTOP,
  • 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)
  • trunk/dll/srchpath.h

    r1398 r1750  
    1212
    1313  04 Oct 08 JBS Make searchapath function non-static
     14  01 Mar 14 JBS Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.
     15
    1416***********************************************************************/
    1517
     
    1820
    1921INT RunFM2Util(PCSZ appname, CHAR *filename);
    20 CHAR *searchapath(PCSZ path, PCSZ filename);
    21 CHAR *searchpath(PCSZ filename);
    22 
     22APIRET SearchPathForFile(PCSZ pPathname,
     23                         PCSZ pFilename,
     24                         PCHAR pFullFilename);
     25APIRET SearchMultiplePathsForFile(PCSZ pFilename,
     26                                  PSZ pFullFilename);
    2327
    2428#endif // SRCHPATH_H
  • trunk/dll/tools.c

    r1673 r1750  
    2525  08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
    2626  17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
     27  01 Mar 14 JBS Ticket #524: Made "searchapath" thread-safe. Function names and signatures were changed.
     28                So calls to these functions had to be changed.
    2729
    2830***********************************************************************/
     
    5456#include "wrappers.h"                   // xfgets
    5557#include "misc.h"                       // CheckDriveSpaceAvail
    56 #include "srchpath.h"                   // searchpath
     58#include "srchpath.h"                   // Search*Path*ForFile
    5759#include "stristr.h"                    // stristr
    5860#include "valid.h"                      // IsFile
     
    141143  FILE *fp;
    142144  CHAR help[80], text[80], flagstr[80], idstr[80], *fname;
     145  CHAR szFullFilename[CCHMAXPATH];
    143146  TOOL *info;
    144147  CHAR *moder = "r";
     
    150153  if (!filename || !*filename)
    151154    filename = (*lasttoolbar) ? lasttoolbar : "CMDS.TLS";
    152   if (*filename)
    153     fname = searchpath(filename);
    154   if (!fname || !*fname)
    155     fname = (PSZ) PCSZ_FM3TOOLSDAT;
     155  if (SearchMultiplePathsForFile(filename, szFullFilename)) {
     156    if (SearchMultiplePathsForFile(PCSZ_FM3TOOLSDAT, szFullFilename))
     157      fname = NULL;
     158    else
     159      fname = szFullFilename;
     160  }
     161  else
     162    fname = szFullFilename;
    156163  if (fname && *fname) {
    157164    filename = fname;
     
    214221{
    215222  FILE *fp;
    216   CHAR *fname;
    217223  TOOL *info;
    218224  CHAR *modew = "w";
     225  CHAR szFullFilename[CCHMAXPATH];
    219226
    220227  if (!filename)
    221228    filename = lasttoolbar;
    222   if (*filename)
    223     fname = searchpath(filename);
    224   if (fname && *fname)
    225     filename = fname;
     229  if (!SearchMultiplePathsForFile(filename, szFullFilename))
     230    filename = szFullFilename;
    226231  else {
    227232    if (*lasttoolbar)
    228233      filename = lasttoolbar;
    229234    else
    230       filename = "FM3TOOLS.TLS";
    231     fname = searchpath(filename);
    232     if (fname && *fname)
    233       filename = fname;
     235      filename = "FM3TOOLS.TLS";        // jbs: Why not PCSZ_FM3TOOLSDAT?
     236    if (!SearchMultiplePathsForFile(filename, szFullFilename))
     237      filename = szFullFilename;
    234238  }
    235239
    236240  if (stristr(filename, PCSZ_FM3TOOLSDAT))
    237     filename = "FM3TOOLS.TLS";
     241    filename = "FM3TOOLS.TLS";          // jbs: Why not PCSZ_FM3TOOLSDAT?
     242  // jbs: Why save full name for toolbar files that are not FM3TOOLS.DAT?
    238243  if (toolhead && filename && *filename) {
    239244    strcpy(lasttoolbar, filename);
     
    956961      HDIR hDir;
    957962      ULONG ulSearchCount, x = 0;
    958       CHAR *masks[] = { "*.TLS", "FM3TOOLS.DAT", NULL };
     963      CHAR *masks[] = { "*.TLS", "FM3TOOLS.DAT", NULL };        // jbs: Why not PCSZ_FM3TOOLSDAT?
    959964
    960965      if (mp2)
Note: See TracChangeset for help on using the changeset viewer.