Ignore:
Timestamp:
Apr 6, 2001, 7:12:11 PM (24 years ago)
Author:
umoeller
Message:

misc changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/helpers/dosh.c

    r54 r55  
    144144}
    145145
    146 
    147146/*
    148147 *@@ doshIsWarp4:
    149  *      returns TRUE only if at least OS/2 Warp 4 is running.
     148 *      checks the OS/2 system version number.
     149 *
     150 *      Returns:
     151 *
     152 *      -- 0 (FALSE): OS/2 2.x or Warp 3 is running.
     153 *
     154 *      -- 1: Warp 4.0 is running.
     155 *
     156 *      -- 2: Warp 4.5 is running (WSeB or Warp 4 FP 13+ or eCS
     157 *            or ACP/MCP), or even something newer.
    150158 *
    151159 *@@changed V0.9.2 (2000-03-05) [umoeller]: reported TRUE on Warp 3 also; fixed
    152160 *@@changed V0.9.6 (2000-10-16) [umoeller]: patched for speed
    153  */
    154 
    155 BOOL doshIsWarp4(VOID)
    156 {
    157     static BOOL s_brc = FALSE;
    158     static BOOL s_fQueried = FALSE;
     161 *@@changed V0.9.9 (2001-04-04) [umoeller]: now returning 2 for Warp 4.5 and above
     162 */
     163
     164ULONG doshIsWarp4(VOID)
     165{
     166    static BOOL     s_fQueried = FALSE;
     167    static ULONG    s_ulrc = 0;
     168
    159169    if (!s_fQueried)
    160170    {
     
    170180
    171181        if     (    (aulBuf[0] > 20)        // major > 20; not the case with Warp 3, 4, 5
    172                  || (   (aulBuf[0] == 20)   // major == 20 and minor >= 40
    173                      && (aulBuf[1] >= 40)
     182                 || (   (aulBuf[0] == 20)   // major == 20 and minor >= 45
     183                     && (aulBuf[1] >= 45)
    174184                    )
    175185               )
    176             s_brc = TRUE;
     186            // Warp 4.5 or newer:
     187            s_ulrc = 2;
     188        else if (   (aulBuf[0] == 20)   // major == 20 and minor == 40
     189                 && (aulBuf[1] == 40)
     190                )
     191            // Warp 4:
     192            s_ulrc = 1;
    177193
    178194        s_fQueried = TRUE;
    179195    }
    180196
    181     return (s_brc);
     197    return (s_ulrc);
    182198}
    183199
     
    11421158
    11431159    return (strdup(szFilename));
     1160}
     1161
     1162/*
     1163 *@@ doshCreateTempFileName:
     1164 *      produces a file name in the the specified directory
     1165 *      or $(TEMP) which presently doesn't exist. This
     1166 *      checks the directory for existing files, but does
     1167 *      not open the temp file.
     1168 *
     1169 *      If (pcszDir != NULL), we look into that directory.
     1170 *      Otherwise we look into the directory specified
     1171 *      by the $(TEMP) environment variable.
     1172 *      If $(TEMP) is not set, $(TMP) is tried next.
     1173 *
     1174 *      If the directory thus specified does not exist, the
     1175 *      root directory of the boot drive is used instead.
     1176 *      As a result, this function should be fairly bomb-proof.
     1177 *
     1178 *      If (pcszExt != NULL), the temp file receives
     1179 *      that extension, or no extension otherwise.
     1180 *      Do not specify the dot in pcszExt.
     1181 *
     1182 *      pszTempFileName receives the fully qualified
     1183 *      file name of the temp file in that directory
     1184 *      and must point to a buffer CCHMAXPATH in size.
     1185 *      The file name is 8+3 compliant if pcszExt does
     1186 *      not exceed three characters.
     1187 *
     1188 *      If (pcszPrefix != NULL), the temp file name
     1189 *      is prefixed with pcszPrefix. Since the temp
     1190 *      file name must not exceed 8+3 letters, we
     1191 *      can only use ( 8 - strlen(pcszPrefix ) digits
     1192 *      for a random number to make the temp file name
     1193 *      unique. You must therefore use a maximum of
     1194 *      four characters for the prefix. Otherwise
     1195 *      ERROR_INVALID_PARAMETER is returned.
     1196 *
     1197 *      Example: Assuming TEMP is set to C:\TEMP,
     1198 +
     1199 +          dosCreateTempFileName(szBuffer,
     1200 +                                NULL,             // use $(TEMP)
     1201 +                                "pre",            // prefix
     1202 +                                "tmp")            // extension
     1203 +
     1204 *      would produce something like "C:\TEMP\pre07FG2.tmp".
     1205 *
     1206 *@@added V0.9.9 (2001-04-04) [umoeller]
     1207 */
     1208
     1209APIRET doshCreateTempFileName(PSZ pszTempFileName,        // out: fully q'fied temp file name
     1210                              const char *pcszDir,        // in: dir or NULL for %TEMP%
     1211                              const char *pcszPrefix,     // in: prefix for temp file or NULL
     1212                              const char *pcszExt)        // in: extension (without dot) or NULL
     1213{
     1214    APIRET      arc = NO_ERROR;
     1215
     1216    ULONG       ulPrefixLen = (pcszPrefix)
     1217                                    ? strlen(pcszPrefix)
     1218                                    : 0;
     1219
     1220    if (    (!pszTempFileName)
     1221         || (ulPrefixLen > 4)
     1222       )
     1223        arc = ERROR_INVALID_PARAMETER;
     1224    else
     1225    {
     1226        CHAR        szDir[CCHMAXPATH] = "";
     1227        FILESTATUS3 fs3;
     1228
     1229        const char  *pcszTemp = pcszDir;
     1230
     1231        if (!pcszTemp)
     1232        {
     1233            pcszTemp = getenv("TEMP");
     1234            if (!pcszTemp)
     1235                pcszTemp = getenv("TMP");
     1236        }
     1237
     1238        if (pcszTemp)       // either pcszDir or $(TEMP) or $(TMP) now
     1239            if (DosQueryPathInfo((PSZ)pcszTemp,
     1240                                 FIL_STANDARD,
     1241                                 &fs3,
     1242                                 sizeof(fs3)))
     1243                // TEMP doesn't exist:
     1244                pcszTemp = NULL;
     1245
     1246        if (!pcszTemp)
     1247            // not set, or doesn't exist:
     1248            // use root directory on boot drive
     1249            sprintf(szDir,
     1250                    "%c:\\",
     1251                    doshQueryBootDrive());
     1252        else
     1253        {
     1254            strcpy(szDir, pcszTemp);
     1255            if (szDir[strlen(szDir) - 1] != '\\')
     1256                strcat(szDir, "\\");
     1257        }
     1258
     1259        if (!szDir[0])
     1260            arc = ERROR_PATH_NOT_FOUND;     // shouldn't happen
     1261        else
     1262        {
     1263            ULONG       ulRandom = 0;
     1264            ULONG       cAttempts = 0;
     1265
     1266            // produce random number
     1267            DosQuerySysInfo(QSV_MS_COUNT,
     1268                            QSV_MS_COUNT,
     1269                            &ulRandom,
     1270                            sizeof(ulRandom));
     1271
     1272            do
     1273            {
     1274                CHAR szFile[20] = "",
     1275                     szFullTryThis[CCHMAXPATH];
     1276
     1277                // use the lower eight hex digits of the
     1278                // system uptime as the temp dir name
     1279                sprintf(szFile,
     1280                        "%08lX",
     1281                        ulRandom & 0xFFFFFFFF);
     1282
     1283                // if prefix is specified, overwrite the
     1284                // first characters in the random number
     1285                if (pcszPrefix)
     1286                    memcpy(szFile, pcszPrefix, ulPrefixLen);
     1287
     1288                if (pcszExt)
     1289                {
     1290                    szFile[8] = '.';
     1291                    strcpy(szFile + 9, pcszExt);
     1292                }
     1293
     1294                // now compose full temp file name
     1295                strcpy(szFullTryThis, szDir);
     1296                strcat(szFullTryThis, szFile);
     1297                // now we have: "C:\temp\wpiXXXXX"
     1298                if (DosQueryPathInfo(szFullTryThis,
     1299                                     FIL_STANDARD,
     1300                                     &fs3,
     1301                                     sizeof(fs3))
     1302                        == ERROR_FILE_NOT_FOUND)
     1303                {
     1304                    // file or dir doesn't exist:
     1305                    // cool, we're done
     1306                    strcpy(pszTempFileName, szFullTryThis);
     1307                    return (NO_ERROR);
     1308                }
     1309
     1310                // if this didn't work, raise ulRandom and try again
     1311                ulRandom += 123;
     1312
     1313                // try only 100 times, just to be sure
     1314                cAttempts++;
     1315            } while (cAttempts < 100);
     1316
     1317            // 100 loops elapsed:
     1318            arc = ERROR_BAD_FORMAT;
     1319        }
     1320    }
     1321
     1322    return (arc);
    11441323}
    11451324
Note: See TracChangeset for help on using the changeset viewer.