Changeset 18 for trunk/src/helpers/dosh2.c
- Timestamp:
- Jan 1, 2001, 4:30:29 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/dosh2.c
r17 r18 552 552 * If "VARNAME" has already been set to something 553 553 * 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. 556 561 * 557 562 *@@added V0.9.4 (2000-07-19) [umoeller] 563 *@@changed V0.9.7 (2000-12-17) [umoeller]: added fAddFirst 558 564 */ 559 565 560 566 APIRET doshSetEnvironmentVar(PDOSENVIRONMENT pEnv, 561 PSZ pszNewEnv) 567 PSZ pszNewEnv, 568 BOOL fAddFirst) 562 569 { 563 570 APIRET arc = NO_ERROR; … … 576 583 free(*ppszEnvLine); 577 584 *ppszEnvLine = strdup(pszNewEnv); 585 if (!(*ppszEnvLine)) 586 arc = ERROR_NOT_ENOUGH_MEMORY; 578 587 } 579 588 else 580 589 { 581 PSZ *ppszNew ;582 PSZ *papszNew ;590 PSZ *ppszNew = NULL; 591 PSZ *papszNew = NULL; 583 592 // 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 587 614 if (!papszNew) 588 615 arc = ERROR_NOT_ENOUGH_MEMORY; … … 590 617 { 591 618 pEnv->papszVars = papszNew; 592 ppszNew = pEnv->papszVars + pEnv->cVars;593 619 pEnv->cVars++; 594 620 *ppszNew = strdup(pszNewEnv); … … 618 644 APIRET doshConvertEnvironment(PDOSENVIRONMENT pEnv, 619 645 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 621 647 { 622 648 APIRET arc = NO_ERROR; … … 652 678 { 653 679 PSZ pTarget = *ppszEnv; 654 *pulSize = cbNeeded; 680 if (pulSize) 681 *pulSize = cbNeeded; 655 682 ppszThis = pEnv->papszVars; 656 683 … … 831 858 // specified in header 832 859 arc = DosSetFilePtr(hFile, 833 (*ppExec)->pDosExeHeader->u sNewHeaderOfs,860 (*ppExec)->pDosExeHeader->ulNewHeaderOfs, 834 861 FILE_BEGIN, 835 862 &ulLocal); … … 847 874 // reset file ptr 848 875 DosSetFilePtr(hFile, 849 (*ppExec)->pDosExeHeader->u sNewHeaderOfs,876 (*ppExec)->pDosExeHeader->ulNewHeaderOfs, 850 877 FILE_BEGIN, 851 878 &ulLocal);
Note:
See TracChangeset
for help on using the changeset viewer.