Ignore:
Timestamp:
Jan 1, 2001, 4:30:29 PM (25 years ago)
Author:
umoeller
Message:

Tons of updates.

File:
1 edited

Legend:

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

    r17 r18  
    552552 *      If "VARNAME" has already been set to something
    553553 *      in the string array in pEnv, that array item
    554  *      is replaced. Otherwise a new item is added to
    555  *      the array, and pEnv->cVars is raised by one.
     554 *      is replaced.
     555 *
     556 *      OTOH, if "VARNAME" has not been set yet, a new
     557 *      item is added to the array, and pEnv->cVars is
     558 *      raised by one. In that case, fAddFirst determines
     559 *      whether the new array item is added to the front
     560 *      or the tail of the environment list.
    556561 *
    557562 *@@added V0.9.4 (2000-07-19) [umoeller]
     563 *@@changed V0.9.7 (2000-12-17) [umoeller]: added fAddFirst
    558564 */
    559565
    560566APIRET doshSetEnvironmentVar(PDOSENVIRONMENT pEnv,
    561                              PSZ pszNewEnv)
     567                             PSZ pszNewEnv,
     568                             BOOL fAddFirst)
    562569{
    563570    APIRET  arc = NO_ERROR;
     
    576583                free(*ppszEnvLine);
    577584                *ppszEnvLine = strdup(pszNewEnv);
     585                if (!(*ppszEnvLine))
     586                    arc = ERROR_NOT_ENOUGH_MEMORY;
    578587            }
    579588            else
    580589            {
    581                 PSZ *ppszNew;
    582                 PSZ *papszNew;
     590                PSZ *ppszNew = NULL;
     591                PSZ *papszNew = NULL;
    583592                // not set already:
    584                 // append
    585                 // reallocate array and add new string
    586                 papszNew = (PSZ*)realloc(pEnv->papszVars, sizeof(PSZ) * (pEnv->cVars + 1));
     593                if (fAddFirst)
     594                {
     595                    // add as first entry:
     596                    papszNew = (PSZ*)malloc(sizeof(PSZ) * (pEnv->cVars + 1));
     597                    // overwrite first entry
     598                    ppszNew = papszNew;
     599                    // copy old entries
     600                    memcpy(papszNew + 1,                // second new entry
     601                           pEnv->papszVars,             // first old entry
     602                           sizeof(PSZ) * pEnv->cVars);
     603                }
     604                else
     605                {
     606                    // append at the tail:
     607                    // reallocate array and add new string
     608                    papszNew = (PSZ*)realloc(pEnv->papszVars,
     609                                             sizeof(PSZ) * (pEnv->cVars + 1));
     610                    // overwrite last entry
     611                    ppszNew = papszNew + pEnv->cVars;
     612                }
     613
    587614                if (!papszNew)
    588615                    arc = ERROR_NOT_ENOUGH_MEMORY;
     
    590617                {
    591618                    pEnv->papszVars = papszNew;
    592                     ppszNew = pEnv->papszVars + pEnv->cVars;
    593619                    pEnv->cVars++;
    594620                    *ppszNew = strdup(pszNewEnv);
     
    618644APIRET doshConvertEnvironment(PDOSENVIRONMENT pEnv,
    619645                              PSZ *ppszEnv,     // out: environment string
    620                               PULONG pulSize)  // out: size of block allocated in *ppszEnv
     646                              PULONG pulSize)  // out: size of block allocated in *ppszEnv; ptr can be NULL
    621647{
    622648    APIRET  arc = NO_ERROR;
     
    652678            {
    653679                PSZ     pTarget = *ppszEnv;
    654                 *pulSize = cbNeeded;
     680                if (pulSize)
     681                    *pulSize = cbNeeded;
    655682                ppszThis = pEnv->papszVars;
    656683
     
    831858                            // specified in header
    832859                            arc = DosSetFilePtr(hFile,
    833                                                 (*ppExec)->pDosExeHeader->usNewHeaderOfs,
     860                                                (*ppExec)->pDosExeHeader->ulNewHeaderOfs,
    834861                                                FILE_BEGIN,
    835862                                                &ulLocal);
     
    847874                                // reset file ptr
    848875                                DosSetFilePtr(hFile,
    849                                               (*ppExec)->pDosExeHeader->usNewHeaderOfs,
     876                                              (*ppExec)->pDosExeHeader->ulNewHeaderOfs,
    850877                                              FILE_BEGIN,
    851878                                              &ulLocal);
Note: See TracChangeset for help on using the changeset viewer.