Changeset 3985 for branches/GRACE/src/win32k/ldr/myldrOpen.cpp
- Timestamp:
- Aug 11, 2000, 4:23:19 AM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GRACE/src/win32k/ldr/myldrOpen.cpp
r3834 r3985 1 /* $Id: myldrOpen.cpp,v 1.10.4. 1 2000-07-16 22:43:36bird Exp $1 /* $Id: myldrOpen.cpp,v 1.10.4.2 2000-08-11 02:23:19 bird Exp $ 2 2 * 3 3 * myldrOpen - ldrOpen. … … 74 74 75 75 /** @sketch 76 * Try open the file (that s why this function is called anyway)76 * Try open the file (that's why this function is called anyway) 77 77 */ 78 78 rc = ldrOpen(phFile, pszFilename, pfl); … … 97 97 { 98 98 char *pach; /* Pointer to the buffer as char. */ 99 unsigned long *pul; /* Pointer to the buffer as unsigned long. */ 99 100 PIMAGE_DOS_HEADER pMzHdr; /* Use the buffer as a dosheader. */ 100 101 PIMAGE_NT_HEADERS pNtHdrs; /* Use the buffer as a NT header. */ … … 251 252 } 252 253 else 254 { 253 255 kprintf(("myldrOpen-%d: Failed to allocate Pe2Lx object.\n", cNesting)); 254 255 goto cleanup; 256 rc = ERROR_NOT_ENOUGH_MEMORY; 257 } 258 259 goto cleanup; 256 260 } 257 261 … … 312 316 * ELF image? 313 317 */ 314 if ( u1.pach[0] == ELFMAG0 && u1.pach[1] == ELFMAG1 && u1.pach[2] == ELFMAG2 && u1.pach[3] == ELFMAG3)318 if (*u1.pul == ELFMAGICLSB) 315 319 { 316 320 if (isELFDisabled()) … … 332 336 * Java image? 333 337 */ 334 if ( u1.pach[0] == 0xCA && u1.pach[1] == 0xFE && u1.pach[2] == 0xBA && u1.pach[3] == 0xBE)338 if (*u1.pul == 0xBEBAFECAUL) //CAh FEh BAh BEh 335 339 { 336 340 if (isJAVADisabled()) … … 393 397 goto cleanup; 394 398 } 399 395 400 } 396 401 else … … 505 510 * Open the new executable file recursively. (psz) 506 511 */ 507 if (isLdrStateExecPgm()) 508 { 509 if (*psz2) 510 rc = AddArgsToFront(3, psz, psz2, achTkExecPgmFilename); 511 else 512 rc = AddArgsToFront(2, psz, achTkExecPgmFilename); 513 if (rc != NO_ERROR) 514 { 515 kprintf(("myldrOpen-%d: AddArgsToFront failed with rc=%d\n", cNesting)); 516 goto cleanup_noerror; 517 } 518 rc = SetExecName(psz); 519 if (rc != NO_ERROR) 520 kprintf(("myldrOpen-%d: SetExecName failed with rc=%d\n", cNesting)); 521 } 522 rc = myldrOpen(phFile, psz, pfl); 512 if (isLdrStateExecPgm()) 513 { 514 if (*psz2) 515 rc = AddArgsToFront(3, psz, psz2, achTkExecPgmFilename); 516 else 517 rc = AddArgsToFront(2, psz, achTkExecPgmFilename); 518 if (rc != NO_ERROR) 519 { 520 kprintf(("myldrOpen-%d: AddArgsToFront failed with rc=%d\n", cNesting)); 521 goto cleanup_noerror; 522 } 523 rc = SetExecName(psz); 524 if (rc != NO_ERROR) 525 kprintf(("myldrOpen-%d: SetExecName failed with rc=%d\n", cNesting)); 526 } 527 ldrClose(*phFile); 528 rc = myldrOpen(phFile, psz, pfl); 529 if (rc != NO_ERROR) 530 { 531 psz2 = psz + strlen(psz); 532 if (psz + 4 >= psz2 || strcmp(psz2 - 4, ".EXE") != 0) 533 { 534 strcpy(psz2, ".EXE"); 535 rc = myldrOpen(phFile, psz, pfl); 536 *psz2 = '\0'; 537 } 538 else 539 psz2 = NULL; 540 541 //should we search the PATH??? For a starting, we'll do it. 542 if (rc != NO_ERROR 543 && (rc = OpenPATH(phFile, psz, pfl)) != NO_ERROR 544 && psz2 != NULL) 545 { 546 *psz2 = '.'; 547 rc = OpenPATH(phFile, psz, pfl); 548 } 549 } 523 550 } 524 551 else … … 677 704 } 678 705 679 cchOldArgs =iSecondArg = strlen(&achTkExecPgmArguments[0]) + 1;680 psz = &achTkExecPgmArguments[ cchOldArgs];706 iSecondArg = strlen(&achTkExecPgmArguments[0]) + 1; 707 psz = &achTkExecPgmArguments[iSecondArg]; 681 708 while (*psz != '\0') 682 psz = &achTkExecPgmArguments[(cchOldArgs += strlen(psz) + 1)]; 709 psz += strlen(psz) + 1; 710 cchOldArgs = psz - &achTkExecPgmArguments[iSecondArg]; 683 711 684 712 va_start(vaarg, cArgs); … … 701 729 * !IMPORTANT! in this move as this have to be re-added in this call! !IMPORTANT! 702 730 */ 703 if (cchOldArgs + 1 + cchNewArgs> CCHARGUMENTS)731 if (cchOldArgs + cchNewArgs + 1 > CCHARGUMENTS) 704 732 { 705 733 kprintf(("AddArgsToFront: argument buffer is too small to hold the arguments to add, cchOldArgs=%d, cchNewArgs=%d\n", … … 708 736 } 709 737 710 if (cchOldArgs > 1)738 if (cchOldArgs > 0) 711 739 { 712 740 memmove(&achTkExecPgmArguments[cchNewArgs], &achTkExecPgmArguments[iSecondArg], 713 cchOldArgs - iSecondArg+ 1);741 cchOldArgs + 1); 714 742 } 715 743 else 716 achTkExecPgmArguments[cchNewArgs + 1] = '\0';744 achTkExecPgmArguments[cchNewArgs] = '\0'; 717 745 718 746 … … 727 755 va_start(vaarg, cArgs); 728 756 psz = va_arg(vaarg, char *); 729 iSecondArg = strlen(psz) + 1; 730 memcpy(&achTkExecPgmArguments[0], psz, iSecondArg); 731 732 psz = &achTkExecPgmArguments[iSecondArg]; 733 i = 2; /* one in advance to avoid a +1. */ 734 while (1) 735 { 757 memcpy(&achTkExecPgmArguments[0], psz, (i = strlen(psz) + 1)); 758 psz = &achTkExecPgmArguments[i]; 759 760 for (i = 1; i < cArgs; i++) 761 { 762 if (i > 1) *psz++ = ' '; //Add space if not second argument. 736 763 strcpy(psz, va_arg(vaarg, char *)); 737 764 psz += strlen(psz); 738 /* IF more arguments following (new or old) THEN add a space separator ELSE break loop */739 if (cchOldArgs > 1 || i < cArgs)740 *psz++ = ' ';741 else742 break;743 i++;744 765 } 745 766 va_end(vaarg); 767 if (cchOldArgs > 0) *psz++ = ' '; //Add space if old arguments 746 768 747 769 #ifdef DEBUG /* assertion */ … … 817 839 APIRET rc; 818 840 USHORT TCBFailErr_save; 819 int cchFilename; /* Filename length + 1. */ 841 int cchFile; /* Filename length + 1. */ 842 const char *pszFile; /* Pointer to filename portion. */ 820 843 const char *pszPath = ScanEnv(GetEnv(FALSE), "PATH"); /* Current Process environment? */ 821 844 … … 826 849 return ERROR_FILE_NOT_FOUND; 827 850 828 cchFilename = strlen(pszFilename) + 1; 851 /**@sketch 852 * Skip any paths in the filename. 853 */ 854 pszFile = pszFilename + (cchFile = strlen(pszFilename)); 855 while (pszFile >= pszFilename && *pszFile != '\\' && *pszFile != '/') 856 pszFile--; 857 cchFile -= pszFile - pszFilename; 858 pszFile++; 829 859 830 860 /**@sketch … … 840 870 while (*pszPath != '\0') 841 871 { 842 const char * pszNext = pszPath;872 const char * pszNext; 843 873 int cchPath; 844 char chEnd, ch; 874 char chEnd; 875 register char ch; 845 876 846 877 /* … … 848 879 */ 849 880 while (*pszPath == ' ') pszPath++; //skip leading spaces. 850 chEnd = *pszPath == '"' ? '"' : ';'; 881 if (*pszPath == '"') 882 { 883 chEnd = '"'; 884 pszPath++; 885 } 886 else 887 chEnd = ';'; 888 pszNext = pszPath; 851 889 while ((ch = *pszNext) != chEnd && ch != '\0') 852 890 pszNext++; 853 891 892 cchPath = pszNext - pszPath; 854 893 if (chEnd == '"') 855 894 { 856 cchPath = pszNext - (++pszPath); //pszPath points at '"' before incrementing it.857 if (ch != '\0')895 /* Skip anything between the " and the ; or string end. */ 896 while ((ch = *pszNext) != ';' && ch != '\0') 858 897 pszNext++; 859 898 } … … 861 900 { 862 901 /* Trim the string. */ 863 cchPath = pszNext - pszPath;864 902 while (cchPath > 0 && pszPath[cchPath-1] == ' ') //?? 865 903 cchPath--; … … 869 907 * No length? No Path! Or path'\'filename too long? => Next 870 908 */ 871 if (cchPath > 0 && cchPath + cchFile name+ 1 < CCHMAXPATH)909 if (cchPath > 0 && cchPath + cchFile + 1 < CCHMAXPATH) 872 910 { 873 911 static char achFilename[CCHMAXPATH]; … … 880 918 else 881 919 achFilename[cchPath] = '\\'; 882 memcpy(&achFilename[cchPath + 1], pszFilename, cchFilename); /* cchFilename = length + 1; hence we copy the terminator too. */920 memcpy(&achFilename[cchPath + 1], pszFile, cchFile); /* cchFile = length + 1; hence we copy the terminator too. */ 883 921 884 922 /* … … 898 936 899 937 case NO_ERROR: 938 strcpy(pszFilename, achFilename); 900 939 default: 901 940 tcbSetTCBFailErr(tcbGetCur(), TCBFailErr_save);
Note:
See TracChangeset
for help on using the changeset viewer.