Changeset 31
- Timestamp:
- Mar 30, 2016, 12:31:15 PM (9 years ago)
- Location:
- rxutilex/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
rxutilex/trunk/rxutilex.c
r30 r31 104 104 #define FL_TIME_LOCALE 2 105 105 106 static const char *PSZ_ZERO = "0"; 107 static const char *PSZ_ONE = "1"; 106 108 107 109 // List of functions to be registered by Sys2LoadFuncs or dropped by Sys2DropFuncs … … 135 137 }; 136 138 137 138 139 // FUNCTION DECLARATIONS 139 140 … … 174 175 RexxFunctionHandler Sys2SyncBuffer; 175 176 176 177 177 // Private internal functions 178 ULONG GetProcess( PSZ pszProgram, PSZ pszFullName, PULONG pulPID, PULONG pulPPID, PULONG pulType, PUSHORT pusPriority, PULONG pulCPU ); 179 BOOL SaveResultString( PRXSTRING prsResult, PCH pchBytes, ULONG ulBytes ); 180 BOOL WriteStemElement( PSZ pszStem, ULONG ulIndex, PSZ pszValue ); 181 void WriteErrorCode( ULONG ulError, PSZ pszContext ); 182 178 ULONG GetProcess( PCSZ pszProgram, PSZ pszFullName, PULONG pulPID, PULONG pulPPID, PULONG pulType, PUSHORT pusPriority, PULONG pulCPU ); // 2016-02-20 SHL 179 BOOL SaveResultString( PRXSTRING prsResult, PCSZ pchBytes, ULONG ulBytes ); // 2016-02-20 SHL 180 BOOL WriteStemElement( PCSZ pszStem, ULONG ulIndex, PCSZ pszValue ); // 2016-02-20 SHL 181 void WriteErrorCode( ULONG ulError, PCSZ pszContext ); // 2016-02-20 SHL 183 182 184 183 // MACROS 185 184 #define TIME_SECONDS( timeval ) ( timeval / 32 ) 186 185 #define TIME_HUNDREDTHS( timeval ) (( timeval % 32 ) * 100 / 32 ) 187 188 186 189 187 /* ------------------------------------------------------------------------- * … … 209 207 RexxRegisterFunctionDll( RxFunctionTbl[i], SZ_LIBRARY_NAME, RxFunctionTbl[i] ); 210 208 211 MAKERXSTRING( *prsResult, "", 0 );209 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 212 210 return ( 0 ); 213 211 } … … 235 233 RexxDeregisterFunction( RxFunctionTbl[i] ); 236 234 237 MAKERXSTRING( *prsResult, "", 0 );235 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 238 236 return ( 0 ); 239 237 } … … 258 256 sprintf( szVersion, "%s", SZ_VERSION ); 259 257 260 MAKERXSTRING( *prsResult, szVersion, strlen(szVersion) );258 SaveResultString( prsResult, szVersion, strlen(szVersion) ); // 2016-02-20 SHL 261 259 return ( 0 ); 262 260 } … … 317 315 DosGetInfoBlocks( &ptib, &ppib ); 318 316 ulPType = ppib->pib_ultype; 319 ppib->pib_ultype = 3; 317 ppib->pib_ultype = 3; // Morph to PM 320 318 hab = WinInitialize( 0 ); 321 319 if ( !hab ) { … … 328 326 * (in the calling process), which is also OK. 329 327 */ 330 hmq = WinCreateMsgQueue( hab, 0); 328 hmq = WinCreateMsgQueue( hab, 0 ); 329 330 // 2016-02-20 SHL Sync return values with docs 331 331 332 332 // Place the string on the clipboard as CF_TEXT … … 337 337 338 338 ulBytes = argv[0].strlength + 1; 339 ulRC = DosAllocSharedMem( (PVOID) &pszShareMem, NULL, ulBytes, 339 ulRC = DosAllocSharedMem( (PVOID) &pszShareMem, 340 NULL, 341 ulBytes, 340 342 PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ); 341 343 if ( ulRC == 0 ) { 342 344 memset( pszShareMem, 0, ulBytes ); 343 345 strncpy( pszShareMem, argv[0].strptr, ulBytes - 1 ); 344 if ( ! WinSetClipbrdData( hab, (ULONG) pszShareMem, CF_TEXT, CFI_POINTER )) 345 WriteErrorCode( ERRORIDERROR(WinGetLastError(hab)), "WinSetClipbrdData"); 346 if ( ! WinSetClipbrdData( hab, (ULONG) pszShareMem, CF_TEXT, CFI_POINTER ) ) { 347 WriteErrorCode( ERRORIDERROR(WinGetLastError(hab)), "WinSetClipbrdData" ); 348 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 349 } 346 350 else 347 MAKERXSTRING( *prsResult, "", 0 );351 SaveResultString( prsResult, PSZ_ONE, 1 ); // Success - 2016-02-20 SHL 348 352 } else { 349 353 WriteErrorCode( ulRC, "DosAllocSharedMem"); 350 MAKERXSTRING( *prsResult, "", 0 );354 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 351 355 } 352 356 353 357 WinCloseClipbrd( hab ); 354 358 } else { 355 WriteErrorCode( ulRC, "WinOpenClipbrd"); 356 MAKERXSTRING( *prsResult, "", 0 ); 359 // 2016-02-20 SHL Report PM error code 360 WriteErrorCode( ERRORIDERROR(WinGetLastError(hab)), "WinOpenClipbrd" ); 361 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 357 362 } 358 363 359 364 if ( hmq != NULLHANDLE ) WinDestroyMsgQueue( hmq ); 360 365 if ( fHabTerm ) WinTerminate( hab ); 361 ppib->pib_ultype = ulPType; 366 ppib->pib_ultype = ulPType; // Restore 362 367 363 368 return ( 0 ); … … 373 378 * None. * 374 379 * * 375 * REXX RETURN VALUE: The retrieved clipboard string 380 * REXX RETURN VALUE: The retrieved clipboard string or "" if fails. * 376 381 * ------------------------------------------------------------------------- */ 377 382 ULONG APIENTRY Sys2GetClipboardText( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult ) … … 415 420 416 421 // Read plain text from the clipboard, if available 417 if (( pszClipText = (PSZ) WinQueryClipbrdData( hab, CF_TEXT ) ) != NULL ) {418 419 ulBytes = strlen( pszClipText) + 1;420 if ( ( pszLocalText = (PSZ) malloc( ulBytes )) != NULL ) {422 if (( pszClipText = (PSZ) WinQueryClipbrdData( hab, CF_TEXT ) ) != NULL ) { 423 424 ulBytes = strlen(pszClipText) + 1; 425 if ( ( pszLocalText = (PSZ) malloc( ulBytes ) ) != NULL ) { 421 426 memset( pszLocalText, 0, ulBytes ); 422 427 strncpy( pszLocalText, pszClipText, ulBytes - 1 ); 423 if ( ! SaveResultString( prsResult, pszLocalText, ulBytes - 1 )) { 424 MAKERXSTRING( *prsResult, "", 0 ); 425 } 428 SaveResultString( prsResult, pszLocalText, ulBytes - 1 ); // 2016-02-20 SHL 426 429 free( pszLocalText ); 427 430 } else { 428 431 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "malloc"); 429 MAKERXSTRING( *prsResult, "", 0 );432 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 430 433 } 431 434 432 435 } else { 433 436 // Either no text exists, or clipboard is not readable 434 MAKERXSTRING( *prsResult, "", 0 );437 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 435 438 } 436 439 437 440 WinCloseClipbrd( hab ); 438 441 } else { 439 WriteErrorCode( ulRC, "WinOpenClipbrd"); 440 MAKERXSTRING( *prsResult, "", 0 ); 442 // 2016-02-20 SHL Report PM error code 443 WriteErrorCode( ERRORIDERROR(WinGetLastError(hab)), "WinOpenClipbrd" ); 444 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 441 445 } 442 446 … … 489 493 490 494 // Parse the ID type flag 491 if ( argc >= 2 && RXVALIDSTRING( argv[1]) ) {495 if ( argc >= 2 && RXVALIDSTRING( argv[1] ) ) { 492 496 strupr( argv[1].strptr ); 493 if ( strcspn(argv[1].strptr, "HNP") > 0 ) return ( 40 );497 if ( strcspn(argv[1].strptr, "HNP") > 0 ) return ( 40 ); 494 498 switch ( argv[1].strptr[0] ) { 495 499 … … 505 509 if ( pszProcName == NULL ) { 506 510 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "calloc"); 507 MAKERXSTRING( *prsResult, "0", 1 );511 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 508 512 return ( 0 ); 509 513 } … … 515 519 if ( pszProcName == NULL ) { 516 520 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "calloc"); 517 MAKERXSTRING( *prsResult, "0", 1 );521 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 518 522 return ( 0 ); 519 523 } … … 524 528 rc = GetProcess( pszProcName, szFullName, &ulPID, &ulPPID, &ulType, &usPrty, &ulTime ); 525 529 if (( rc != NO_ERROR ) || ( ulPID == 0 )) { 526 MAKERXSTRING( *prsResult, "", 0 );530 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 527 531 return ( 0 ); 528 532 } … … 532 536 TIME_SECONDS( ulTime ) % 60, TIME_HUNDREDTHS( ulTime ), szFullName ); 533 537 534 MAKERXSTRING( *prsResult, szReturn, strlen(szReturn) );538 SaveResultString( prsResult, szReturn, strlen(szReturn) ); // 2016-02-20 SHL 535 539 536 540 return ( 0 ); … … 588 592 if ( pszProcName == NULL ) { 589 593 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "calloc"); 590 MAKERXSTRING( *prsResult, "0", 1 );594 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 591 595 return ( 0 ); 592 596 } … … 598 602 if ( pszProcName == NULL ) { 599 603 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "calloc"); 600 MAKERXSTRING( *prsResult, "0", 1 );604 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 601 605 return ( 0 ); 602 606 } … … 604 608 } 605 609 606 if ( pszProcName != NULL) {610 if ( pszProcName ) { 607 611 // Get the process PID 608 612 rc = GetProcess( pszProcName, szFullName, &ulPID, &ulPPID, &ulType, &usPrty, &ulTime ); 609 613 if (( rc != NO_ERROR ) || ( ulPID == 0 )) { 610 MAKERXSTRING( *prsResult, "0", 1 ); 614 free( pszProcName ); 615 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 611 616 return ( 0 ); 612 617 } … … 617 622 if ( rc != NO_ERROR ) { 618 623 WriteErrorCode( rc, "DosKillProcess"); 619 MAKERXSTRING( *prsResult, "0", 1 ); 620 return ( 0 ); 621 } 622 623 MAKERXSTRING( *prsResult, "1", 1 ); 624 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 625 } 626 else 627 SaveResultString( prsResult, PSZ_ONE, 1 ); // 2016-02-20 SHL 628 629 // 2016-02-20 SHL Avoid leak 630 if ( pszProcName ) 631 free( pszProcName ); 632 624 633 return ( 0 ); 625 634 } … … 683 692 pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE ); 684 693 #else 685 pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE ); 694 pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE ); // 2015-04-23 SHL 686 695 #endif 687 696 688 697 if ( pBuf == NULL ) { 689 698 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "malloc"); 690 MAKERXSTRING( *prsResult, "", 0 );699 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 691 700 return ( 0 ); 692 701 } … … 697 706 if ( rc != NO_ERROR ) { 698 707 WriteErrorCode( rc, "DosQProcStatus"); 699 MAKERXSTRING( *prsResult, "", 0 );708 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 700 709 return ( 0 ); 701 710 } … … 705 714 if ( rc != NO_ERROR ) { 706 715 WriteErrorCode( rc, "DosQuerySysState"); 707 MAKERXSTRING( *prsResult, "", 0 );716 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 708 717 return ( 0 ); 709 718 } … … 712 721 // Now get the list of processes 713 722 ulCount = 0; 714 # if 1 // 2015-06-12 SHL FIXME to know if can occur 715 if ( pBuf->pProcRec == NULL ) { 716 WriteErrorCode( rc, "pBuf->pProcRec NULL"); 717 MAKERXSTRING( *prsResult, "", 0 ); 723 # if 1 // 2016-02-25 SHL FIXME debug bad pointer 724 // 2016-02-26 SHL FIXME to be gone when sure this can not occur 725 if ( (ULONG)pBuf->pProcRec < 0x10000 ) { 726 sprintf( szName, "rxutilex#%u pBuf->pProcRec 0x%x < 0x10000", 727 __LINE__, (ULONG)pBuf->pProcRec ); 728 WriteErrorCode( ERROR_INVALID_ADDRESS, szName ); 729 SaveResultString( prsResult, NULL, 0 ); 730 free( pBuf ); 718 731 return ( 0 ); 719 732 } 720 733 # endif 721 734 722 // 2015-06-12 SHL pThrdRec can be 0 - probably when process starting or dieing723 735 for (pPrec = pBuf->pProcRec; 724 736 ; 725 pPrec = pPrec->pThrdRec ? 726 (QSPREC *)(pPrec->pThrdRec + pPrec->cTCB) : 727 pPrec + 1 737 pPrec = (QSPREC *)(pPrec->pThrdRec + pPrec->cTCB) 728 738 ) 729 739 730 740 { 731 # if 1 732 // 2015-06-19 SHL FIXME to be gone if proven that never can occur 733 if ((ULONG)pPrec < 0x10000) { 734 fprintf(stderr, "* rxutilex#%u ulCount %u pPrec %p\n", __LINE__, ulCount, pPrec); 735 break; // Avoid death 741 # if 0 // 2015-06-19 SHL FIXME debug bad pointer 742 // 2016-02-26 SHL FIMXE to be gone when sure no longer needed 743 if ( (ULONG)pPrec < 0x10000 ) { 744 sprintf( szName, "rxutilex#%u pPrec 0x%x < 0x10000", 745 __LINE__, (ULONG)pPrec ); 746 WriteErrorCode( ERROR_INVALID_ADDRESS, szName ); 747 SaveResultString( prsResult, NULL, 0 ); 748 free( pBuf ); 749 return ( 0 ); 736 750 } 737 751 # endif 738 752 739 // 2015-06-19 SHL FIXME debug was trapping here if pThrdRec NULL 740 if (pPrec->RecType != QS_PROCESS) 741 break; 742 743 # if 1 744 /* Avoid death if no threads 745 This is undocumented but probably occurs if called while process 746 is starting or terminating 747 2015-07-31 SHL 748 */ 749 if (!pPrec->cTCB) 750 fprintf(stderr, "* rxutilex#%u ulCount %u pBuf %p pPrec %p pPrec->pThrdRec %p pPrec->cTCB %u\n", __LINE__, ulCount, pBuf, pPrec, pPrec->pThrdRec, pPrec->cTCB); 751 // 2015-07-31 SHL FIXME debug 752 if ((ULONG)(pPrec->pThrdRec) < 0x10000) { 753 fprintf(stderr, "* rxutilex#%u ulCount %u pBuf %p pPrec %p pPrec->pThrdRec %p pPrec->cTCB %u\n", __LINE__, ulCount, pBuf, pPrec, pPrec->pThrdRec, pPrec->cTCB); 754 break; // Avoid death 753 // Check for documented end marker - RecType not QS_PROCESS 754 if ( pPrec->RecType != QS_PROCESS ) { 755 # if 0 // 2016-02-26 SHL FIXME debug 756 fprintf( stderr, 757 "* rxutilex#%u RecType != QS_PROCESS " 758 "ulCount %u pBuf %p pPrec %p ->RecType %x ->pThrdRec %p ->pid %u ->ppid %u ->type %u ->stat %u ->hmte %x ->cTCB %u\n", 759 __LINE__, ulCount, pBuf, pPrec, pPrec->RecType, pPrec->pThrdRec, 760 pPrec->pid, pPrec->ppid, 761 pPrec->type, pPrec->stat, pPrec->hMte, pPrec->cTCB ); 762 # endif 763 break; // Must be end of list 764 } 765 766 // Check for alternate end marker - pThredRec NULL 767 // This appears to be an undocumented end marker 768 // Might be a defect - testing says only RecType is non-zero 769 // 2015-06-12 SHL pThrdRec can be 0 - probably when process starting or dieing 770 if ( (PVOID)pPrec->pThrdRec == NULL ) { 771 # if 0 // 2016-02-26 SHL FIXME debug 772 fprintf( stderr, 773 "* rxutilex#%u pThrdRec NULL " 774 "ulCount %u pBuf %p pPrec %p ->pThrdRec %p ->pid %u ->ppid %u ->type %u ->stat %u ->hmte %x ->cTCB %u\n", 775 __LINE__, ulCount, pBuf, pPrec, pPrec->pThrdRec, pPrec->pid, pPrec->ppid, 776 pPrec->type, pPrec->stat, pPrec->hMte, pPrec->cTCB ); 777 # endif 778 break; // Must be end of list 779 } 780 781 # if 1 // 2015-07-31 SHL FIXME debug bad pointer 782 // 2016-02-26 SHL FIXME to be gone when sure can not occur 783 if ( (ULONG)(pPrec->pThrdRec) < 0x10000 ) { 784 sprintf( szName, 785 "rxutilex#%u pPrec < 0x10000 " 786 "ulCount %u pBuf %p pPrec %p ->pThrdRec %p ->pid %u ->ppid %u ->type %u ->stat %u ->hmte %x ->cTCB %u\n", 787 __LINE__, ulCount, pBuf, pPrec, pPrec->pThrdRec, pPrec->pid, pPrec->ppid, 788 pPrec->type, pPrec->stat, pPrec->hMte, pPrec->cTCB ); 789 WriteErrorCode( ERROR_INVALID_ADDRESS, szName ); 790 SaveResultString( prsResult, NULL, 0 ); 791 free( pBuf ); 792 return ( 0 ); 793 } 794 # endif 795 # if 1 // 2016-02-26 SHL FIXME debug bad count 796 // 2016-02-26 SHL FIXME to be gone when sure can not occur 797 // This is probably occurs only when pThrdRec NULL too which is already checked 798 if ( !pPrec->cTCB ) { 799 sprintf( szName, "rxutilex#%u cTCB 0 ulCount %u pBuf %p pPrec %p ->pid %u ->type %u ->stat %u\n", 800 __LINE__, ulCount, pBuf, pPrec, pPrec->pid, pPrec->type, pPrec->stat ); 801 WriteErrorCode( ERROR_INVALID_DATA, szName ); 802 SaveResultString( prsResult, NULL, 0 ); 803 free( pBuf ); 804 return ( 0 ); 755 805 } 756 806 # endif … … 784 834 WriteStemElement( szStem, ulCount, szPInfo ); 785 835 786 # if 1 // 2015-07-31 SHL FIXME debug 787 // 2015-07-31 SHL FIXME debug 788 if (!pPrec->cTCB) { 789 fprintf(stderr, "* rxutilex: szPInfo %s\n", szPInfo); 790 fprintf(stderr, "* rxutilex: ulCount %u pBuf %p pPrec %p pPrec->pThrdRec %p pPrec->cTCB %u\n", ulCount, pBuf, pPrec, pPrec->pThrdRec, pPrec->cTCB); 791 fprintf(stderr, "* rxutilex: next RecType %x\n", (pPrec + 1)->RecType); 792 } 793 // 2015-07-31 SHL FIXME debug 794 if ((ULONG)pPrec->pThrdRec < 0x10000 || !pPrec->cTCB) { 795 fprintf(stderr, "* rxutilex: szPInfo %s\n", szPInfo); 796 fprintf(stderr, "* rxutilex: ulCount %u pBuf %p pPrec %p pPrec->pThrdRec %p pPrec->cTCB %u\n", ulCount, pBuf, pPrec, pPrec->pThrdRec, pPrec->cTCB); 797 fprintf(stderr, "* rxutilex: next RecType %x\n", (pPrec + 1)->RecType); 798 break; // Avoid death 836 # if 0 // 2015-07-31 SHL FIXME debug bad count 837 // 2016-02-26 SHL FIXME to be gone when sure no longer needed 838 if ( !pPrec->cTCB ) { 839 sprintf( szName, "rxutilex#%u: cTCB 0 " 840 "ulCount %u pBuf %p pPrec %p ->pThrdRec %p ->pid %u\n", 841 __LINE__, ulCount, pBuf, pPrec, pPrec->pThrdRec, pPrec->pid ); 842 WriteErrorCode( ERROR_INVALID_DATA, szName ); 843 SaveResultString( prsResult, NULL, 0 ); 844 free( pBuf ); 845 return ( 0 ); 846 } 847 # endif 848 # if 0 // 2015-07-31 SHL FIXME debug bad pointer 849 // 2016-02-26 SHL FIXME to be gone when sure no longer needed 850 if ( (ULONG)pPrec->pThrdRec < 0x10000 ) { 851 sprintf( szName, 852 "rxutilex#%u: pBuf->pThrdRec < 0x10000 " 853 "ulCount %u pBuf %p pPrec %p ->pThrdRec %p ->pid %u ->cTCB %u\n", 854 __LINE__, ulCount, pBuf, pPrec, pPrec->pThrdRec, pPrec->pid, pPrec->cTCB ); 855 WriteErrorCode( rc, szName ); 856 SaveResultString( prsResult, NULL, 0 ); 857 free( pBuf ); 858 return ( 0 ); 799 859 } 800 860 # endif 801 861 } // for 802 862 803 // Create the "0" stemelement with the number of processes found863 // Create the stem.0 element with the number of processes found 804 864 sprintf( szNumber, "%d", ulCount ); 805 865 WriteStemElement( szStem, 0, szNumber ); 806 866 807 867 // And also return the number of processes as the REXX return string 808 MAKERXSTRING( *prsResult, szNumber, strlen(szNumber) );868 SaveResultString( prsResult, szNumber, strlen(szNumber) ); // 2016-02-20 SHL 809 869 810 870 free( pBuf ); … … 842 902 if ( rc != NO_ERROR ) { 843 903 WriteErrorCode( rc, "DosQuerySysInfo"); 844 MAKERXSTRING( *prsResult, "0", 1 );904 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 845 905 return ( 0 ); 846 906 } … … 851 911 852 912 // Return the memory size as the REXX return string 853 MAKERXSTRING( *prsResult, szMemSize, strlen(szMemSize) );913 SaveResultString( prsResult, szMemSize, strlen(szMemSize) ); // 2016-02-20 SHL 854 914 855 915 return ( 0 ); … … 886 946 if ( rc != NO_ERROR ) { 887 947 WriteErrorCode( rc, "DosQuerySysInfo"); 888 MAKERXSTRING( *prsResult, "0", 1 );948 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 889 949 return ( 0 ); 890 950 } … … 892 952 893 953 // Return the PID as the REXX return string 894 MAKERXSTRING( *prsResult, szPID, strlen(szPID) );954 SaveResultString( prsResult, szPID, strlen(szPID) ); // 2016-02-20 SHL 895 955 896 956 return ( 0 ); … … 926 986 if ( pszOldModule == NULL ) { 927 987 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "calloc"); 928 MAKERXSTRING( *prsResult, "0", 1 );988 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 929 989 return ( 0 ); 930 990 } … … 937 997 if ( pszNewModule == NULL ) { 938 998 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "calloc"); 939 MAKERXSTRING( *prsResult, "0", 1 );999 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 940 1000 return ( 0 ); 941 1001 } … … 950 1010 if ( pszBackup == NULL ) { 951 1011 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "calloc"); 952 MAKERXSTRING( *prsResult, "0", 1 );1012 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 953 1013 return ( 0 ); 954 1014 } … … 961 1021 if ( rc != NO_ERROR ) { 962 1022 WriteErrorCode( rc, "DosReplaceModule"); 963 MAKERXSTRING( *prsResult, "0", 1 );1023 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 964 1024 return ( 0 ); 965 1025 } 966 1026 967 1027 // Return 1 on success 968 MAKERXSTRING( *prsResult, "1", 1 );1028 SaveResultString( prsResult, PSZ_ONE, 1 ); // 2016-02-20 SHL 969 1029 970 1030 return ( 0 ); … … 985 1045 * values. Ignored for integer values. (DEFAULT: 2) * 986 1046 * * 987 * REXX RETURN VALUE: The formatted number, or ''on error. *1047 * REXX RETURN VALUE: The formatted number, or "" on error. * 988 1048 * ------------------------------------------------------------------------- */ 989 1049 ULONG APIENTRY Sys2FormatNumber( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult ) … … 1015 1075 */ 1016 1076 PSZ pszLang, p; 1017 if (( DosScanEnv("LANG", &pszLang ) == NO_ERROR ) && 1018 pszLang && ( strlen( pszLang ) >= 2 )) 1077 if ( DosScanEnv( "LANG", &pszLang ) == NO_ERROR && 1078 pszLang && 1079 strlen(pszLang) >= 2 ) 1019 1080 { 1020 1081 p = strdup( pszLang ); … … 1091 1152 if ( rc != ULS_SUCCESS ) { 1092 1153 WriteErrorCode( rc, "UniCreateLocaleObject"); 1093 MAKERXSTRING( *prsResult, "", 0 );1154 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1094 1155 return ( 0 ); 1095 1156 } … … 1097 1158 if ( rc != ULS_SUCCESS ) { 1098 1159 WriteErrorCode( rc, "UniQueryLocaleInfo"); 1099 MAKERXSTRING( *prsResult, "", 0 );1160 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1100 1161 return ( 0 ); 1101 1162 } … … 1121 1182 1122 1183 // Return the formatted number 1123 MAKERXSTRING( *prsResult, achNumber, strlen( achNumber ));1184 SaveResultString( prsResult, achNumber, strlen(achNumber) ); // 2016-02-20 SHL 1124 1185 1125 1186 return ( 0 ); … … 1147 1208 * L = convert to local time using the current TZ (DEFAULT) * 1148 1209 * * 1149 * REXX RETURN VALUE: The formatted time string, or ''on error. *1210 * REXX RETURN VALUE: The formatted time string, or "" on error. * 1150 1211 * ------------------------------------------------------------------------- */ 1151 1212 ULONG APIENTRY Sys2FormatTime( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult ) … … 1203 1264 */ 1204 1265 DosScanEnv("TZ", &pszTZ ); 1205 pszSetTZ = (PSZ) malloc( strlen( pszTZ) + 5 );1266 pszSetTZ = (PSZ) malloc( strlen(pszTZ) + 5 ); 1206 1267 if ( pszSetTZ ) { 1207 1268 sprintf( pszSetTZ, "TZ=%s", pszTZ ); … … 1217 1278 if ( ttSeconds == -1 ) { 1218 1279 WriteErrorCode( ttSeconds, "time"); 1219 MAKERXSTRING( *prsResult, "", 0 );1280 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1220 1281 if ( pszSetTZ ) free( pszSetTZ ); 1221 1282 return 0; … … 1227 1288 if ( !timeptr ) { 1228 1289 WriteErrorCode( 1, "gmtime"); 1229 MAKERXSTRING( *prsResult, "0", 1 );1290 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL // 2016-02-20 SHL 1230 1291 if ( pszSetTZ ) free( pszSetTZ ); 1231 1292 return 0; … … 1236 1297 if ( !timeptr ) { 1237 1298 WriteErrorCode( 1, "localtime"); 1238 MAKERXSTRING( *prsResult, "0", 1 );1299 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1239 1300 if ( pszSetTZ ) free( pszSetTZ ); 1240 1301 return 0; … … 1261 1322 if ( stRC == NO_ERROR ) { 1262 1323 WriteErrorCode( stRC, "strftime"); 1263 MAKERXSTRING( *prsResult, "", 0 );1324 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1264 1325 if ( pszSetTZ ) free( pszSetTZ ); 1265 1326 return ( 0 ); … … 1267 1328 1268 1329 // Return the formatted time string 1269 MAKERXSTRING( *prsResult, szTime, strlen(szTime) );1330 SaveResultString( prsResult, szTime, strlen(szTime) ); // 2016-02-20 SHL 1270 1331 1271 1332 if ( pszSetTZ ) free( pszSetTZ ); … … 1376 1437 */ 1377 1438 DosScanEnv("TZ", &pszTZ ); 1378 pszSetTZ = (PSZ) malloc( strlen( pszTZ) + 5 );1439 pszSetTZ = (PSZ) malloc( strlen(pszTZ) + 5 ); 1379 1440 sprintf( pszSetTZ, "TZ=%s", pszTZ ); 1380 1441 putenv( pszSetTZ ); … … 1390 1451 if ( timeval == -1 ) { 1391 1452 WriteErrorCode( timeval, "time"); 1392 MAKERXSTRING( *prsResult, "0", 1 );1453 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 1393 1454 free( pszSetTZ ); 1394 1455 return 0; … … 1407 1468 if ( timeval == -1 ) { 1408 1469 WriteErrorCode( timeval, "mktime"); 1409 MAKERXSTRING( *prsResult, "0", 1 );1470 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 1410 1471 free( pszSetTZ ); 1411 1472 return 0; … … 1419 1480 sprintf( szEpochTime, "%d", timeval ); 1420 1481 #endif 1421 MAKERXSTRING( *prsResult, szEpochTime, strlen(szEpochTime) );1482 SaveResultString( prsResult, szEpochTime, strlen(szEpochTime) ); // 2016-02-20 SHL 1422 1483 1423 1484 free( pszSetTZ ); … … 1440 1501 * * 1441 1502 * REXX RETURN VALUE: * 1442 * The fully-qualified path of the DLL, if found (or ''if not found). *1503 * The fully-qualified path of the DLL, if found (or "" if not found). * 1443 1504 * ------------------------------------------------------------------------- */ 1444 1505 ULONG APIENTRY Sys2LocateDLL( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult ) … … 1472 1533 if ( bLoadedOnly ) { 1473 1534 // Just return 1474 MAKERXSTRING( *prsResult, "", 0 );1535 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1475 1536 return 0; 1476 1537 } … … 1479 1540 if ( rc ) { 1480 1541 WriteErrorCode( rc, "DosLoadModule"); 1481 MAKERXSTRING( *prsResult, "", 0 );1542 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1482 1543 return 0; 1483 1544 } … … 1489 1550 if ( rc ) { 1490 1551 WriteErrorCode( rc, "DosQueryModuleName"); 1491 MAKERXSTRING( *prsResult, "", 0 );1552 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1492 1553 if ( bUnload ) DosFreeModule( hmod ); 1493 1554 return 0; … … 1498 1559 1499 1560 // Return the full path name 1500 if ( ! SaveResultString( prsResult, achModuleName, strlen( achModuleName ))) { 1501 MAKERXSTRING( *prsResult, "", 0 ); 1502 } 1561 SaveResultString( prsResult, achModuleName, strlen(achModuleName) ); // 2016-02-20 SHL 1503 1562 1504 1563 return 0; … … 1534 1593 * * 1535 1594 * REXX RETURN VALUE: * 1536 * A four-byte pipe handle .*1595 * A four-byte pipe handle or 0 if create fails * 1537 1596 * ------------------------------------------------------------------------- */ 1538 1597 ULONG APIENTRY Sys2CreateNamedPipe( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult ) … … 1623 1682 if ( pszNPName == NULL ) { 1624 1683 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "calloc"); 1625 MAKERXSTRING( *prsResult, "0", 1 );1684 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 1626 1685 return ( 0 ); 1627 1686 } … … 1632 1691 if (rc) { 1633 1692 WriteErrorCode( rc, "DosCreateNPipe"); 1634 MAKERXSTRING( *prsResult, "", 0 );1693 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 1635 1694 return 0; 1636 1695 } … … 1638 1697 // Return the handle as the REXX result string 1639 1698 sprintf( achHandle, "%8X", hp ); 1640 MAKERXSTRING( *prsResult, achHandle, strlen( achHandle ));1699 SaveResultString( prsResult, achHandle, strlen(achHandle) ); // 2016-02-20 SHL 1641 1700 1642 1701 free( pszNPName ); … … 1681 1740 { 1682 1741 WriteErrorCode( rc, "DosConnectNPipe"); 1683 MAKERXSTRING( *prsResult, "0", 1 );1742 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 1684 1743 return ( 0 ); 1685 1744 } 1686 1745 1687 1746 // Return 1 on success 1688 MAKERXSTRING( *prsResult, "1", 1 );1747 SaveResultString( prsResult, PSZ_ONE, 1 ); // 2016-02-20 SHL 1689 1748 return ( 0 ); 1690 1749 } … … 1718 1777 if ( rc != NO_ERROR ) { 1719 1778 WriteErrorCode( rc, "DosDisConnectNPipe"); 1720 MAKERXSTRING( *prsResult, "0", 1 );1779 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 1721 1780 return ( 0 ); 1722 1781 } 1723 1782 1724 1783 // Return 1 on success 1725 MAKERXSTRING( *prsResult, "1", 1 );1784 SaveResultString( prsResult, PSZ_ONE, 1 ); // 2016-02-20 SHL 1726 1785 return ( 0 ); 1727 1786 } … … 1739 1798 * String of the format "bytes status", where bytes is the number of bytes * 1740 1799 * currently waiting in the pipe, and status is one of: DISCONNECTED, * 1741 * LISTENING, CONNECTED, or CLOSING .*1800 * LISTENING, CONNECTED, or CLOSING or "" if API error * 1742 1801 * ------------------------------------------------------------------------- */ 1743 1802 ULONG APIENTRY Sys2CheckNamedPipe( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult ) … … 1759 1818 if ( rc != NO_ERROR ) { 1760 1819 WriteErrorCode( rc, "DosPeekNPipe"); 1761 MAKERXSTRING( *prsResult, "", 0 );1820 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1762 1821 return ( 0 ); 1763 1822 } … … 1771 1830 } 1772 1831 1773 if ( ! SaveResultString( prsResult, szStatus, strlen( szStatus ))) { 1774 MAKERXSTRING( *prsResult, "", 0 ); 1775 } 1832 SaveResultString( prsResult, szStatus, strlen(szStatus) ); // 2016-02-20 SHL 1833 1776 1834 return ( 0 ); 1777 1835 } … … 1953 2011 if ( pszFile == NULL ) { 1954 2012 WriteErrorCode( ERROR_NOT_ENOUGH_MEMORY, "calloc"); 1955 MAKERXSTRING( *prsResult, "0", 1 );2013 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1956 2014 return ( 0 ); 1957 2015 } … … 1962 2020 if (rc) { 1963 2021 WriteErrorCode( rc, "DosOpenL"); 1964 MAKERXSTRING( *prsResult, "", 0 );2022 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 1965 2023 free( pszFile ); 1966 2024 return ( 0 ); … … 1969 2027 // Return the handle as the REXX result string 1970 2028 sprintf( achHandle, "%8X", hf ); 1971 MAKERXSTRING( *prsResult, achHandle, strlen( achHandle ));2029 SaveResultString( prsResult, achHandle, strlen(achHandle) ); // 2016-02-20 SHL 1972 2030 1973 2031 free( pszFile ); … … 2004 2062 if ( rc != NO_ERROR ) { 2005 2063 WriteErrorCode( rc, "DosClose"); 2006 MAKERXSTRING( *prsResult, "0", 1 );2064 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 2007 2065 } 2008 2066 else { 2009 MAKERXSTRING( *prsResult, "1", 1 );2067 SaveResultString( prsResult, PSZ_ONE, 1 ); // 2016-02-20 SHL 2010 2068 } 2011 2069 … … 2029 2087 * * 2030 2088 * REXX RETURN VALUE: * 2031 * The new file position, in bytes .*2089 * The new file position, in bytes or "" if error * 2032 2090 * ------------------------------------------------------------------------- */ 2033 2091 ULONG APIENTRY Sys2Seek( PSZ pszName, ULONG argc, RXSTRING argv[], PSZ pszQueue, PRXSTRING prsResult ) … … 2067 2125 if ( rc != NO_ERROR ) { 2068 2126 WriteErrorCode( rc, "DosSetFilePtrL"); 2069 MAKERXSTRING( *prsResult, "", 0 );2127 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 2070 2128 return ( 0 ); 2071 2129 } … … 2073 2131 // Return the new position as the REXX result string 2074 2132 sprintf( achActual, "%lld", llActual ); 2075 MAKERXSTRING( *prsResult, achActual, strlen( achActual ));2133 SaveResultString( prsResult, achActual, strlen(achActual) ); // 2016-02-20 SHL 2076 2134 2077 2135 return ( 0 ); … … 2117 2175 if ( rc || !cbActual ) { 2118 2176 WriteErrorCode( rc, "DosRead"); 2119 MAKERXSTRING( *prsResult, "", 0 );2177 SaveResultString( prsResult, NULL, 0 ); // 2016-02-20 SHL 2120 2178 goto cleanup; 2121 2179 } 2122 if ( ! SaveResultString( prsResult, pszData, cbActual )) { 2123 MAKERXSTRING( *prsResult, "", 0 ); 2124 } 2180 SaveResultString( prsResult, pszData, cbActual ); // 2016-02-20 SHL 2125 2181 2126 2182 cleanup: … … 2164 2220 if ( rc != NO_ERROR ) { 2165 2221 WriteErrorCode( rc, "DosWrite"); 2166 MAKERXSTRING( *prsResult, "0", 1 );2222 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 2167 2223 return ( 0 ); 2168 2224 } 2169 2225 2170 2226 sprintf( szActual, "%d", cbActual ); 2171 MAKERXSTRING( *prsResult, szActual, strlen( szActual ));2227 SaveResultString( prsResult, szActual, strlen(szActual) ); // 2016-02-20 SHL 2172 2228 return ( 0 ); 2173 2229 } … … 2203 2259 if ( rc != NO_ERROR ) { 2204 2260 WriteErrorCode( rc, "DosResetBuffer"); 2205 MAKERXSTRING( *prsResult, "0", 1 );2261 SaveResultString( prsResult, PSZ_ZERO, 1 ); // 2016-02-20 SHL 2206 2262 } 2207 2263 else { 2208 MAKERXSTRING( *prsResult, "1", 1 );2264 SaveResultString( prsResult, PSZ_ONE, 1 ); // 2016-02-20 SHL 2209 2265 } 2210 2266 … … 2239 2295 * 0 on success, or a non-zero API return code in the case of an error. * 2240 2296 * ------------------------------------------------------------------------- */ 2241 ULONG GetProcess( PSZ pszProgram, 2297 // 2016-02-20 SHL Rework to avoid traps 2298 ULONG GetProcess( PCSZ pszProgram, 2242 2299 PSZ pszFullName, 2243 2300 PULONG pulPID, … … 2250 2307 QSPTRREC *pBuf; // Data returned by DosQProcStatus() 2251 2308 #else 2252 QSPTRREC *pBuf; // Data returned by DosQuerySysState() 2309 QSPTRREC *pBuf; // Data returned by DosQuerySysState() // 2015-04-23 SHL 2253 2310 #endif 2254 2311 QSPREC *pPrec; // Pointer to process information block … … 2265 2322 APIRET rc; // Return code 2266 2323 2267 2268 2324 // Use current process when PID is 0 and program name is not specified 2269 2325 if (( pszProgram == NULL ) && ( *pulPID == 0 )) { … … 2279 2335 pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE ); 2280 2336 #else 2281 pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE ); 2337 pBuf = (QSPTRREC *) malloc( UL_SSBUFSIZE ); // 2015-04-23 SHL 2282 2338 #endif 2283 2339 … … 2300 2356 if ( rc != NO_ERROR ) { 2301 2357 WriteErrorCode( rc, "DosQuerySysState"); 2358 free( pBuf ); 2302 2359 return ( rc ); 2303 2360 } 2304 pPrec = (QSPREC *)(((QSPTRREC*)pBuf) -> pProcRec); 2361 pPrec = (QSPREC *)(((QSPTRREC*)pBuf) -> pProcRec); // 2015-04-23 SHL 2305 2362 #endif 2306 2363 … … 2312 2369 else if ( *pulPID == 0 ) return 0; 2313 2370 2371 # if 1 // 2016-02-25 SHL FIXME debug bad pointer 2372 // 2016-02-26 SHL FIXME to be gone when sure can not occur 2373 if ( (ULONG)pPrec < 0x10000 ) { 2374 sprintf( szName, "rxutilex#%u pPrec 0x%x < 0x10000", __LINE__, (ULONG)pPrec ); 2375 WriteErrorCode( ERROR_INVALID_ADDRESS, szName); 2376 free( pBuf ); 2377 return ( 0 ); 2378 } 2379 # endif 2380 2314 2381 // Now look for the specified process 2315 while (( pPrec->RecType == 1 ) && ( !fMatch )) { 2382 // List ends with RecType not QS_PROCESS or pThrdRec NULL 2383 while ( pPrec->RecType == QS_PROCESS && pPrec->pThrdRec != NULL && !fMatch ) { 2316 2384 2317 2385 if ( pszProgram == NULL ) { 2386 // Match by pid 2318 2387 if ( pPrec->pid == *pulPID ) { 2319 2388 fMatch = TRUE; … … 2351 2420 // Create a copy without the extension 2352 2421 strcpy( szNoExt, pszCurrent ); 2353 if (( c = strrchr( szNoExt, '.')) != NULL ) memset( c, 0, strlen(c) ); 2354 if (( pszCurrent != NULL ) && 2355 (( stricmp(pszCurrent, pszProgram) == 0 ) || ( stricmp(szNoExt, pszProgram) == 0 ))) 2422 if ( ( c = strrchr( szNoExt, '.') ) != NULL ) 2423 memset( c, 0, strlen(c) ); 2424 if ( pszCurrent != NULL && 2425 ( stricmp(pszCurrent, pszProgram) == 0 || stricmp(szNoExt, pszProgram) == 0 ) ) 2356 2426 { 2357 2427 fMatch = TRUE; … … 2377 2447 } 2378 2448 } 2379 pPrec = (QSPREC *) ( (PBYTE) (pPrec->pThrdRec) + ( pPrec->cTCB * sizeof(QSTREC) ) ); 2380 } 2449 pPrec = (QSPREC *)(pPrec->pThrdRec + pPrec->cTCB); 2450 2451 # if 1 // 2016-02-25 SHL FIXME debug pointer - can this occur? 2452 // 2016-02-26 SHL FIXME to be gone when sure can not occur 2453 if ( (ULONG)pPrec < 0x10000 ) { 2454 sprintf( szName, "rxutilex#%u pPrec 0x%x < 0x10000", __LINE__, (ULONG)pPrec ); 2455 WriteErrorCode( ERROR_INVALID_ADDRESS, szName); 2456 free( pBuf ); 2457 return ( 0 ); 2458 } 2459 # endif 2460 2461 } // while 2381 2462 if ( !fMatch ) *pulPID = 0; 2382 2463 … … 2390 2471 * * 2391 2472 * Writes new string contents to the specified RXSTRING, allocating any * 2392 * additional memory that may be required. If the string to be written has * 2393 * zero length, nothing is done. * 2394 * * 2395 * This function should be used in place of MAKERXSTRING if there is a * 2396 * possibility that the string contents could be longer than 256 characters. * 2473 * additional memory that may be required. * 2397 2474 * * 2398 2475 * ARGUMENTS: * 2399 2476 * PRXSTRING prsResult: Pointer to an existing RXSTRING for writing. * 2400 * PCH pchBytes : The string contents to write to prsResult .*2401 * ULONG ulBytes : The number of bytes in pchBytes to write .*2477 * PCH pchBytes : The string contents to write to prsResult or NULL * 2478 * ULONG ulBytes : The number of bytes in pchBytes to write 0..N. * 2402 2479 * * 2403 2480 * RETURNS: BOOL * 2404 2481 * TRUE if prsResult was successfully updated. FALSE otherwise. * 2405 2482 * ------------------------------------------------------------------------- */ 2406 BOOL SaveResultString( PRXSTRING prsResult, PC HpchBytes, ULONG ulBytes )2483 BOOL SaveResultString( PRXSTRING prsResult, PCSZ pchBytes, ULONG ulBytes ) 2407 2484 { 2408 2485 ULONG ulRC; 2409 2486 PCH pchNew; 2410 2487 2411 if ( ulBytes == 0 ) return ( FALSE ); 2488 // 2016-02-20 SHL Rework for easier usage 2489 if (!pchBytes) 2490 ulBytes = 0; // Sync for caller 2412 2491 if ( ulBytes > 256 ) { 2413 2492 // REXX provides 256 bytes by default; allocate more if necessary … … 2415 2494 if ( ulRC != 0 ) { 2416 2495 WriteErrorCode( ulRC, "DosAllocMem"); 2496 prsResult->strlength = 0; // 2016-02-20 SHL Force result to empty string 2417 2497 return ( FALSE ); 2418 2498 } … … 2421 2501 prsResult->strptr = pchNew; 2422 2502 } 2423 memcpy( prsResult->strptr, pchBytes, ulBytes ); 2503 if (ulBytes) 2504 memcpy( prsResult->strptr, pchBytes, ulBytes ); 2424 2505 prsResult->strlength = ulBytes; 2425 2506 … … 2442 2523 * TRUE on success, FALSE on failure. * 2443 2524 * ------------------------------------------------------------------------- */ 2444 BOOL WriteStemElement( PSZ pszStem, ULONG ulIndex, PSZ pszValue ) 2525 // 2016-02-20 SHL 2526 BOOL WriteStemElement( PCSZ pszStem, ULONG ulIndex, PCSZ pszValue ) 2445 2527 { 2446 2528 SHVBLOCK shvVar; // REXX shared variable pool block … … 2456 2538 // 2015-06-03 SHL Was using DosAllocMem and leaking memory 2457 2539 // REXX API does not free this kind of buffer 2458 ulBytes = strlen( pszValue);2540 ulBytes = strlen(pszValue); 2459 2541 } 2460 2542 MAKERXSTRING( shvVar.shvname, szCompoundName, strlen(szCompoundName) ); 2461 shvVar.shvvalue.strptr = pszValue;2543 shvVar.shvvalue.strptr = (PCH)pszValue; 2462 2544 shvVar.shvvalue.strlength = ulBytes; 2463 2545 shvVar.shvnamelen = RXSTRLEN( shvVar.shvname ); … … 2489 2571 * RETURNS: N/A * 2490 2572 * ------------------------------------------------------------------------- */ 2491 void WriteErrorCode( ULONG ulError, P SZ pszContext )2573 void WriteErrorCode( ULONG ulError, PCSZ pszContext ) 2492 2574 { 2493 2575 SHVBLOCK shvVar; // REXX shared variable pool block … … 2500 2582 sprintf( szErrorText, "%u: %s", ulError, pszContext ); 2501 2583 MAKERXSTRING( shvVar.shvname, SZ_ERROR_NAME, strlen(SZ_ERROR_NAME) ); 2502 MAKERXSTRING( shvVar.shvvalue, szErrorText, 2584 MAKERXSTRING( shvVar.shvvalue, szErrorText, strlen(szErrorText) ); 2503 2585 shvVar.shvnamelen = RXSTRLEN( shvVar.shvname ); 2504 2586 shvVar.shvvaluelen = RXSTRLEN( shvVar.shvvalue ); 2505 2587 shvVar.shvcode = RXSHV_SYSET; 2506 2588 shvVar.shvnext = NULL; 2589 shvVar.shvret = 0; // 2016-02-26 SHL 2507 2590 ulRc = RexxVariablePool( &shvVar ); 2508 if ( ulRc > 1 )2509 printf("Unable to set %s: rc = %d, ulRc = %x\n", shvVar.shvname.strptr, shvVar.shvret, ulRc ); /* 2015-04-23 SHL */2510 } 2511 2512 2591 // 2016-02-26 SHL Correct if 2592 if ( ulRc & ~RXSHV_NEWV ) 2593 printf("* Unable to set %s: shvret = 0x%x, apiret = 0x%x\n", shvVar.shvname.strptr, (UCHAR)shvVar.shvret, ulRc ); // 2016-02-26 SHL Correct formatting 2594 } 2595 -
rxutilex/trunk/rxutilex.def
r30 r31 1 1 LIBRARY RXUTILEX INITINSTANCE TERMINSTANCE 2 2 DATA MULTIPLE NONSHARED 3 DESCRIPTION '@#Alex Taylor:0.1.3#@##1## 27 Jan 2016 00:26:24REINFORCE::::::@@Extended REXX Utility Functions'3 DESCRIPTION '@#Alex Taylor:0.1.3#@##1## 30 Mar 2016 18:58:46 REINFORCE::::::@@Extended REXX Utility Functions' 4 4 5 5 EXPORTS Sys2LoadFuncs
Note:
See TracChangeset
for help on using the changeset viewer.