1 /* $Header: eval.c,v 3.0.1.10 90/11/10 01:33:22 lwall Locked $
3 * Copyright (c) 1989, Larry Wall
5 * You may distribute under the terms of the GNU General Public License
6 * as specified in the README file that comes with the perl 3.0 kit.
9 * Revision 3.0.1.10 90/11/10 01:33:22 lwall
10 * patch38: random cleanup
11 * patch38: couldn't return from sort routine
12 * patch38: added hooks for unexec()
13 * patch38: added alarm function
15 * Revision 3.0.1.9 90/10/15 16:46:13 lwall
16 * patch29: added caller
17 * patch29: added scalar
18 * patch29: added cmp and <=>
19 * patch29: added sysread and syswrite
20 * patch29: added -M, -A and -C
21 * patch29: index and substr now have optional 3rd args
22 * patch29: you can now read into the middle string
23 * patch29: ~ now works on vector string
24 * patch29: non-existent array values no longer cause core dumps
25 * patch29: eof; core dumped
26 * patch29: oct and hex now produce unsigned result
27 * patch29: unshift did not return the documented value
29 * Revision 3.0.1.8 90/08/13 22:17:14 lwall
30 * patch28: the NSIG hack didn't work right on Xenix
31 * patch28: defined(@array) and defined(%array) didn't work right
32 * patch28: rename was busted on systems without rename system call
34 * Revision 3.0.1.7 90/08/09 03:33:44 lwall
35 * patch19: made ~ do vector operation on strings like &, | and ^
36 * patch19: dbmopen(%name...) didn't work right
37 * patch19: dbmopen(name, 'filename', undef) now refrains from creating
38 * patch19: empty %array now returns 0 in scalar context
39 * patch19: die with no arguments no longer exits unconditionally
40 * patch19: return outside a subroutine now returns a reasonable message
41 * patch19: rename done with unlink()/link()/unlink() now checks for clobbering
42 * patch19: -s now returns size of file
44 * Revision 3.0.1.6 90/03/27 15:53:51 lwall
45 * patch16: MSDOS support
46 * patch16: support for machines that can't cast negative floats to unsigned ints
47 * patch16: ioctl didn't return values correctly
49 * Revision 3.0.1.5 90/03/12 16:37:40 lwall
50 * patch13: undef $/ didn't work as advertised
51 * patch13: added list slice operator (LIST)[LIST]
52 * patch13: added splice operator: @oldelems = splice(@array,$offset,$len,LIST)
54 * Revision 3.0.1.4 90/02/28 17:36:59 lwall
55 * patch9: added pipe function
56 * patch9: a return in scalar context wouldn't return array
57 * patch9: !~ now always returns scalar even in array context
58 * patch9: some machines can't cast float to long with high bit set
59 * patch9: piped opens returned undef in child
60 * patch9: @array in scalar context now returns length of array
61 * patch9: chdir; coredumped
62 * patch9: wait no longer ignores signals
63 * patch9: mkdir now handles odd versions of /bin/mkdir
64 * patch9: -l FILEHANDLE now disallowed
66 * Revision 3.0.1.3 89/12/21 20:03:05 lwall
67 * patch7: errno may now be a macro with an lvalue
68 * patch7: ANSI strerror() is now supported
69 * patch7: send() didn't allow a TO argument
70 * patch7: ord() now always returns positive even on signed char machines
72 * Revision 3.0.1.2 89/11/17 15:19:34 lwall
73 * patch5: constant numeric subscripts get lost inside ?:
75 * Revision 3.0.1.1 89/11/11 04:31:51 lwall
76 * patch2: mkdir and rmdir needed to quote argument when passed to shell
77 * patch2: mkdir and rmdir now return better error codes
78 * patch2: fileno, seekdir, rewinddir and closedir now disallow defaults
80 * Revision 3.0 89/10/18 15:17:04 lwall
88 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
100 static void (*ihand)();
101 static void (*qhand)();
103 static int (*ihand)();
104 static int (*qhand)();
111 static struct lstring *lstr;
112 static int old_record_separator;
114 double sin(), cos(), atan2(), pow();
135 int arglast[8]; /* highest sp for arg--valid only for non-O_LIST args */
136 unsigned long tmplong;
143 bool assigning = FALSE;
144 double exp(), log(), sqrt(), modf();
145 char *crypt(), *getenv();
146 extern void grow_dlevel();
150 optype = arg->arg_type;
151 maxarg = arg->arg_len;
153 str = arg->arg_ptr.arg_str;
154 if (sp + maxarg > stack->ary_max)
155 astore(stack, sp + maxarg, Nullstr);
156 st = stack->ary_array;
161 deb("%s (%lx) %d args:\n",opname[optype],arg,maxarg);
163 debname[dlevel] = opname[optype][0];
164 debdelim[dlevel] = ':';
165 if (++dlevel >= dlmax)
170 #include "evalargs.xc"
178 if (gimme == G_ARRAY)
186 if (gimme == G_ARRAY)
189 STR_SSET(str,st[arglast[anum]-arglast[0]]);
193 if (gimme == G_ARRAY)
196 STR_SSET(str,st[arglast[anum]-arglast[0]]);
206 anum = (int)str_gnum(st[2]);
208 tmpstr = Str_new(50, 0);
209 str_sset(tmpstr,str);
210 tmps = str_get(tmpstr); /* force to be string */
211 STR_GROW(str, (anum * str->str_cur) + 1);
212 repeatcpy(str->str_ptr, tmps, tmpstr->str_cur, anum);
213 str->str_cur *= anum;
214 str->str_ptr[str->str_cur] = '\0';
217 str_sset(str,&str_no);
221 sp = do_match(str,arg,
223 if (gimme == G_ARRAY)
228 sp = do_match(str,arg,
230 str_sset(str, str_true(str) ? &str_no : &str_yes);
234 sp = do_subst(str,arg,arglast[0]);
237 sp = do_subst(str,arg,arglast[0]);
238 str = arg->arg_ptr.arg_str;
239 str_set(str, str_true(str) ? No : Yes);
242 if (arg[1].arg_flags & AF_ARYOK) {
243 if (arg->arg_len == 1) {
244 arg->arg_type = O_LOCAL;
248 arg->arg_type = O_AASSIGN;
253 arg->arg_type = O_SASSIGN;
258 arglast[2] = arglast[1]; /* push a null array */
267 STR_SSET(str, st[2]);
272 str = arg->arg_ptr.arg_str;
273 for (sp = arglast[0] + 1; sp <= arglast[1]; sp++)
278 if (arg[1].arg_type & A_DONT) {
279 sp = do_defined(str,arg,
283 else if (str->str_pok || str->str_nok)
287 if (arg[1].arg_type & A_DONT) {
288 sp = do_undef(str,arg,
292 else if (str != stab_val(defstab)) {
293 str->str_pok = str->str_nok = 0;
298 sp = do_study(str,arg,
302 value = str_gnum(st[1]);
303 value = pow(value,str_gnum(st[2]));
306 value = str_gnum(st[1]);
307 value *= str_gnum(st[2]);
310 if ((value = str_gnum(st[2])) == 0.0)
311 fatal("Illegal division by zero");
312 value = str_gnum(st[1]) / value;
315 tmplong = (long) str_gnum(st[2]);
317 fatal("Illegal modulus zero");
318 when = (long)str_gnum(st[1]);
321 value = (double)(when % tmplong);
323 value = (double)(tmplong - ((-when - 1) % tmplong)) - 1;
327 value = str_gnum(st[1]);
328 value += str_gnum(st[2]);
331 value = str_gnum(st[1]);
332 value -= str_gnum(st[2]);
335 value = str_gnum(st[1]);
336 anum = (int)str_gnum(st[2]);
338 value = (double)(U_L(value) << anum);
342 value = str_gnum(st[1]);
343 anum = (int)str_gnum(st[2]);
345 value = (double)(U_L(value) >> anum);
349 value = str_gnum(st[1]);
350 value = (value < str_gnum(st[2])) ? 1.0 : 0.0;
353 value = str_gnum(st[1]);
354 value = (value > str_gnum(st[2])) ? 1.0 : 0.0;
357 value = str_gnum(st[1]);
358 value = (value <= str_gnum(st[2])) ? 1.0 : 0.0;
361 value = str_gnum(st[1]);
362 value = (value >= str_gnum(st[2])) ? 1.0 : 0.0;
366 if ((!st[1]->str_nok && !looks_like_number(st[1])) ||
367 (!st[2]->str_nok && !looks_like_number(st[2])) )
368 warn("Possible use of == on string value");
370 value = str_gnum(st[1]);
371 value = (value == str_gnum(st[2])) ? 1.0 : 0.0;
374 value = str_gnum(st[1]);
375 value = (value != str_gnum(st[2])) ? 1.0 : 0.0;
378 value = str_gnum(st[1]);
379 value -= str_gnum(st[2]);
382 else if (value < 0.0)
386 if (!sawvec || st[1]->str_nok || st[2]->str_nok) {
387 value = str_gnum(st[1]);
389 value = (double)(U_L(value) & U_L(str_gnum(st[2])));
394 do_vop(optype,str,st[1],st[2]);
397 if (!sawvec || st[1]->str_nok || st[2]->str_nok) {
398 value = str_gnum(st[1]);
400 value = (double)(U_L(value) ^ U_L(str_gnum(st[2])));
405 do_vop(optype,str,st[1],st[2]);
408 if (!sawvec || st[1]->str_nok || st[2]->str_nok) {
409 value = str_gnum(st[1]);
411 value = (double)(U_L(value) | U_L(str_gnum(st[2])));
416 do_vop(optype,str,st[1],st[2]);
418 /* use register in evaluating str_true() */
420 if (str_true(st[1])) {
423 argflags = arg[anum].arg_flags;
424 if (gimme == G_ARRAY)
425 argflags |= AF_ARYOK;
426 argtype = arg[anum].arg_type & A_MASK;
427 argptr = arg[anum].arg_ptr;
435 str_sset(str, st[1]);
443 if (str_true(st[1])) {
445 str_sset(str, st[1]);
455 argflags = arg[anum].arg_flags;
456 if (gimme == G_ARRAY)
457 argflags |= AF_ARYOK;
458 argtype = arg[anum].arg_type & A_MASK;
459 argptr = arg[anum].arg_ptr;
466 anum = (str_true(st[1]) ? 2 : 3);
467 optype = (anum == 2 ? O_ITEM2 : O_ITEM3);
468 argflags = arg[anum].arg_flags;
469 if (gimme == G_ARRAY)
470 argflags |= AF_ARYOK;
471 argtype = arg[anum].arg_type & A_MASK;
472 argptr = arg[anum].arg_ptr;
478 if (gimme == G_ARRAY)
483 value = -str_gnum(st[1]);
486 value = (double) !str_true(st[1]);
489 if (!sawvec || st[1]->str_nok) {
491 value = (double) ~U_L(str_gnum(st[1]));
498 for (anum = str->str_cur; anum; anum--, tmps++)
503 stab_fullname(str,defoutstab);
505 if ((arg[1].arg_type & A_MASK) == A_WORD)
506 defoutstab = arg[1].arg_ptr.arg_stab;
508 defoutstab = stabent(str_get(st[1]),TRUE);
509 if (!stab_io(defoutstab))
510 stab_io(defoutstab) = stio_new();
511 curoutstab = defoutstab;
518 else if ((arg[1].arg_type & A_MASK) == A_WORD) {
519 if (!(stab = arg[1].arg_ptr.arg_stab))
523 stab = stabent(str_get(st[1]),TRUE);
524 if (!stab_io(stab)) {
530 fp = stab_io(stab)->ofp;
532 if (stab_io(stab)->fmt_stab)
533 form = stab_form(stab_io(stab)->fmt_stab);
535 form = stab_form(stab);
539 warn("No format for filehandle");
541 if (stab_io(stab)->ifp)
542 warn("Filehandle only opened for input");
544 warn("Write on closed filehandle");
551 format(&outrec,form,sp);
552 do_write(&outrec,stab_io(stab),sp);
553 if (stab_io(stab)->flags & IOF_FLUSH)
560 stab = arg[1].arg_ptr.arg_stab;
561 if (st[3]->str_nok || st[3]->str_pok)
562 anum = (int)str_gnum(st[3]);
565 value = (double)hdbmopen(stab_hash(stab),str_get(st[2]),anum);
568 fatal("No dbm or ndbm on this machine");
572 stab = arg[1].arg_ptr.arg_stab;
573 hdbmclose(stab_hash(stab));
576 fatal("No dbm or ndbm on this machine");
579 if ((arg[1].arg_type & A_MASK) == A_WORD)
580 stab = arg[1].arg_ptr.arg_stab;
582 stab = stabent(str_get(st[1]),TRUE);
583 tmps = str_get(st[2]);
584 if (do_open(stab,tmps,st[2]->str_cur)) {
585 value = (double)forkprocess;
586 stab_io(stab)->lines = 0;
589 else if (forkprocess == 0) /* we are a new child */
595 value = (double) do_trans(str,arg);
596 str = arg->arg_ptr.arg_str;
599 str_set(arg->arg_ptr.arg_str, do_trans(str,arg) == 0 ? Yes : No);
600 str = arg->arg_ptr.arg_str;
605 else if ((arg[1].arg_type & A_MASK) == A_WORD)
606 stab = arg[1].arg_ptr.arg_stab;
608 stab = stabent(str_get(st[1]),TRUE);
609 str_set(str, do_close(stab,TRUE) ? Yes : No );
613 sp = do_each(str,stab_hash(arg[1].arg_ptr.arg_stab),
618 sp = do_kv(str,stab_hash(arg[1].arg_ptr.arg_stab), optype,
622 str->str_nok = str->str_pok = 0;
623 str->str_u.str_stab = arg[1].arg_ptr.arg_stab;
624 str->str_state = SS_ARY;
627 ary = stab_array(arg[1].arg_ptr.arg_stab);
628 maxarg = ary->ary_fill + 1;
629 if (gimme == G_ARRAY) { /* array wanted */
632 if (maxarg > 0 && sp + maxarg > stack->ary_max) {
633 astore(stack,sp + maxarg, Nullstr);
634 st = stack->ary_array;
637 Copy(ary->ary_array, &st[1], maxarg, STR*);
642 value = (double)maxarg;
646 anum = ((int)str_gnum(st[2])) - arybase;
647 str = afetch(stab_array(arg[1].arg_ptr.arg_stab),anum,FALSE);
650 tmpstab = arg[1].arg_ptr.arg_stab;
651 tmps = str_get(st[2]);
652 str = hdelete(stab_hash(tmpstab),tmps,st[2]->str_cur);
653 if (tmpstab == envstab)
659 str->str_nok = str->str_pok = 0;
660 str->str_u.str_stab = arg[1].arg_ptr.arg_stab;
661 str->str_state = SS_HASH;
664 if (gimme == G_ARRAY) { /* array wanted */
665 sp = do_kv(str,stab_hash(arg[1].arg_ptr.arg_stab), optype,
670 tmpstab = arg[1].arg_ptr.arg_stab;
671 if (!stab_hash(tmpstab)->tbl_fill)
673 sprintf(buf,"%d/%d",stab_hash(tmpstab)->tbl_fill,
674 stab_hash(tmpstab)->tbl_max+1);
679 tmpstab = arg[1].arg_ptr.arg_stab;
680 tmps = str_get(st[2]);
681 str = hfetch(stab_hash(tmpstab),tmps,st[2]->str_cur,FALSE);
684 anum = ((int)str_gnum(st[2])) - arybase;
685 str = afetch(stab_array(arg[1].arg_ptr.arg_stab),anum,TRUE);
686 if (!str || str == &str_undef)
687 fatal("Assignment to non-creatable value, subscript %d",anum);
690 tmpstab = arg[1].arg_ptr.arg_stab;
691 tmps = str_get(st[2]);
692 anum = st[2]->str_cur;
693 str = hfetch(stab_hash(tmpstab),tmps,anum,TRUE);
694 if (!str || str == &str_undef)
695 fatal("Assignment to non-creatable value, subscript \"%s\"",tmps);
696 if (tmpstab == envstab) /* heavy wizardry going on here */
697 str_magic(str, tmpstab, 'E', tmps, anum); /* str is now magic */
698 /* he threw the brick up into the air */
699 else if (tmpstab == sigstab)
700 str_magic(str, tmpstab, 'S', tmps, anum);
702 else if (stab_hash(tmpstab)->tbl_dbm)
703 str_magic(str, tmpstab, 'D', tmps, anum);
705 else if (perldb && tmpstab == DBline)
706 str_magic(str, tmpstab, 'L', tmps, anum);
711 goto do_slice_already;
715 goto do_slice_already;
719 goto do_slice_already;
723 goto do_slice_already;
728 sp = do_slice(arg[1].arg_ptr.arg_stab,str,anum,argtype,
732 sp = do_splice(stab_array(arg[1].arg_ptr.arg_stab),gimme,arglast);
735 if (arglast[2] - arglast[1] != 1)
736 str = do_push(stab_array(arg[1].arg_ptr.arg_stab),arglast);
738 str = Str_new(51,0); /* must copy the STR */
740 (void)apush(stab_array(arg[1].arg_ptr.arg_stab),str);
744 str = apop(ary = stab_array(arg[1].arg_ptr.arg_stab));
745 goto staticalization;
747 str = ashift(ary = stab_array(arg[1].arg_ptr.arg_stab));
751 if (ary->ary_flags & ARF_REAL)
752 (void)str_2static(str);
755 sp = do_unpack(str,gimme,arglast);
758 value = str_gnum(st[3]);
759 sp = do_split(str, arg[2].arg_ptr.arg_spat, (int)value,
764 value = (double)str_len(stab_val(defstab));
766 value = (double)str_len(st[1]);
769 do_sprintf(str, sp-arglast[0], st+1);
772 anum = ((int)str_gnum(st[2])) - arybase; /* anum=where to start*/
773 tmps = str_get(st[1]); /* force conversion to string */
774 if (argtype = (str == st[1]))
775 str = arg->arg_ptr.arg_str;
777 anum += st[1]->str_cur + arybase;
778 if (anum < 0 || anum > st[1]->str_cur)
781 optype = maxarg < 3 ? st[1]->str_cur : (int)str_gnum(st[3]);
785 anum = st[1]->str_cur - anum; /* anum=how many bytes left*/
788 str_nset(str, tmps, anum);
789 if (argtype) { /* it's an lvalue! */
790 lstr = (struct lstring*)str;
791 str->str_magic = st[1];
792 st[1]->str_rare = 's';
793 lstr->lstr_offset = tmps - str_get(st[1]);
794 lstr->lstr_len = anum;
799 (void)do_pack(str,arglast);
802 sp = do_grep(arg,str,gimme,arglast);
805 do_join(str,arglast);
808 tmps = str_get(st[1]);
809 value = (double) (str_cmp(st[1],st[2]) < 0);
812 tmps = str_get(st[1]);
813 value = (double) (str_cmp(st[1],st[2]) > 0);
816 tmps = str_get(st[1]);
817 value = (double) (str_cmp(st[1],st[2]) <= 0);
820 tmps = str_get(st[1]);
821 value = (double) (str_cmp(st[1],st[2]) >= 0);
824 tmps = str_get(st[1]);
825 value = (double) str_eq(st[1],st[2]);
828 tmps = str_get(st[1]);
829 value = (double) !str_eq(st[1],st[2]);
832 tmps = str_get(st[1]);
833 value = (double) str_cmp(st[1],st[2]);
836 sp = do_subr(arg,gimme,arglast);
837 st = stack->ary_array + arglast[0]; /* maybe realloced */
840 sp = do_subr(arg,gimme,arglast);
841 st = stack->ary_array + arglast[0]; /* maybe realloced */
844 sp = do_caller(arg,maxarg,gimme,arglast);
845 st = stack->ary_array + arglast[0]; /* maybe realloced */
848 if ((arg[1].arg_type & A_MASK) == A_WORD)
849 stab = arg[1].arg_ptr.arg_stab;
851 stab = stabent(str_get(st[1]),TRUE);
852 sp = do_sort(str,stab,
856 if (gimme == G_ARRAY)
857 sp = do_reverse(arglast);
859 sp = do_sreverse(str, arglast);
862 if (arglast[2] - arglast[1] != 1) {
863 do_join(str,arglast);
864 tmps = str_get(st[1]);
868 tmps = str_get(st[2]);
871 tmps = "Warning: something's wrong";
875 if (arglast[2] - arglast[1] != 1) {
876 do_join(str,arglast);
877 tmps = str_get(st[1]);
881 tmps = str_get(st[2]);
889 if ((arg[1].arg_type & A_MASK) == A_WORD)
890 stab = arg[1].arg_ptr.arg_stab;
892 stab = stabent(str_get(st[1]),TRUE);
895 if (!stab_io(stab)) {
897 warn("Filehandle never opened");
900 if (!(fp = stab_io(stab)->ofp)) {
902 if (stab_io(stab)->ifp)
903 warn("Filehandle opened only for input");
905 warn("Print on closed filehandle");
910 if (optype == O_PRTF || arglast[2] - arglast[1] != 1)
911 value = (double)do_aprint(arg,fp,arglast);
913 value = (double)do_print(st[2],fp);
914 if (orslen && optype == O_PRINT)
915 if (fwrite(ors, 1, orslen, fp) == 0)
918 if (stab_io(stab)->flags & IOF_FLUSH)
919 if (fflush(fp) == EOF)
927 tmps = str_get(st[1]);
928 if (!tmps || !*tmps) {
929 tmpstr = hfetch(stab_hash(envstab),"HOME",4,FALSE);
930 tmps = str_get(tmpstr);
932 if (!tmps || !*tmps) {
933 tmpstr = hfetch(stab_hash(envstab),"LOGDIR",6,FALSE);
934 tmps = str_get(tmpstr);
937 taintproper("Insecure dependency in chdir");
939 value = (double)(chdir(tmps) >= 0);
945 anum = (int)str_gnum(st[1]);
952 tmps = str_get(st[1]);
953 str_reset(tmps,curcmd->c_stash);
957 if (gimme == G_ARRAY)
960 str = st[sp - arglast[0]]; /* unwanted list, return last item */
967 else if ((arg[1].arg_type & A_MASK) == A_WORD)
968 stab = arg[1].arg_ptr.arg_stab;
970 stab = stabent(str_get(st[1]),TRUE);
971 str_set(str, do_eof(stab) ? Yes : No);
977 else if ((arg[1].arg_type & A_MASK) == A_WORD)
978 stab = arg[1].arg_ptr.arg_stab;
980 stab = stabent(str_get(st[1]),TRUE);
983 if (!stab || do_eof(stab)) /* make sure we have fp with something */
990 *str->str_ptr = getc(stab_io(stab)->ifp); /* should never be EOF */
997 else if ((arg[1].arg_type & A_MASK) == A_WORD)
998 stab = arg[1].arg_ptr.arg_stab;
1000 stab = stabent(str_get(st[1]),TRUE);
1002 value = (double)do_tell(stab);
1004 (void)do_tell(stab);
1010 if ((arg[1].arg_type & A_MASK) == A_WORD)
1011 stab = arg[1].arg_ptr.arg_stab;
1013 stab = stabent(str_get(st[1]),TRUE);
1014 tmps = str_get(st[2]);
1015 anum = (int)str_gnum(st[3]);
1017 maxarg = sp - arglast[0];
1019 warn("Too many args on read");
1021 maxarg = (int)str_gnum(st[4]);
1024 if (!stab_io(stab) || !stab_io(stab)->ifp)
1027 if (optype == O_RECV) {
1028 argtype = sizeof buf;
1029 anum = recvfrom(fileno(stab_io(stab)->ifp), tmps, anum, maxarg,
1032 st[2]->str_cur = anum;
1033 st[2]->str_ptr[anum] = '\0';
1034 str_nset(str,buf,argtype);
1037 str_sset(str,&str_undef);
1041 if (optype == O_RECV)
1044 STR_GROW(st[2], anum+maxarg+1), (tmps = str_get(st[2])); /* sneaky */
1046 if (stab_io(stab)->type == 's') {
1047 argtype = sizeof buf;
1048 anum = recvfrom(fileno(stab_io(stab)->ifp), tmps+maxarg, anum, 0,
1053 if (optype == O_SYSREAD) {
1054 anum = read(fileno(stab_io(stab)->ifp), tmps+maxarg, anum);
1057 anum = fread(tmps+maxarg, 1, anum, stab_io(stab)->ifp);
1060 st[2]->str_cur = anum+maxarg;
1061 st[2]->str_ptr[anum+maxarg] = '\0';
1062 value = (double)anum;
1066 if ((arg[1].arg_type & A_MASK) == A_WORD)
1067 stab = arg[1].arg_ptr.arg_stab;
1069 stab = stabent(str_get(st[1]),TRUE);
1070 tmps = str_get(st[2]);
1071 anum = (int)str_gnum(st[3]);
1073 stio = stab_io(stab);
1074 maxarg = sp - arglast[0];
1075 if (!stio || !stio->ifp) {
1078 if (optype == O_SYSWRITE)
1079 warn("Syswrite on closed filehandle");
1081 warn("Send on closed socket");
1084 else if (optype == O_SYSWRITE) {
1086 warn("Too many args on syswrite");
1088 optype = (int)str_gnum(st[4]);
1091 anum = write(fileno(stab_io(stab)->ifp), tmps+optype, anum);
1094 else if (maxarg >= 4) {
1096 warn("Too many args on send");
1097 tmps2 = str_get(st[4]);
1098 anum = sendto(fileno(stab_io(stab)->ifp), tmps, st[2]->str_cur,
1099 anum, tmps2, st[4]->str_cur);
1102 anum = send(fileno(stab_io(stab)->ifp), tmps, st[2]->str_cur, anum);
1109 value = (double)anum;
1112 if ((arg[1].arg_type & A_MASK) == A_WORD)
1113 stab = arg[1].arg_ptr.arg_stab;
1115 stab = stabent(str_get(st[1]),TRUE);
1116 value = str_gnum(st[2]);
1117 str_set(str, do_seek(stab,
1118 (long)value, (int)str_gnum(st[3]) ) ? Yes : No);
1122 tmps = "_SUB_"; /* just fake up a "last _SUB_" */
1124 if (curcsv && curcsv->wantarray == G_ARRAY) {
1125 lastretstr = Nullstr;
1126 lastspbase = arglast[1];
1127 lastsize = arglast[2] - arglast[1];
1130 lastretstr = str_static(st[arglast[2] - arglast[0]]);
1136 tmps = str_get(arg[1].arg_ptr.arg_str);
1138 while (loop_ptr >= 0 && (!loop_stack[loop_ptr].loop_label ||
1139 strNE(tmps,loop_stack[loop_ptr].loop_label) )) {
1142 deb("(Skipping label #%d %s)\n",loop_ptr,
1143 loop_stack[loop_ptr].loop_label);
1150 deb("(Found label #%d %s)\n",loop_ptr,
1151 loop_stack[loop_ptr].loop_label);
1156 if (tmps && strEQ(tmps, "_SUB_"))
1157 fatal("Can't return outside a subroutine");
1158 fatal("Bad label: %s", maxarg > 0 ? tmps : "<null>");
1160 if (!lastretstr && optype == O_LAST && lastsize) {
1162 st += lastspbase + 1;
1163 optype = loop_stack[loop_ptr].loop_sp - lastspbase; /* negative */
1165 for (anum = lastsize; anum > 0; anum--,st++)
1166 st[optype] = str_static(st[0]);
1168 longjmp(loop_stack[loop_ptr].loop_env, O_LAST);
1170 longjmp(loop_stack[loop_ptr].loop_env, optype);
1172 case O_GOTO:/* shudder */
1173 goto_targ = str_get(arg[1].arg_ptr.arg_str);
1175 goto_targ = Nullch; /* just restart from top */
1176 if (optype == O_DUMP) {
1180 longjmp(top_env, 1);
1182 tmps = str_get(st[1]);
1186 anum = (int) str_gnum(st[3]) - arybase;
1189 else if (anum > st[1]->str_cur)
1190 anum = st[1]->str_cur;
1193 if (!(tmps2 = fbminstr((unsigned char*)tmps + anum,
1194 (unsigned char*)tmps + st[1]->str_cur, st[2])))
1196 if (tmps2 = fbminstr(Null(unsigned char*),Null(unsigned char*),Nullstr))
1198 value = (double)(-1 + arybase);
1200 value = (double)(tmps2 - tmps + arybase);
1203 tmps = str_get(st[1]);
1204 tmps2 = str_get(st[2]);
1206 anum = st[1]->str_cur;
1208 anum = (int) str_gnum(st[3]) - arybase + st[2]->str_cur;
1211 else if (anum > st[1]->str_cur)
1212 anum = st[1]->str_cur;
1215 if (!(tmps2 = rninstr(tmps, tmps + anum,
1216 tmps2, tmps2 + st[2]->str_cur)))
1218 if (tmps2 = rninstr(Nullch,Nullch,Nullch,Nullch))
1220 value = (double)(-1 + arybase);
1222 value = (double)(tmps2 - tmps + arybase);
1226 value = (double) time(Null(long*));
1230 sp = do_tms(str,gimme,arglast);
1236 when = (long)str_gnum(st[1]);
1237 sp = do_time(str,localtime(&when),
1244 when = (long)str_gnum(st[1]);
1245 sp = do_time(str,gmtime(&when),
1249 sp = do_truncate(str,arg,
1254 sp = do_stat(str,arg,
1259 tmps = str_get(st[1]);
1261 str_set(str,fcrypt(tmps,str_get(st[2])));
1263 str_set(str,crypt(tmps,str_get(st[2])));
1267 "The crypt() function is unimplemented due to excessive paranoia.");
1271 value = str_gnum(st[1]);
1272 value = atan2(value,str_gnum(st[2]));
1276 value = str_gnum(stab_val(defstab));
1278 value = str_gnum(st[1]);
1283 value = str_gnum(stab_val(defstab));
1285 value = str_gnum(st[1]);
1292 value = str_gnum(st[1]);
1296 value = rand() * value / 2147483648.0;
1299 value = rand() * value / 65536.0;
1302 value = rand() * value / 32768.0;
1304 value = rand() * value / (double)(((unsigned long)1) << RANDBITS);
1315 anum = (int)str_gnum(st[1]);
1320 value = str_gnum(stab_val(defstab));
1322 value = str_gnum(st[1]);
1327 value = str_gnum(stab_val(defstab));
1329 value = str_gnum(st[1]);
1334 value = str_gnum(stab_val(defstab));
1336 value = str_gnum(st[1]);
1337 value = sqrt(value);
1341 value = str_gnum(stab_val(defstab));
1343 value = str_gnum(st[1]);
1345 (void)modf(value,&value);
1347 (void)modf(-value,&value);
1353 tmps = str_get(stab_val(defstab));
1355 tmps = str_get(st[1]);
1357 value = (double) (*tmps & 255);
1360 value = (double) (anum & 255);
1365 tmps = str_get(stab_val(defstab));
1367 tmps = str_get(st[1]);
1370 anum = alarm((unsigned int)atoi(tmps));
1373 value = (double)anum;
1379 tmps = str_get(st[1]);
1381 if (!tmps || !*tmps)
1382 sleep((32767<<16)+32767);
1384 sleep((unsigned int)atoi(tmps));
1386 value = (double)when;
1388 value = ((double)when) - value;
1392 sp = do_range(gimme,arglast);
1395 if (gimme == G_ARRAY) { /* it's a range */
1396 /* can we optimize to constant array? */
1397 if ((arg[1].arg_type & A_MASK) == A_SINGLE &&
1398 (arg[2].arg_type & A_MASK) == A_SINGLE) {
1399 st[2] = arg[2].arg_ptr.arg_str;
1400 sp = do_range(gimme,arglast);
1401 st = stack->ary_array;
1402 maxarg = sp - arglast[0];
1403 str_free(arg[1].arg_ptr.arg_str);
1404 str_free(arg[2].arg_ptr.arg_str);
1405 arg->arg_type = O_ARRAY;
1406 arg[1].arg_type = A_STAB|A_DONT;
1408 stab = arg[1].arg_ptr.arg_stab = aadd(genstab());
1409 ary = stab_array(stab);
1410 afill(ary,maxarg - 1);
1412 while (maxarg-- > 0)
1413 ary->ary_array[maxarg] = str_smake(st[maxarg]);
1416 arg->arg_type = optype = O_RANGE;
1417 maxarg = arg->arg_len = 2;
1419 arg[anum].arg_flags &= ~AF_ARYOK;
1420 argflags = arg[anum].arg_flags;
1421 argtype = arg[anum].arg_type & A_MASK;
1422 arg[anum].arg_type = argtype;
1423 argptr = arg[anum].arg_ptr;
1429 arg->arg_type = O_FLIP;
1432 if ((arg[1].arg_type & A_MASK) == A_SINGLE ?
1433 last_in_stab && (int)str_gnum(st[1]) == stab_io(last_in_stab)->lines
1436 str_numset(str,0.0);
1438 arg->arg_type = optype = O_FLOP;
1439 arg[2].arg_type &= ~A_DONT;
1440 arg[1].arg_type |= A_DONT;
1441 argflags = arg[2].arg_flags;
1442 argtype = arg[2].arg_type & A_MASK;
1443 argptr = arg[2].arg_ptr;
1452 if ((arg[2].arg_type & A_MASK) == A_SINGLE ?
1453 last_in_stab && (int)str_gnum(st[2]) == stab_io(last_in_stab)->lines
1456 arg->arg_type = O_FLIP;
1457 arg[1].arg_type &= ~A_DONT;
1458 arg[2].arg_type |= A_DONT;
1466 if (tmpstab = stabent("$",allstabs))
1467 str_numset(STAB_STR(tmpstab),(double)getpid());
1468 hclear(pidstatus); /* no kids, so don't wait for 'em */
1470 value = (double)anum;
1473 fatal("Unsupported function fork");
1479 anum = wait(&argflags);
1481 pidgone(anum,argflags);
1482 value = (double)anum;
1484 statusvalue = (unsigned short)argflags;
1487 fatal("Unsupported function wait");
1493 anum = (int)str_gnum(st[1]);
1494 optype = (int)str_gnum(st[2]);
1495 anum = wait4pid(anum, &argflags,optype);
1496 value = (double)anum;
1498 statusvalue = (unsigned short)argflags;
1501 fatal("Unsupported function wait");
1507 if (arglast[2] - arglast[1] == 1) {
1509 tainted |= st[2]->str_tainted;
1510 taintproper("Insecure dependency in system");
1513 while ((anum = vfork()) == -1) {
1514 if (errno != EAGAIN) {
1522 ihand = signal(SIGINT, SIG_IGN);
1523 qhand = signal(SIGQUIT, SIG_IGN);
1524 argtype = wait4pid(anum, &argflags, 0);
1528 (void)signal(SIGINT, ihand);
1529 (void)signal(SIGQUIT, qhand);
1530 statusvalue = (unsigned short)argflags;
1534 value = (double)((unsigned int)argflags & 0xffff);
1536 do_execfree(); /* free any memory child malloced on vfork */
1539 if ((arg[1].arg_type & A_MASK) == A_STAB)
1540 value = (double)do_aexec(st[1],arglast);
1541 else if (arglast[2] - arglast[1] != 1)
1542 value = (double)do_aexec(Nullstr,arglast);
1544 value = (double)do_exec(str_get(str_static(st[2])));
1548 if ((arg[1].arg_type & A_MASK) == A_STAB)
1549 value = (double)do_aspawn(st[1],arglast);
1550 else if (arglast[2] - arglast[1] != 1)
1551 value = (double)do_aspawn(Nullstr,arglast);
1553 value = (double)do_spawn(str_get(str_static(st[2])));
1558 if ((arg[1].arg_type & A_MASK) == A_STAB)
1559 value = (double)do_aexec(st[1],arglast);
1560 else if (arglast[2] - arglast[1] != 1)
1561 value = (double)do_aexec(Nullstr,arglast);
1563 value = (double)do_exec(str_get(str_static(st[2])));
1576 tmps = str_get(stab_val(defstab));
1578 tmps = str_get(st[1]);
1587 case '0': case '1': case '2': case '3': case '4':
1588 case '5': case '6': case '7':
1589 tmplong <<= argtype;
1590 tmplong += *tmps++ & 15;
1592 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
1593 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
1597 tmplong += (*tmps++ & 7) + 9;
1606 value = (double)tmplong;
1610 value = (double)apply(optype,arglast);
1613 fatal("Unsupported function chown");
1618 value = (double)apply(optype,arglast);
1621 fatal("Unsupported function kill");
1627 value = (double)apply(optype,arglast);
1636 anum = umask((int)str_gnum(st[1]));
1637 value = (double)anum;
1639 taintproper("Insecure dependency in umask");
1643 fatal("Unsupported function umask");
1650 if ((anum = do_ipcget(optype, arglast)) == -1)
1652 value = (double)anum;
1657 anum = do_ipcctl(optype, arglast);
1661 value = (double)anum;
1664 str_set(str,"0 but true");
1668 value = (double)(do_msgsnd(arglast) >= 0);
1671 value = (double)(do_msgrcv(arglast) >= 0);
1674 value = (double)(do_semop(arglast) >= 0);
1678 value = (double)(do_shmio(optype, arglast) >= 0);
1680 #else /* not SYSVIPC */
1692 fatal("System V IPC is not implemented on this machine");
1693 #endif /* not SYSVIPC */
1695 tmps = str_get(st[1]);
1696 tmps2 = str_get(st[2]);
1698 taintproper("Insecure dependency in rename");
1701 value = (double)(rename(tmps,tmps2) >= 0);
1703 if (same_dirent(tmps2, tmps)) /* can always rename to same name */
1706 if (euid || stat(tmps2,&statbuf) < 0 ||
1707 (statbuf.st_mode & S_IFMT) != S_IFDIR )
1708 (void)UNLINK(tmps2);
1709 if (!(anum = link(tmps,tmps2)))
1710 anum = UNLINK(tmps);
1712 value = (double)(anum >= 0);
1717 tmps = str_get(st[1]);
1718 tmps2 = str_get(st[2]);
1720 taintproper("Insecure dependency in link");
1722 value = (double)(link(tmps,tmps2) >= 0);
1725 fatal("Unsupported function link");
1729 tmps = str_get(st[1]);
1730 anum = (int)str_gnum(st[2]);
1732 taintproper("Insecure dependency in mkdir");
1735 value = (double)(mkdir(tmps,anum) >= 0);
1738 (void)strcpy(buf,"mkdir ");
1740 #if !defined(MKDIR) || !defined(RMDIR)
1742 for (tmps2 = buf+6; *tmps; ) {
1746 (void)strcpy(tmps2," 2>&1");
1747 rsfp = mypopen(buf,"r");
1750 tmps2 = fgets(buf,sizeof buf,rsfp);
1751 (void)mypclose(rsfp);
1752 if (tmps2 != Nullch) {
1753 for (errno = 1; errno < sys_nerr; errno++) {
1754 if (instr(buf,sys_errlist[errno])) /* you don't see this */
1759 #define EACCES EPERM
1761 if (instr(buf,"cannot make"))
1763 else if (instr(buf,"existing file"))
1765 else if (instr(buf,"ile exists"))
1767 else if (instr(buf,"non-exist"))
1769 else if (instr(buf,"does not exist"))
1771 else if (instr(buf,"not empty"))
1773 else if (instr(buf,"cannot access"))
1779 else { /* some mkdirs return no failure indication */
1780 tmps = str_get(st[1]);
1781 anum = (stat(tmps,&statbuf) >= 0);
1782 if (optype == O_RMDIR)
1787 errno = EACCES; /* a guess */
1788 value = (double)anum;
1797 tmps = str_get(stab_val(defstab));
1799 tmps = str_get(st[1]);
1801 taintproper("Insecure dependency in rmdir");
1804 value = (double)(rmdir(tmps) >= 0);
1807 (void)strcpy(buf,"rmdir ");
1808 goto one_liner; /* see above in MKDIR */
1812 value = (double)getppid();
1815 fatal("Unsupported function getppid");
1823 anum = (int)str_gnum(st[1]);
1824 value = (double)getpgrp(anum);
1827 fatal("The getpgrp() function is unimplemented on this machine");
1832 argtype = (int)str_gnum(st[1]);
1833 anum = (int)str_gnum(st[2]);
1835 taintproper("Insecure dependency in setpgrp");
1837 value = (double)(setpgrp(argtype,anum) >= 0);
1840 fatal("The setpgrp() function is unimplemented on this machine");
1845 argtype = (int)str_gnum(st[1]);
1846 anum = (int)str_gnum(st[2]);
1847 value = (double)getpriority(argtype,anum);
1850 fatal("The getpriority() function is unimplemented on this machine");
1855 argtype = (int)str_gnum(st[1]);
1856 anum = (int)str_gnum(st[2]);
1857 optype = (int)str_gnum(st[3]);
1859 taintproper("Insecure dependency in setpriority");
1861 value = (double)(setpriority(argtype,anum,optype) >= 0);
1864 fatal("The setpriority() function is unimplemented on this machine");
1870 tmps = str_get(stab_val(defstab));
1872 tmps = str_get(st[1]);
1874 taintproper("Insecure dependency in chroot");
1876 value = (double)(chroot(tmps) >= 0);
1879 fatal("Unsupported function chroot");
1885 stab = last_in_stab;
1886 else if ((arg[1].arg_type & A_MASK) == A_WORD)
1887 stab = arg[1].arg_ptr.arg_stab;
1889 stab = stabent(str_get(st[1]),TRUE);
1890 argtype = U_I(str_gnum(st[2]));
1892 taintproper("Insecure dependency in ioctl");
1894 anum = do_ctl(optype,stab,argtype,st[3]);
1898 value = (double)anum;
1901 str_set(str,"0 but true");
1907 stab = last_in_stab;
1908 else if ((arg[1].arg_type & A_MASK) == A_WORD)
1909 stab = arg[1].arg_ptr.arg_stab;
1911 stab = stabent(str_get(st[1]),TRUE);
1912 if (stab && stab_io(stab))
1913 fp = stab_io(stab)->ifp;
1917 argtype = (int)str_gnum(st[2]);
1918 value = (double)(flock(fileno(fp),argtype) >= 0);
1924 fatal("The flock() function is unimplemented on this machine");
1928 ary = stab_array(arg[1].arg_ptr.arg_stab);
1929 if (arglast[2] - arglast[1] != 1)
1930 do_unshift(ary,arglast);
1932 STR *tmpstr = Str_new(52,0); /* must copy the STR */
1933 str_sset(tmpstr,st[2]);
1935 (void)astore(ary,0,tmpstr);
1937 value = (double)(ary->ary_fill + 1);
1944 tmpstr = stab_val(defstab);
1947 (arg[1].arg_type & A_MASK) != A_NULL ? st[1] : stab_val(defstab);
1949 tainted |= tmpstr->str_tainted;
1950 taintproper("Insecure dependency in eval");
1952 sp = do_eval(tmpstr, optype, curcmd->c_stash,
1980 if (mystat(arg,st[1]) < 0)
1982 if (cando(anum,argtype,&statcache))
1987 if (mystat(arg,st[1]) < 0)
1992 if (mystat(arg,st[1]) < 0)
1994 if (statcache.st_uid == (optype == O_FTEOWNED ? euid : uid) )
1998 if (mystat(arg,st[1]) < 0)
2000 if (!statcache.st_size)
2004 if (mystat(arg,st[1]) < 0)
2006 value = (double)statcache.st_size;
2010 if (mystat(arg,st[1]) < 0)
2012 value = (double)(basetime - statcache.st_mtime) / 86400.0;
2015 if (mystat(arg,st[1]) < 0)
2017 value = (double)(basetime - statcache.st_atime) / 86400.0;
2020 if (mystat(arg,st[1]) < 0)
2022 value = (double)(basetime - statcache.st_ctime) / 86400.0;
2028 goto check_file_type;
2034 goto check_file_type;
2038 goto check_file_type;
2044 goto check_file_type;
2048 if (mystat(arg,st[1]) < 0)
2050 if ((statcache.st_mode & S_IFMT) == anum )
2056 goto check_file_type;
2061 if (arg[1].arg_type & A_DONT)
2062 fatal("You must supply explicit filename with -l");
2064 if (lstat(str_get(st[1]),&statcache) < 0)
2066 if ((statcache.st_mode & S_IFMT) == S_IFLNK )
2072 tmps = str_get(st[1]);
2073 tmps2 = str_get(st[2]);
2075 taintproper("Insecure dependency in symlink");
2077 value = (double)(symlink(tmps,tmps2) >= 0);
2080 fatal("Unsupported function symlink");
2085 tmps = str_get(stab_val(defstab));
2087 tmps = str_get(st[1]);
2088 anum = readlink(tmps,buf,sizeof buf);
2091 str_nset(str,buf,anum);
2094 fatal("Unsupported function readlink");
2117 if (mystat(arg,st[1]) < 0)
2119 if (statcache.st_mode & anum)
2123 if (arg[1].arg_type & A_DONT) {
2124 stab = arg[1].arg_ptr.arg_stab;
2128 stab = stabent(tmps = str_get(st[1]),FALSE);
2129 if (stab && stab_io(stab) && stab_io(stab)->ifp)
2130 anum = fileno(stab_io(stab)->ifp);
2131 else if (isdigit(*tmps))
2140 str = do_fttext(arg,st[1]);
2144 if ((arg[1].arg_type & A_MASK) == A_WORD)
2145 stab = arg[1].arg_ptr.arg_stab;
2147 stab = stabent(str_get(st[1]),TRUE);
2149 value = (double)do_socket(stab,arglast);
2151 (void)do_socket(stab,arglast);
2155 if ((arg[1].arg_type & A_MASK) == A_WORD)
2156 stab = arg[1].arg_ptr.arg_stab;
2158 stab = stabent(str_get(st[1]),TRUE);
2160 value = (double)do_bind(stab,arglast);
2162 (void)do_bind(stab,arglast);
2166 if ((arg[1].arg_type & A_MASK) == A_WORD)
2167 stab = arg[1].arg_ptr.arg_stab;
2169 stab = stabent(str_get(st[1]),TRUE);
2171 value = (double)do_connect(stab,arglast);
2173 (void)do_connect(stab,arglast);
2177 if ((arg[1].arg_type & A_MASK) == A_WORD)
2178 stab = arg[1].arg_ptr.arg_stab;
2180 stab = stabent(str_get(st[1]),TRUE);
2182 value = (double)do_listen(stab,arglast);
2184 (void)do_listen(stab,arglast);
2188 if ((arg[1].arg_type & A_MASK) == A_WORD)
2189 stab = arg[1].arg_ptr.arg_stab;
2191 stab = stabent(str_get(st[1]),TRUE);
2192 if ((arg[2].arg_type & A_MASK) == A_WORD)
2193 stab2 = arg[2].arg_ptr.arg_stab;
2195 stab2 = stabent(str_get(st[2]),TRUE);
2196 do_accept(str,stab,stab2);
2204 sp = do_ghent(optype,
2212 sp = do_gnent(optype,
2220 sp = do_gpent(optype,
2228 sp = do_gsent(optype,
2232 value = (double) sethostent((int)str_gnum(st[1]));
2235 value = (double) setnetent((int)str_gnum(st[1]));
2238 value = (double) setprotoent((int)str_gnum(st[1]));
2241 value = (double) setservent((int)str_gnum(st[1]));
2244 value = (double) endhostent();
2247 value = (double) endnetent();
2250 value = (double) endprotoent();
2253 value = (double) endservent();
2256 if ((arg[1].arg_type & A_MASK) == A_WORD)
2257 stab = arg[1].arg_ptr.arg_stab;
2259 stab = stabent(str_get(st[1]),TRUE);
2260 if ((arg[2].arg_type & A_MASK) == A_WORD)
2261 stab2 = arg[2].arg_ptr.arg_stab;
2263 stab2 = stabent(str_get(st[2]),TRUE);
2265 value = (double)do_spair(stab,stab2,arglast);
2267 (void)do_spair(stab,stab2,arglast);
2271 if ((arg[1].arg_type & A_MASK) == A_WORD)
2272 stab = arg[1].arg_ptr.arg_stab;
2274 stab = stabent(str_get(st[1]),TRUE);
2276 value = (double)do_shutdown(stab,arglast);
2278 (void)do_shutdown(stab,arglast);
2283 if ((arg[1].arg_type & A_MASK) == A_WORD)
2284 stab = arg[1].arg_ptr.arg_stab;
2286 stab = stabent(str_get(st[1]),TRUE);
2287 sp = do_sopt(optype,stab,arglast);
2291 if ((arg[1].arg_type & A_MASK) == A_WORD)
2292 stab = arg[1].arg_ptr.arg_stab;
2294 stab = stabent(str_get(st[1]),TRUE);
2297 sp = do_getsockname(optype,stab,arglast);
2300 #else /* SOCKET not defined */
2333 fatal("Unsupported socket function");
2337 sp = do_select(gimme,arglast);
2340 fatal("select not implemented");
2345 if ((arg[1].arg_type & A_MASK) == A_WORD)
2346 stab = arg[1].arg_ptr.arg_stab;
2348 stab = stabent(str_get(st[1]),TRUE);
2349 if (!stab || !(stio = stab_io(stab)) || !(fp = stio->ifp))
2356 if ((arg[1].arg_type & A_MASK) == A_WORD)
2357 stab = arg[1].arg_ptr.arg_stab;
2359 stab = stabent(str_get(st[1]),TRUE);
2360 if (!stab || !(stio = stab_io(stab)) || !(fp = stio->ifp))
2363 str_set(str, (setmode(fileno(fp), O_BINARY) != -1) ? Yes : No);
2370 sp = do_vec(str == st[1], arg->arg_ptr.arg_str, arglast);
2376 sp = do_gpwent(optype,
2380 value = (double) setpwent();
2383 value = (double) endpwent();
2388 fatal("Unsupported password function");
2395 sp = do_ggrent(optype,
2399 value = (double) setgrent();
2402 value = (double) endgrent();
2407 fatal("Unsupported group function");
2412 if (!(tmps = getlogin()))
2416 fatal("Unsupported function getlogin");
2427 if ((arg[1].arg_type & A_MASK) == A_WORD)
2428 stab = arg[1].arg_ptr.arg_stab;
2430 stab = stabent(str_get(st[1]),TRUE);
2433 sp = do_dirop(optype,stab,gimme,arglast);
2436 value = (double)do_syscall(arglast);
2440 if ((arg[1].arg_type & A_MASK) == A_WORD)
2441 stab = arg[1].arg_ptr.arg_stab;
2443 stab = stabent(str_get(st[1]),TRUE);
2444 if ((arg[2].arg_type & A_MASK) == A_WORD)
2445 stab2 = arg[2].arg_ptr.arg_stab;
2447 stab2 = stabent(str_get(st[2]),TRUE);
2448 do_pipe(str,stab,stab2);
2451 fatal("Unsupported function pipe");
2462 deb("%s RETURNS \"%s\"\n",opname[optype],str_get(str));
2465 return arglast[0] + 1;
2472 anum = sp - arglast[0];
2475 deb("%s RETURNS ()\n",opname[optype]);
2478 deb("%s RETURNS (\"%s\")\n",opname[optype],str_get(st[1]));
2481 tmps = str_get(st[1]);
2482 deb("%s RETURNS %d ARGS (\"%s\",%s\"%s\")\n",opname[optype],
2483 anum,tmps,anum==2?"":"...,",str_get(st[anum]));
2508 str_numset(str,value);
2515 deb("%s RETURNS \"%f\"\n",opname[optype],value);
2518 return arglast[0] + 1;