Ignore:
Timestamp:
Oct 13, 2001, 7:57:58 PM (24 years ago)
Author:
umoeller
Message:

Lots of updates from the last week for conditional compiles and other stuff.

File:
1 edited

Legend:

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

    r105 r108  
    6969#pragma hdrstop
    7070
    71 static const CHAR  G_acDriveLetters[28] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     71// static const CHAR  G_acDriveLetters[28] = " ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    7272
    7373/*
     
    703703            PFSQBUFFER2 pfsqBuffer = (PFSQBUFFER2)fsqBuffer;
    704704
    705             szName[0] = G_acDriveLetters[ulLogicalDrive];
     705            szName[0] = ulLogicalDrive + 'A' - 1;
    706706            szName[1] = ':';
    707707            szName[2] = '\0';
     
    753753                    &ulBootDrive,
    754754                    sizeof(ulBootDrive));
    755     return (G_acDriveLetters[ulBootDrive]);
     755    return (ulBootDrive + 'A' - 1);
    756756}
    757757
     
    10341034 *@@changed V0.9.1 (99-12-12) [umoeller]: added cbBuf to prototype
    10351035 *@@changed V0.9.14 (2001-08-01) [umoeller]: fixed, this never respected cbBuf
     1036 *@@changed V0.9.16 (2001-10-02) [umoeller]: added check for valid logical disk no
    10361037 */
    10371038
     
    10481049
    10491050    // compose "D:"-type string from logical drive letter
    1050     szName[0] = G_acDriveLetters[ulLogicalDrive];
    1051     szName[1] = ':';
    1052     szName[2] = '\0';
    1053 
    1054     arc = DosQueryFSAttach(szName,          // logical drive of attached FS ("D:"-style)
    1055                            0,               // ulOrdinal, ignored for FSAIL_QUERYNAME
    1056                            FSAIL_QUERYNAME, // return name for a drive or device
    1057                            pfsqBuffer,      // buffer for returned data
    1058                            &cbBuffer);      // sizeof(*pfsqBuffer)
    1059 
    1060     if (arc == NO_ERROR)
    1061     {
    1062         if (pszBuf)
     1051    if (ulLogicalDrive > 0 && ulLogicalDrive < 27)
     1052    {
     1053        szName[0] = ulLogicalDrive + 'A' - 1;
     1054        szName[1] = ':';
     1055        szName[2] = '\0';
     1056
     1057        arc = DosQueryFSAttach(szName,          // logical drive of attached FS ("D:"-style)
     1058                               0,               // ulOrdinal, ignored for FSAIL_QUERYNAME
     1059                               FSAIL_QUERYNAME, // return name for a drive or device
     1060                               pfsqBuffer,      // buffer for returned data
     1061                               &cbBuffer);      // sizeof(*pfsqBuffer)
     1062
     1063        if (arc == NO_ERROR)
    10631064        {
    1064             // The data for the last three fields in the FSQBUFFER2
    1065             // structure are stored at the offset of fsqBuffer.szName.
    1066             // Each data field following fsqBuffer.szName begins
    1067             // immediately after the previous item.
    1068             strncpy(pszBuf,
    1069                     (CHAR*)(&pfsqBuffer->szName) + pfsqBuffer->cbName + 1,
    1070                     cbBuf);         // V0.9.14 (2001-08-01) [umoeller]
    1071             *(pszBuf + cbBuf) = '\0';
     1065            if (pszBuf)
     1066            {
     1067                // The data for the last three fields in the FSQBUFFER2
     1068                // structure are stored at the offset of fsqBuffer.szName.
     1069                // Each data field following fsqBuffer.szName begins
     1070                // immediately after the previous item.
     1071                strncpy(pszBuf,
     1072                        (CHAR*)(&pfsqBuffer->szName) + pfsqBuffer->cbName + 1,
     1073                        cbBuf);         // V0.9.14 (2001-08-01) [umoeller]
     1074                *(pszBuf + cbBuf) = '\0';
     1075            }
    10721076        }
    10731077    }
     1078    else
     1079        arc = ERROR_INVALID_PARAMETER; // V0.9.16 (2001-10-02) [umoeller]
    10741080
    10751081    return (arc);
     
    18831889        ULONG   cbWritten;
    18841890        DosGetDateTime(&dt);
    1885         sprintf(szTemp, "Time: %02d:%02d:%02d %s",
    1886             dt.hours, dt.minutes, dt.seconds,
    1887             pcsz);
     1891        sprintf(szTemp,
     1892                "Time: %02d:%02d:%02d %s",
     1893                dt.hours, dt.minutes, dt.seconds,
     1894                pcsz);
    18881895        return (DosWrite(hfLog, (PVOID)szTemp, strlen(szTemp), &cbWritten));
    18891896    }
     
    20002007    ULONG   ulCurDisk = 0;
    20012008    ULONG   ulMap = 0;
    2002     arc = DosQueryCurrentDisk(&ulCurDisk, &ulMap);
    2003     if (arc == NO_ERROR)
     2009    if (!(arc = DosQueryCurrentDisk(&ulCurDisk, &ulMap)))
    20042010    {
    20052011        ULONG   cbBuf = CCHMAXPATH - 3;
    2006         *pszBuf = G_acDriveLetters[ulCurDisk];
     2012        *pszBuf = ulCurDisk + 'A' - 1;
    20072013        *(pszBuf + 1) = ':';
    20082014        *(pszBuf + 2) = '\\';
     
    22702276
    22712277        // resolve DosPerfSysCall API entry
    2272         arc = DosLoadModule(NULL, 0, "DOSCALLS", &pPerfSys->hmod);
    2273         if (arc == NO_ERROR)
     2278        if (!(arc = DosLoadModule(NULL, 0, "DOSCALLS", &pPerfSys->hmod)))
    22742279        {
    2275             arc = DosQueryProcAddr(pPerfSys->hmod,
    2276                                    976,
    2277                                    "DosPerfSysCall",
    2278                                    (PFN*)(&pPerfSys->pDosPerfSysCall));
    2279             if (arc == NO_ERROR)
     2280            if (!(arc = DosQueryProcAddr(pPerfSys->hmod,
     2281                                         976,
     2282                                         "DosPerfSysCall",
     2283                                         (PFN*)(&pPerfSys->pDosPerfSysCall))))
    22802284            {
    22812285                // OK, we got the API: initialize!
    2282                 arc = pPerfSys->pDosPerfSysCall(CMD_KI_ENABLE, 0, 0, 0);
    2283                 if (arc == NO_ERROR)
     2286                if (!(arc = pPerfSys->pDosPerfSysCall(CMD_KI_ENABLE, 0, 0, 0)))
    22842287                {
    22852288                    pPerfSys->fInitialized = TRUE;
    22862289                            // call CMD_KI_DISABLE later
    22872290
    2288                     arc = pPerfSys->pDosPerfSysCall(CMD_PERF_INFO,
    2289                                                     0,
    2290                                                     (ULONG)(&pPerfSys->cProcessors),
    2291                                                     0);
    2292                     if (arc == NO_ERROR)
     2291                    if (!(arc = pPerfSys->pDosPerfSysCall(CMD_PERF_INFO,
     2292                                                          0,
     2293                                                          (ULONG)(&pPerfSys->cProcessors),
     2294                                                          0)))
    22932295                    {
    2294                         ULONG   ul = 0;
     2296                        ULONG   ul = 0,
     2297                                cProcs = pPerfSys->cProcessors,
     2298                                cbDouble = cProcs * sizeof(double),
     2299                                cbLong = cProcs * sizeof(LONG);
    22952300
    22962301                        // allocate arrays
    2297                         pPerfSys->paCPUUtils = (PCPUUTIL)calloc(pPerfSys->cProcessors,
    2298                                                                 sizeof(CPUUTIL));
    2299                         if (!pPerfSys->paCPUUtils)
     2302                        if (    (!(pPerfSys->paCPUUtils = (PCPUUTIL)calloc(cProcs,
     2303                                                                sizeof(CPUUTIL))))
     2304                             || (!(pPerfSys->padBusyPrev
     2305                                    = (double*)malloc(cbDouble)))
     2306                             || (!(pPerfSys->padTimePrev
     2307                                    = (double*)malloc(cbDouble)))
     2308                             || (!(pPerfSys->padIntrPrev
     2309                                    = (double*)malloc(cbDouble)))
     2310                             || (!(pPerfSys->palLoads
     2311                                    = (PLONG)malloc(cbLong)))
     2312                             || (!(pPerfSys->palIntrs
     2313                                    = (PLONG)malloc(cbLong)))
     2314                           )
    23002315                            arc = ERROR_NOT_ENOUGH_MEMORY;
    23012316                        else
    23022317                        {
    2303                             pPerfSys->padBusyPrev = (double*)malloc(pPerfSys->cProcessors * sizeof(double));
    2304                             if (!pPerfSys->padBusyPrev)
    2305                                 arc = ERROR_NOT_ENOUGH_MEMORY;
    2306                             else
     2318                            for (ul = 0; ul < cProcs; ul++)
    23072319                            {
    2308                                 pPerfSys->padTimePrev
    2309                                     = (double*)malloc(pPerfSys->cProcessors * sizeof(double));
    2310                                 if (!pPerfSys->padTimePrev)
    2311                                     arc = ERROR_NOT_ENOUGH_MEMORY;
    2312                                 else
    2313                                 {
    2314                                     pPerfSys->padIntrPrev
    2315                                         = (double*)malloc(pPerfSys->cProcessors * sizeof(double));
    2316                                     if (!pPerfSys->padIntrPrev)
    2317                                         arc = ERROR_NOT_ENOUGH_MEMORY;
    2318                                     else
    2319                                     {
    2320                                         pPerfSys->palLoads = (PLONG)malloc(pPerfSys->cProcessors * sizeof(LONG));
    2321                                         if (!pPerfSys->palLoads)
    2322                                             arc = ERROR_NOT_ENOUGH_MEMORY;
    2323                                         else
    2324                                         {
    2325                                             pPerfSys->palIntrs = (PLONG)malloc(pPerfSys->cProcessors * sizeof(LONG));
    2326                                             if (!pPerfSys->palIntrs)
    2327                                                 arc = ERROR_NOT_ENOUGH_MEMORY;
    2328                                             else
    2329                                             {
    2330                                                 for (ul = 0; ul < pPerfSys->cProcessors; ul++)
    2331                                                 {
    2332                                                     pPerfSys->padBusyPrev[ul] = 0.0;
    2333                                                     pPerfSys->padTimePrev[ul] = 0.0;
    2334                                                     pPerfSys->padIntrPrev[ul] = 0.0;
    2335                                                     pPerfSys->palLoads[ul] = 0;
    2336                                                     pPerfSys->palIntrs[ul] = 0;
    2337                                                 }
    2338                                             }
    2339                                         }
    2340                                     }
    2341                                 }
     2320                                pPerfSys->padBusyPrev[ul] = 0.0;
     2321                                pPerfSys->padTimePrev[ul] = 0.0;
     2322                                pPerfSys->padIntrPrev[ul] = 0.0;
     2323                                pPerfSys->palLoads[ul] = 0;
     2324                                pPerfSys->palIntrs[ul] = 0;
    23422325                            }
    23432326                        }
     
    23472330        } // end if (arc == NO_ERROR)
    23482331
    2349         if (arc != NO_ERROR)
    2350         {
     2332        if (arc)
     2333            // error: clean up
    23512334            doshPerfClose(ppPerfSys);
    2352         }
     2335
    23532336    } // end else if (!*ppPerfSys)
    23542337
     
    24052388    else
    24062389    {
    2407         arc = pPerfSys->pDosPerfSysCall(CMD_KI_RDCNT,
    2408                                         (ULONG)pPerfSys->paCPUUtils,
    2409                                         0, 0);
    2410         if (arc == NO_ERROR)
     2390        if (!(arc = pPerfSys->pDosPerfSysCall(CMD_KI_RDCNT,
     2391                                              (ULONG)pPerfSys->paCPUUtils,
     2392                                              0, 0)))
    24112393        {
    24122394            // go thru all processors
Note: See TracChangeset for help on using the changeset viewer.