1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
|
/* File: "os_shell.c", Time-stamp: <2007-12-19 13:51:53 feeley> */
/* Copyright (c) 1994-2007 by Marc Feeley, All Rights Reserved. */
/*
* This module implements the operating system specific routines
* related to the shell.
*/
#define ___INCLUDED_FROM_OS_SHELL
#define ___VERSION 402008
#include "gambit.h"
#include "os_base.h"
#include "os_shell.h"
#include "os_files.h"
/*---------------------------------------------------------------------------*/
___shell_module ___shell_mod =
{
0
#ifdef ___SHELL_MODULE_INIT
___SHELL_MODULE_INIT
#endif
};
/*---------------------------------------------------------------------------*/
/* Access to shell environment variables. */
/****************** obsolete.... use ___getenv_UCS_2 */
char *___getenv
___P((char *name),
(name)
char *name;)
{
return getenv (name);
}
#define GETENV_NAME_STATIC_SIZE 128
#define GETENV_VALUE_STATIC_SIZE 128
#define SETENV_NAME_STATIC_SIZE 128
#define SETENV_VALUE_STATIC_SIZE 128
#define UNSETENV_NAME_STATIC_SIZE 128
___SCMOBJ ___getenv_UCS_2
___P((___UCS_2STRING name,
___UCS_2STRING *value),
(name,
value)
___UCS_2STRING name;
___UCS_2STRING *value;)
{
___SCMOBJ e;
___UCS_2STRING v;
___UCS_2STRING p1;
int name_len;
/* reject strings that contain "=" except as the first character */
p1 = name;
if (*p1 == '=')
p1++;
while (*p1 != '\0')
{
#if ENV_CHAR_BYTES == 1
if (*p1 > 255)
return ___FIX(___IMPL_LIMIT_ERR);
#endif
if (*p1++ == '=')
return ___FIX(___IMPL_LIMIT_ERR);
}
name_len = p1 - name;
/* find in the environment a string of the form name=value */
e = ___FIX(___NO_ERR);
*value = 0;
#ifdef USE_environ
{
char **probe;
char *p2;
probe = environ;
while ((p2 = *probe++) != 0)
{
p1 = name;
while (*p1 != '\0' &&
*p1 == ___CAST(___UCS_2,___CAST(unsigned char,*p2)))
{
p1++;
p2++;
}
if (*p1 == '\0' && *p2 == '=')
{
int len = 0;
p2++;
while (p2[len] != '\0')
len++;
v = ___CAST(___UCS_2STRING,
___alloc_mem (sizeof (___UCS_2) * (len+1)));
if (v == 0)
return ___FIX(___HEAP_OVERFLOW_ERR);
do
{
v[len] = ___CAST(___UCS_2,___CAST(unsigned char,p2[len]));
} while (len-- > 0);
*value = v;
}
}
}
#else
{
#if ENV_CHAR_BYTES == 1
char *cvalue_ptr = 0;
char cname[GETENV_NAME_STATIC_SIZE];
char *cname_ptr = cname;
if (name_len >= GETENV_NAME_STATIC_SIZE)
{
cname_ptr = ___CAST(char*,
___alloc_mem (sizeof (*cname_ptr)
* (name_len+1)));
if (cname_ptr == 0)
return ___FIX(___HEAP_OVERFLOW_ERR);
}
do
{
cname_ptr[name_len] = name[name_len];
} while (name_len-- > 0);
#else
___UCS_2 *cvalue_ptr = 0;
___UCS_2 *cname_ptr = name;
#endif
#ifndef USE_getenv
#ifndef USE_GetEnvironmentVariable
if (cvalue_ptr != 0)
#endif
#endif
#ifdef USE_getenv
cvalue_ptr = getenv (cname_ptr);
if (cvalue_ptr != 0)
#endif
#ifdef USE_GetEnvironmentVariable
{
___CHAR_TYPE(___GETENV_CE_SELECT) cvalue[GETENV_VALUE_STATIC_SIZE];
int n;
cvalue_ptr = cvalue;
n = GetEnvironmentVariable
(cname_ptr,
cvalue_ptr,
GETENV_VALUE_STATIC_SIZE);
if (n >= GETENV_VALUE_STATIC_SIZE)
{
cvalue_ptr = ___CAST(___CHAR_TYPE(___GETENV_CE_SELECT)*,
___alloc_mem (sizeof (*cvalue_ptr) * n));
if (cvalue_ptr != 0)
n = GetEnvironmentVariable
(cname_ptr,
cvalue_ptr,
n);
}
if (cvalue_ptr == 0)
e = ___FIX(___HEAP_OVERFLOW_ERR);
else if (n > 0)
#endif
{
___UCS_2STRING v;
int len = 0;
while (cvalue_ptr[len] != '\0')
len++;
v = ___CAST(___UCS_2STRING,
___alloc_mem (sizeof (___UCS_2) * (len+1)));
if (v == 0)
e = ___FIX(___HEAP_OVERFLOW_ERR);
else
{
do
{
v[len] = ___CAST(___UCS_2,cvalue_ptr[len]);
} while (len-- > 0);
*value = v;
}
}
#ifdef USE_GetEnvironmentVariable
if (cvalue_ptr != cvalue)
___free_mem (cvalue_ptr);
}
#endif
#if ENV_CHAR_BYTES == 1
if (cname_ptr != cname)
___free_mem (cname_ptr);
#endif
}
#endif
return e;
}
___SCMOBJ ___setenv_UCS_2
___P((___UCS_2STRING name,
___UCS_2STRING value),
(name,
value)
___UCS_2STRING name;
___UCS_2STRING value;)
{
___SCMOBJ e;
___UCS_2STRING p1;
int name_len;
int value_len;
/* reject strings that contain "=" except as the first character */
p1 = name;
if (*p1 == '=')
p1++;
while (*p1 != '\0')
{
#if ENV_CHAR_BYTES == 1
if (*p1 > 255)
return ___FIX(___IMPL_LIMIT_ERR);
#endif
if (*p1++ == '=')
return ___FIX(___IMPL_LIMIT_ERR);
}
name_len = p1 - name;
p1 = value;
while (*p1 != '\0')
{
#if ENV_CHAR_BYTES == 1
if (*p1 > 255)
return ___FIX(___IMPL_LIMIT_ERR);
#endif
p1++;
}
value_len = p1 - value;
/* find in the environment a string of the form name=value */
e = ___FIX(___NO_ERR);
#ifdef USE_environ
{
char **old_environ = environ;
char **probe;
char *p2;
char *name_value = ___CAST(char*,
___alloc_mem (name_len + value_len + 2));
if (name_value == 0)
return ___FIX(___HEAP_OVERFLOW_ERR);
p2 = name_value;
p1 = name;
while (name_len > 0)
{
*p2++ = ___CAST(char,*p1++);
name_len--;
}
*p2++ = '=';
p1 = value;
while (value_len > 0)
{
*p2++ = ___CAST(char,*p1++);
value_len--;
}
*p2++ = '\0';
probe = old_environ;
while ((p2 = *probe++) != 0)
{
p1 = name;
while (*p1 != '\0' &&
*p1 == ___CAST(___UCS_2,___CAST(unsigned char,*p2)))
{
p1++;
p2++;
}
if (*p1 == '\0' && *p2 == '=')
{
probe[-1] = name_value;
return ___FIX(___NO_ERR);
}
}
if (___shell_mod.environ_unused_at_end > 0)
{
probe[-1] = name_value;
probe[0] = 0;
___shell_mod.environ_unused_at_end--;
return ___FIX(___NO_ERR);
}
else
{
char **new_environ;
int n = probe - old_environ; /* length including null pointer at end */
___shell_mod.environ_unused_at_end = n/2 + 1;
new_environ =
___CAST(char**,
___alloc_mem ((n + ___shell_mod.environ_unused_at_end)
* sizeof (char*)));
if (new_environ == 0)
{
___free_mem (name_value);
return ___FIX(___HEAP_OVERFLOW_ERR);
}
environ = new_environ;
probe = old_environ;
while (--n > 0)
*new_environ++ = *probe++;
*new_environ++ = name_value;
*new_environ++ = 0;
___shell_mod.environ_unused_at_end--;
if (___shell_mod.environ_was_extended)
___free_mem (old_environ);
___shell_mod.environ_was_extended = 1;
}
}
#else
{
#if ENV_CHAR_BYTES == 1
char *cname_ptr;
char *cvalue_ptr;
char cname[SETENV_NAME_STATIC_SIZE];
char cvalue[SETENV_VALUE_STATIC_SIZE];
if (name_len < SETENV_NAME_STATIC_SIZE)
cname_ptr = cname;
else
{
cname_ptr = ___CAST(char*,
___alloc_mem (sizeof (*cname_ptr)
* (name_len+1)));
if (cname_ptr == 0)
return ___FIX(___HEAP_OVERFLOW_ERR);
}
do
{
cname_ptr[name_len] = name[name_len];
} while (name_len-- > 0);
if (value_len < SETENV_VALUE_STATIC_SIZE)
cvalue_ptr = cvalue;
else
{
cvalue_ptr = ___CAST(char*,
___alloc_mem (sizeof (*cvalue_ptr)
* (value_len+1)));
if (cvalue_ptr == 0)
{
if (cname_ptr != cname)
___free_mem (cname_ptr);
return ___FIX(___HEAP_OVERFLOW_ERR);
}
}
do
{
cvalue_ptr[value_len] = value[value_len];
} while (value_len-- > 0);
#else
___UCS_2 *cname_ptr = name;
___UCS_2 *cvalue_ptr = value;
#endif
#ifdef USE_setenv
if (setenv (cname_ptr, cvalue_ptr, 1) < 0)
e = err_code_from_errno ();
#endif
#ifdef USE_SetEnvironmentVariable
if (!SetEnvironmentVariable (cname_ptr, cvalue_ptr))
e = err_code_from_GetLastError ();
#endif
#if ENV_CHAR_BYTES == 1
if (cvalue_ptr != cvalue)
___free_mem (cvalue_ptr);
if (cname_ptr != cname)
___free_mem (cname_ptr);
#endif
}
#endif
return e;
}
___SCMOBJ ___unsetenv_UCS_2
___P((___UCS_2STRING name),
(name)
___UCS_2STRING name;)
{
___SCMOBJ e;
___UCS_2STRING p1;
int name_len;
/* reject strings that contain "=" except as the first character */
p1 = name;
if (*p1 == '=')
p1++;
while (*p1 != '\0')
{
#if ENV_CHAR_BYTES == 1
if (*p1 > 255)
return ___FIX(___IMPL_LIMIT_ERR);
#endif
if (*p1++ == '=')
return ___FIX(___IMPL_LIMIT_ERR);
}
name_len = p1 - name;
/* find in the environment a string of the form name=value */
e = ___FIX(___NO_ERR);
#ifdef USE_environ
{
char **probe;
char *p2;
probe = environ;
while ((p2 = *probe++) != 0)
{
p1 = name;
while (*p1 != '\0' &&
*p1 == ___CAST(___UCS_2,___CAST(unsigned char,*p2)))
{
p1++;
p2++;
}
if (*p1 == '\0' && *p2 == '=')
{
___shell_mod.environ_unused_at_end++;
while ((probe[-1] = probe[0]) != 0)
probe++;
return ___FIX(___NO_ERR);
}
}
}
#else
{
#if ENV_CHAR_BYTES == 1
char *cname_ptr;
char cname[UNSETENV_NAME_STATIC_SIZE];
if (name_len < UNSETENV_NAME_STATIC_SIZE)
cname_ptr = cname;
else
{
cname_ptr = ___CAST(char*,
___alloc_mem (sizeof (*cname_ptr)
* (name_len+1)));
if (cname_ptr == 0)
return ___FIX(___HEAP_OVERFLOW_ERR);
}
do
{
cname_ptr[name_len] = name[name_len];
} while (name_len-- > 0);
#else
___UCS_2 *cname_ptr = name;
#endif
#ifdef USE_unsetenv
if (unsetenv (cname_ptr) < 0)
e = err_code_from_errno ();
#endif
#ifdef USE_SetEnvironmentVariable
if (!SetEnvironmentVariable (cname_ptr, 0))
{
e = err_code_from_GetLastError ();
/*
* Apparently an error is signaled if the environment
* variable being removed does not exist (the Microsoft
* documentation does not mention this).
*/
if (e == ___FIX(___WIN32_ERR(ERROR_ENVVAR_NOT_FOUND)))
e = ___FIX(___NO_ERR);
}
#endif
#if ENV_CHAR_BYTES == 1
if (cname_ptr != cname)
___free_mem (cname_ptr);
#endif
}
#endif
return e;
}
___SCMOBJ ___os_getenv
___P((___SCMOBJ name),
(name)
___SCMOBJ name;)
{
___SCMOBJ e;
___SCMOBJ result;
___UCS_2STRING cname;
___UCS_2STRING cvalue;
if ((e = ___SCMOBJ_to_NONNULLUCS_2STRING
(name,
&cname,
1))
!= ___FIX(___NO_ERR))
result = e;
else
{
if ((e = ___getenv_UCS_2 (cname, &cvalue)) != ___FIX(___NO_ERR))
result = e;
else
{
if ((e = ___UCS_2STRING_to_SCMOBJ
(cvalue,
&result,
___RETURN_POS))
!= ___FIX(___NO_ERR))
result = e;
else
___release_scmobj (result);
if (cvalue != 0)
___free_mem (cvalue);
}
___release_string (cname);
}
return result;
}
___SCMOBJ ___os_setenv
___P((___SCMOBJ name,
___SCMOBJ value),
(name,
value)
___SCMOBJ name;
___SCMOBJ value;)
{
___SCMOBJ e;
___UCS_2STRING cname;
___UCS_2STRING cvalue;
if ((e = ___SCMOBJ_to_NONNULLUCS_2STRING
(name,
&cname,
1))
== ___FIX(___NO_ERR))
{
if (value == ___ABSENT)
e = ___unsetenv_UCS_2 (cname);
else if ((e = ___SCMOBJ_to_NONNULLUCS_2STRING
(value,
&cvalue,
2))
== ___FIX(___NO_ERR))
{
e = ___setenv_UCS_2 (cname, cvalue);
___release_string (cvalue);
}
___release_string (cname);
}
return e;
}
___SCMOBJ ___os_environ ___PVOID
{
___SCMOBJ e;
___SCMOBJ result;
#ifndef USE_environ
#ifndef USE_GetEnvironmentStrings
result = ___NUL;
#endif
#endif
#ifdef USE_environ
if ((e = ___NONNULLCHARSTRINGLIST_to_SCMOBJ
(environ,
&result,
___RETURN_POS))
!= ___FIX(___NO_ERR))
result = e;
else
___release_scmobj (result);
#endif
#ifdef USE_GetEnvironmentStrings
___STRING_TYPE(___ENVIRON_CE_SELECT) env;
___STRING_TYPE(___ENVIRON_CE_SELECT) ptr;
___SCMOBJ pair;
___SCMOBJ str;
e = ___FIX(___NO_ERR);
result = ___NUL;
env = GetEnvironmentStrings ();
if (env != 0 && *env != 0)
{
ptr = env;
/* find end of environment strings. */
do
{
do { ptr++; } while (*ptr != 0);
ptr++; /* skip null char at end of string */
} while (*ptr != 0);
while (ptr > env)
{
ptr--; /* move ptr to terminating null char of previous string */
while (ptr > env && ptr[-1] != 0)
ptr--;
if ((e = ___NONNULLSTRING_to_SCMOBJ
(ptr,
&str,
___RETURN_POS,
___CE(___ENVIRON_CE_SELECT)))
!= ___FIX(___NO_ERR))
break;
pair = ___make_pair (str, result, ___STILL);
___release_scmobj (str);
___release_scmobj (result);
if (___FIXNUMP(pair))
{
e = ___FIX(___CTOS_HEAP_OVERFLOW_ERR+___RETURN_POS);
break;
}
result = pair;
}
___release_scmobj (result);
}
if (env != 0)
if (!FreeEnvironmentStrings (env))
e = err_code_from_GetLastError ();
if (e != ___FIX(___NO_ERR))
result = e;
#endif
return result;
}
/*---------------------------------------------------------------------------*/
/* Shell command. */
___SCMOBJ ___os_shell_command
___P((___SCMOBJ cmd,
___SCMOBJ dir),
(cmd,
dir)
___SCMOBJ cmd;
___SCMOBJ dir;)
{
___SCMOBJ e;
#ifndef USE_POSIX
#ifndef USE_WIN32
e = ___FIX(___UNIMPL_ERR);
#endif
#endif
#ifdef USE_POSIX
char *ccmd;
if ((e = ___SCMOBJ_to_NONNULLCHARSTRING
(cmd,
&ccmd,
1))
== ___FIX(___NO_ERR))
{
void *cdir;
if ((e = ___SCMOBJ_to_NONNULLSTRING
(dir,
&cdir,
2,
___CE(___PATH_CE_SELECT),
0))
== ___FIX(___NO_ERR))
{
int code;
___CHAR_TYPE(___PATH_CE_SELECT) old_dir[___PATH_MAX_LENGTH+1];
if (getcwd (old_dir, ___PATH_MAX_LENGTH) == 0)
e = err_code_from_errno ();
else
{
if (chdir (___CAST(___STRING_TYPE(___PATH_CE_SELECT),cdir)) < 0)
e = err_code_from_errno ();
else
{
___disable_os_interrupts ();
code = system (ccmd);
if (code == -1)
e = err_code_from_errno ();
else
e = ___FIX(code & ___MAX_FIX);
___enable_os_interrupts ();
chdir (old_dir); /* ignore error */
}
}
___release_string (cdir);
}
___release_string (ccmd);
}
#endif
#ifdef USE_WIN32
#ifdef _UNICODE
#define ___SHELL_COMMAND_CE_SELECT(latin1,utf8,ucs2,ucs4,wchar,native) ucs2
#else
#define ___SHELL_COMMAND_CE_SELECT(latin1,utf8,ucs2,ucs4,wchar,native) native
#endif
void *ccmd;
if ((e = ___SCMOBJ_to_NONNULLSTRING
(cmd,
&ccmd,
1,
___CE(___SHELL_COMMAND_CE_SELECT),
0))
== ___FIX(___NO_ERR))
{
void *cdir;
if ((e = ___SCMOBJ_to_STRING
(dir,
&cdir,
2,
___CE(___PATH_CE_SELECT),
0))
== ___FIX(___NO_ERR))
{
DWORD n;
___CHAR_TYPE(___PATH_CE_SELECT) old_dir[___PATH_MAX_LENGTH+1];
n = GetCurrentDirectory (___PATH_MAX_LENGTH+1,
old_dir);
if (n < 1 || n > ___PATH_MAX_LENGTH)
e = err_code_from_GetLastError ();
else
{
if (!SetCurrentDirectory (___CAST(___STRING_TYPE(___PATH_CE_SELECT),cdir)))
e = err_code_from_GetLastError ();
else
{
#ifdef ___DO_NOT_USE_system
/*
* This code does not really cause the shell to run
* the command. This means that the shell builtin
* commands (such as "DIR" cannot be executed. It
* is better to use "system" and "_wsystem".
*/
DWORD code;
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory (&si, sizeof (si));
si.cb = sizeof (si);
ZeroMemory (&pi, sizeof (pi));
if (!CreateProcess
(NULL, /* module name */
___CAST(___STRING_TYPE(___SHELL_COMMAND_CE_SELECT),ccmd),
NULL, /* process handle not inheritable */
NULL, /* thread handle not inheritable */
FALSE, /* set handle inheritance to FALSE */
0, /* no creation flags */
NULL, /* use parent's environment block */
NULL, /* use parent's starting directory */
&si, /* pointer to STARTUPINFO structure */
&pi)) /* pointer to PROCESS_INFORMATION structure */
e = err_code_from_GetLastError ();
else
{
if (WaitForSingleObject (pi.hProcess, INFINITE) == WAIT_FAILED ||
!GetExitCodeProcess (pi.hProcess, &code))
e = err_code_from_GetLastError ();
else
e = ___FIX(code & ___MAX_FIX);
CloseHandle (pi.hProcess); /* ignore error */
CloseHandle (pi.hThread); /* ignore error */
}
#else
int code;
#ifdef _UNICODE
code = _wsystem (___CAST(___STRING_TYPE(___SHELL_COMMAND_CE_SELECT),ccmd));
#else
code = system (___CAST(___STRING_TYPE(___SHELL_COMMAND_CE_SELECT),ccmd));
#endif
if (code == -1)
e = err_code_from_errno ();
else
e = ___FIX(code & ___MAX_FIX);
#endif
SetCurrentDirectory (old_dir); /* ignore error */
}
}
___release_string (cdir);
}
___release_string (ccmd);
}
#endif
return e;
}
/*---------------------------------------------------------------------------*/
/* Shell module initialization/finalization. */
___SCMOBJ ___setup_shell_module ___PVOID
{
if (!___shell_mod.setup)
{
#ifdef USE_environ
___shell_mod.environ_unused_at_end = 0;
___shell_mod.environ_was_extended = 0;
#endif
___shell_mod.setup = 1;
return ___FIX(___NO_ERR);
}
return ___FIX(___UNKNOWN_ERR);
}
void ___cleanup_shell_module ___PVOID
{
if (___shell_mod.setup)
{
#ifdef USE_environ
if (___shell_mod.environ_was_extended)
___free_mem (environ);
#endif
___shell_mod.setup = 0;
}
}
/*---------------------------------------------------------------------------*/
|