3 * Copyright (c) 1991-1997, Larry Wall
5 * You may distribute under the terms of either the GNU General Public
6 * License or the Artistic License, as specified in the README file.
11 * "Sam sat on the ground and put his head in his hands. 'I wish I had never
12 * come here, and I don't want to see no more magic,' he said, and fell silent."
18 /* XXX If this causes problems, set i_unistd=undef in the hint file. */
23 #if defined(HAS_GETGROUPS) || defined(HAS_SETGROUPS)
30 * Use the "DESTRUCTOR" scope cleanup to reinstate magic.
37 typedef struct magic_state MGS;
39 static void restore_magic _((void *p));
46 assert(SvMAGICAL(sv));
49 mgs->mgs_flags = SvMAGICAL(sv) | SvREADONLY(sv);
50 SAVEDESTRUCTOR(restore_magic, mgs);
54 SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
64 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
67 SvFLAGS(sv) |= mgs->mgs_flags;
71 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
81 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
82 MGVTBL* vtbl = mg->mg_virtual;
84 if (vtbl->svt_get && !(mg->mg_flags & MGf_GSKIP))
88 if (!(SvFLAGS(sv) & (SVs_GMG|SVs_SMG)) || vtbl->svt_clear)
104 save_magic(&mgs, sv);
107 while ((mg = *mgp) != 0) {
108 MGVTBL* vtbl = mg->mg_virtual;
109 if (!(mg->mg_flags & MGf_GSKIP) && vtbl && vtbl->svt_get) {
110 (*vtbl->svt_get)(sv, mg);
111 /* Ignore this magic if it's been deleted */
112 if ((mg == (mgp_valid ? *mgp : SvMAGIC(sv))) &&
113 (mg->mg_flags & MGf_GSKIP))
116 /* Advance to next magic (complicated by possible deletion) */
117 if (mg == (mgp_valid ? *mgp : SvMAGIC(sv))) {
118 mgp = &mg->mg_moremagic;
122 mgp = &SvMAGIC(sv); /* Re-establish pointer after sv_upgrade */
138 save_magic(&mgs, sv);
140 for (mg = SvMAGIC(sv); mg; mg = nextmg) {
141 MGVTBL* vtbl = mg->mg_virtual;
142 nextmg = mg->mg_moremagic; /* it may delete itself */
143 if (mg->mg_flags & MGf_GSKIP) {
144 mg->mg_flags &= ~MGf_GSKIP; /* setting requires another read */
147 if (vtbl && vtbl->svt_set)
148 (*vtbl->svt_set)(sv, mg);
163 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
164 MGVTBL* vtbl = mg->mg_virtual;
165 if (vtbl && vtbl->svt_len) {
169 save_magic(&mgs, sv);
170 /* omit MGf_GSKIP -- not changed here */
171 len = (*vtbl->svt_len)(sv, mg);
177 junk = SvPV(sv, len);
189 save_magic(&mgs, sv);
191 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
192 MGVTBL* vtbl = mg->mg_virtual;
193 /* omit GSKIP -- never set here */
195 if (vtbl && vtbl->svt_clear)
196 (*vtbl->svt_clear)(sv, mg);
209 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
210 if (mg->mg_type == type)
217 mg_copy(sv, nsv, key, klen)
225 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
226 if (isUPPER(mg->mg_type)) {
227 sv_magic(nsv, mg->mg_obj, toLOWER(mg->mg_type), key, klen);
240 for (mg = SvMAGIC(sv); mg; mg = moremagic) {
241 MGVTBL* vtbl = mg->mg_virtual;
242 moremagic = mg->mg_moremagic;
243 if (vtbl && vtbl->svt_free)
244 (*vtbl->svt_free)(sv, mg);
245 if (mg->mg_ptr && mg->mg_type != 'g')
247 Safefree(mg->mg_ptr);
248 else if (mg->mg_len == HEf_SVKEY)
249 SvREFCNT_dec((SV*)mg->mg_ptr);
250 if (mg->mg_flags & MGf_REFCOUNTED)
251 SvREFCNT_dec(mg->mg_obj);
258 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
273 switch (*mg->mg_ptr) {
274 case '1': case '2': case '3': case '4':
275 case '5': case '6': case '7': case '8': case '9': case '&':
276 if (curpm && (rx = curpm->op_pmregexp)) {
277 paren = atoi(mg->mg_ptr);
279 if (paren <= rx->nparens &&
280 (s = rx->startp[paren]) &&
281 (t = rx->endp[paren]))
290 if (curpm && (rx = curpm->op_pmregexp)) {
291 paren = rx->lastparen;
297 if (curpm && (rx = curpm->op_pmregexp)) {
298 if ((s = rx->subbeg) && rx->startp[0]) {
299 i = rx->startp[0] - s;
306 if (curpm && (rx = curpm->op_pmregexp)) {
307 if (rx->subend && (s = rx->endp[0])) {
315 return (STRLEN)ofslen;
317 return (STRLEN)orslen;
320 if (!SvPOK(sv) && SvNIOK(sv))
338 switch (*mg->mg_ptr) {
339 case '\001': /* ^A */
340 sv_setsv(sv, bodytarget);
342 case '\004': /* ^D */
343 sv_setiv(sv, (IV)(debug & 32767));
345 case '\005': /* ^E */
348 # include <descrip.h>
349 # include <starlet.h>
351 $DESCRIPTOR(msgdsc,msg);
352 sv_setnv(sv,(double) vaxc$errno);
353 if (sys$getmsg(vaxc$errno,&msgdsc.dsc$w_length,&msgdsc,0,0) & 1)
354 sv_setpvn(sv,msgdsc.dsc$a_pointer,msgdsc.dsc$w_length);
360 sv_setnv(sv, (double)Perl_rc);
361 sv_setpv(sv, os2error(Perl_rc));
363 sv_setnv(sv, (double)errno);
364 sv_setpv(sv, errno ? Strerror(errno) : "");
367 SvNOK_on(sv); /* what a wonderful hack! */
369 case '\006': /* ^F */
370 sv_setiv(sv, (IV)maxsysfd);
372 case '\010': /* ^H */
373 sv_setiv(sv, (IV)hints);
377 sv_setpv(sv, inplace);
379 sv_setsv(sv, &sv_undef);
381 case '\017': /* ^O */
382 sv_setpv(sv, osname);
384 case '\020': /* ^P */
385 sv_setiv(sv, (IV)perldb);
387 case '\024': /* ^T */
389 sv_setnv(sv, basetime);
391 sv_setiv(sv, (IV)basetime);
394 case '\027': /* ^W */
395 sv_setiv(sv, (IV)dowarn);
397 case '1': case '2': case '3': case '4':
398 case '5': case '6': case '7': case '8': case '9': case '&':
399 if (curpm && (rx = curpm->op_pmregexp)) {
400 paren = atoi(GvENAME((GV*)mg->mg_obj));
402 if (paren <= rx->nparens &&
403 (s = rx->startp[paren]) &&
404 (t = rx->endp[paren]))
411 was_tainted = tainted;
416 tainted = was_tainted || rx->exec_tainted;
421 sv_setsv(sv,&sv_undef);
424 if (curpm && (rx = curpm->op_pmregexp)) {
425 paren = rx->lastparen;
429 sv_setsv(sv,&sv_undef);
432 if (curpm && (rx = curpm->op_pmregexp)) {
433 if ((s = rx->subbeg) && rx->startp[0]) {
434 i = rx->startp[0] - s;
438 sv_setsv(sv,&sv_undef);
441 if (curpm && (rx = curpm->op_pmregexp)) {
442 if (rx->subend && (s = rx->endp[0])) {
447 sv_setsv(sv,&sv_undef);
451 if (GvIO(last_in_gv)) {
452 sv_setiv(sv, (IV)IoLINES(GvIO(last_in_gv)));
457 sv_setiv(sv, (IV)STATUS_CURRENT);
458 #ifdef COMPLEX_STATUS
459 LvTARGOFF(sv) = statusvalue;
460 LvTARGLEN(sv) = statusvalue_vms;
464 s = IoTOP_NAME(GvIOp(defoutgv));
468 sv_setpv(sv,GvENAME(defoutgv));
473 s = IoFMT_NAME(GvIOp(defoutgv));
475 s = GvENAME(defoutgv);
480 sv_setiv(sv, (IV)IoPAGE_LEN(GvIOp(defoutgv)));
483 sv_setiv(sv, (IV)IoLINES_LEFT(GvIOp(defoutgv)));
486 sv_setiv(sv, (IV)IoPAGE(GvIOp(defoutgv)));
494 sv_setiv(sv, (IV)curcop->cop_arybase);
497 sv_setiv(sv, (IV)(IoFLAGS(GvIOp(defoutgv)) & IOf_FLUSH) != 0 );
500 sv_setpvn(sv,ofs,ofslen);
503 sv_setpvn(sv,ors,orslen);
510 sv_setnv(sv, (double)((errno == EVMSERR) ? vaxc$errno : errno));
511 sv_setpv(sv, errno ? Strerror(errno) : "");
514 int saveerrno = errno;
515 sv_setnv(sv, (double)errno);
517 if (errno == errno_isOS2) sv_setpv(sv, os2error(Perl_rc));
520 sv_setpv(sv, errno ? Strerror(errno) : "");
524 SvNOK_on(sv); /* what a wonderful hack! */
527 sv_setiv(sv, (IV)uid);
530 sv_setiv(sv, (IV)euid);
533 sv_setiv(sv, (IV)gid);
534 sv_setpvf(sv, "%Vd", (IV)gid);
537 sv_setiv(sv, (IV)egid);
538 sv_setpvf(sv, "%Vd", (IV)egid);
542 Groups_t gary[NGROUPS];
543 i = getgroups(NGROUPS,gary);
545 sv_catpvf(sv, " %Vd", (IV)gary[i]);
548 SvIOK_on(sv); /* what a wonderful hack! */
559 magic_getuvar(sv, mg)
563 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
565 if (uf && uf->uf_val)
566 (*uf->uf_val)(uf->uf_index, sv);
584 #ifdef DYNAMIC_ENV_FETCH
585 /* We just undefd an environment var. Is a replacement */
586 /* waiting in the wings? */
589 if ((valp = hv_fetch(GvHVn(envgv), ptr, klen, FALSE)))
590 s = SvPV(*valp, len);
594 #if !defined(OS2) && !defined(AMIGAOS) && !defined(_WIN32)
595 /* And you'll never guess what the dog had */
596 /* in its mouth... */
598 MgTAINTEDDIR_off(mg);
600 if (s && klen == 8 && strEQ(ptr, "DCL$PATH")) {
601 char pathbuf[256], eltbuf[256], *cp, *elt = s;
605 do { /* DCL$PATH may be a search list */
606 while (1) { /* as may dev portion of any element */
607 if ( ((cp = strchr(elt,'[')) || (cp = strchr(elt,'<'))) ) {
608 if ( *(cp+1) == '.' || *(cp+1) == '-' ||
609 cando_by_name(S_IWUSR,0,elt) ) {
614 if ((cp = strchr(elt, ':')) != Nullch)
616 if (my_trnlnm(elt, eltbuf, j++))
622 } while (my_trnlnm(s, pathbuf, i++) && (elt = pathbuf));
625 if (s && klen == 4 && strEQ(ptr,"PATH")) {
626 char *strend = s + len;
630 s = delimcpy(tokenbuf, tokenbuf + sizeof tokenbuf,
633 if (i >= sizeof tokenbuf /* too long -- assume the worst */
635 || (Stat(tokenbuf, &st) == 0 && (st.st_mode & 2)) ) {
642 #endif /* neither OS2 nor AMIGAOS nor _WIN32 */
648 magic_clearenv(sv,mg)
652 my_setenv(MgPV(mg,na),Nullch);
662 /* Are we fetching a signal entry? */
663 i = whichsig(MgPV(mg,na));
666 sv_setsv(sv,psig_ptr[i]);
668 Sighandler_t sigstate = rsignal_state(i);
670 /* cache state so we don't fetch it again */
671 if(sigstate == SIG_IGN)
672 sv_setpv(sv,"IGNORE");
674 sv_setsv(sv,&sv_undef);
675 psig_ptr[i] = SvREFCNT_inc(sv);
682 magic_clearsig(sv,mg)
687 /* Are we clearing a signal entry? */
688 i = whichsig(MgPV(mg,na));
691 SvREFCNT_dec(psig_ptr[i]);
695 SvREFCNT_dec(psig_name[i]);
713 if (strEQ(s,"__DIE__"))
715 else if (strEQ(s,"__WARN__"))
717 else if (strEQ(s,"__PARSE__"))
720 croak("No such hook: %s", s);
728 i = whichsig(s); /* ...no, a brick */
730 if (dowarn || strEQ(s,"ALARM"))
731 warn("No such signal: SIG%s", s);
734 SvREFCNT_dec(psig_name[i]);
735 SvREFCNT_dec(psig_ptr[i]);
736 psig_ptr[i] = SvREFCNT_inc(sv);
737 SvTEMP_off(sv); /* Make sure it doesn't go away on us */
738 psig_name[i] = newSVpv(s, strlen(s));
739 SvREADONLY_on(psig_name[i]);
741 if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) {
743 (void)rsignal(i, sighandler);
745 *svp = SvREFCNT_inc(sv);
748 s = SvPV_force(sv,na);
749 if (strEQ(s,"IGNORE")) {
751 (void)rsignal(i, SIG_IGN);
755 else if (strEQ(s,"DEFAULT") || !*s) {
757 (void)rsignal(i, SIG_DFL);
763 * We should warn if HINT_STRICT_REFS, but without
764 * access to a known hint bit in a known OP, we can't
765 * tell whether HINT_STRICT_REFS is in force or not.
767 if (!strchr(s,':') && !strchr(s,'\''))
768 sv_setpv(sv, form("main::%s", s));
770 (void)rsignal(i, sighandler);
772 *svp = SvREFCNT_inc(sv);
789 magic_setamagic(sv,mg)
793 /* HV_badAMAGIC_on(Sv_STASH(sv)); */
798 #endif /* OVERLOAD */
801 magic_setnkeys(sv,mg)
806 hv_ksplit((HV*)LvTARG(sv), SvIV(sv));
807 LvTARG(sv) = Nullsv; /* Don't allow a ref to reassign this. */
813 magic_methpack(sv,mg,meth)
827 PUSHs(sv_2mortal(newSVpv(mg->mg_ptr, mg->mg_len)));
828 else if (mg->mg_len == HEf_SVKEY)
829 PUSHs((SV*)mg->mg_ptr);
831 else if (mg->mg_type == 'p')
832 PUSHs(sv_2mortal(newSViv(mg->mg_len)));
835 if (perl_call_method(meth, G_SCALAR))
836 sv_setsv(sv, *stack_sp--);
848 magic_methpack(sv,mg,"FETCH");
850 mg->mg_flags |= MGf_GSKIP;
866 PUSHs(sv_2mortal(newSVpv(mg->mg_ptr, mg->mg_len)));
867 else if (mg->mg_len == HEf_SVKEY)
868 PUSHs((SV*)mg->mg_ptr);
870 else if (mg->mg_type == 'p')
871 PUSHs(sv_2mortal(newSViv(mg->mg_len)));
875 perl_call_method("STORE", G_SCALAR|G_DISCARD);
881 magic_clearpack(sv,mg)
885 return magic_methpack(sv,mg,"DELETE");
888 int magic_wipepack(sv,mg)
898 perl_call_method("CLEAR", G_SCALAR|G_DISCARD);
904 magic_nextpack(sv,mg,key)
910 char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY";
921 if (perl_call_method(meth, G_SCALAR))
922 sv_setsv(key, *stack_sp--);
930 magic_existspack(sv,mg)
934 return magic_methpack(sv,mg,"EXISTS");
938 magic_setdbline(sv,mg)
949 svp = av_fetch(GvAV(gv),
950 atoi(MgPV(mg,na)), FALSE);
951 if (svp && SvIOKp(*svp) && (o = (OP*)SvSTASH(*svp)))
954 warn("Can't break at that line\n");
959 magic_getarylen(sv,mg)
963 sv_setiv(sv, AvFILL((AV*)mg->mg_obj) + curcop->cop_arybase);
968 magic_setarylen(sv,mg)
972 av_fill((AV*)mg->mg_obj, SvIV(sv) - curcop->cop_arybase);
981 SV* lsv = LvTARG(sv);
983 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv)) {
984 mg = mg_find(lsv, 'g');
985 if (mg && mg->mg_len >= 0) {
986 sv_setiv(sv, mg->mg_len + curcop->cop_arybase);
999 SV* lsv = LvTARG(sv);
1005 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv))
1006 mg = mg_find(lsv, 'g');
1010 sv_magic(lsv, (SV*)0, 'g', Nullch, 0);
1011 mg = mg_find(lsv, 'g');
1013 else if (!SvOK(sv)) {
1017 len = SvPOK(lsv) ? SvCUR(lsv) : sv_len(lsv);
1019 pos = SvIV(sv) - curcop->cop_arybase;
1028 mg->mg_flags &= ~MGf_MINMATCH;
1034 magic_getglob(sv,mg)
1038 if (SvFAKE(sv)) { /* FAKE globs can get coerced */
1040 gv_efullname3(sv,((GV*)sv), "*");
1044 gv_efullname3(sv,((GV*)sv), "*"); /* a gv value, be nice */
1049 magic_setglob(sv,mg)
1059 if (*s == '*' && s[1])
1061 gv = gv_fetchpv(s,TRUE, SVt_PVGV);
1066 GvGP(sv) = gp_ref(GvGP(gv));
1071 magic_setsubstr(sv,mg)
1076 char *tmps = SvPV(sv,len);
1077 sv_insert(LvTARG(sv),LvTARGOFF(sv),LvTARGLEN(sv), tmps, len);
1082 magic_gettaint(sv,mg)
1086 TAINT_IF((mg->mg_len & 1) ||
1087 (mg->mg_len & 2) && mg->mg_obj == sv); /* kludge */
1092 magic_settaint(sv,mg)
1097 if (localizing == 1)
1114 do_vecset(sv); /* XXX slurp this routine */
1119 magic_getdefelem(sv,mg)
1124 if (LvTARGLEN(sv)) {
1126 HV* hv = (HV*)LvTARG(sv);
1127 HE* he = hv_fetch_ent(hv, mg->mg_obj, FALSE, 0);
1132 AV* av = (AV*)LvTARG(sv);
1133 if ((I32)LvTARGOFF(sv) <= AvFILL(av))
1134 targ = AvARRAY(av)[LvTARGOFF(sv)];
1136 if (targ && targ != &sv_undef) {
1137 /* somebody else defined it for us */
1138 SvREFCNT_dec(LvTARG(sv));
1139 LvTARG(sv) = SvREFCNT_inc(targ);
1141 SvREFCNT_dec(mg->mg_obj);
1142 mg->mg_obj = Nullsv;
1143 mg->mg_flags &= ~MGf_REFCOUNTED;
1148 sv_setsv(sv, targ ? targ : &sv_undef);
1153 magic_setdefelem(sv,mg)
1160 sv_setsv(LvTARG(sv), sv);
1161 SvSETMAGIC(LvTARG(sv));
1167 magic_freedefelem(sv,mg)
1171 SvREFCNT_dec(LvTARG(sv));
1182 if (!LvTARGLEN(sv) || !(mg = mg_find(sv, 'y')))
1185 HV* hv = (HV*)LvTARG(sv);
1186 HE* he = hv_fetch_ent(hv, mg->mg_obj, TRUE, 0);
1187 if (!he || (value = HeVAL(he)) == &sv_undef)
1188 croak(no_helem, SvPV(mg->mg_obj, na));
1191 AV* av = (AV*)LvTARG(sv);
1192 if ((I32)LvTARGLEN(sv) < 0 && (I32)LvTARGOFF(sv) > AvFILL(av))
1193 LvTARG(sv) = Nullsv; /* array can't be extended */
1195 SV** svp = av_fetch(av, LvTARGOFF(sv), TRUE);
1196 if (!svp || (value = *svp) == &sv_undef)
1197 croak(no_aelem, (I32)LvTARGOFF(sv));
1200 SvREFCNT_inc(value);
1201 SvREFCNT_dec(LvTARG(sv));
1204 SvREFCNT_dec(mg->mg_obj);
1205 mg->mg_obj = Nullsv;
1206 mg->mg_flags &= ~MGf_REFCOUNTED;
1210 magic_setmglob(sv,mg)
1224 sv_unmagic(sv, 'B');
1234 sv_unmagic(sv, 'f');
1240 magic_setuvar(sv,mg)
1244 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
1246 if (uf && uf->uf_set)
1247 (*uf->uf_set)(uf->uf_index, sv);
1251 #ifdef USE_LOCALE_COLLATE
1253 magic_setcollxfrm(sv,mg)
1258 * René Descartes said "I think not."
1259 * and vanished with a faint plop.
1262 Safefree(mg->mg_ptr);
1268 #endif /* USE_LOCALE_COLLATE */
1278 switch (*mg->mg_ptr) {
1279 case '\001': /* ^A */
1280 sv_setsv(bodytarget, sv);
1282 case '\004': /* ^D */
1283 debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | 0x80000000;
1284 DEBUG_x(dump_all());
1286 case '\005': /* ^E */
1288 set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1290 /* will anyone ever use this? */
1291 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4);
1294 case '\006': /* ^F */
1295 maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1297 case '\010': /* ^H */
1298 hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1304 inplace = savepv(SvPV(sv,na));
1308 case '\017': /* ^O */
1312 osname = savepv(SvPV(sv,na));
1316 case '\020': /* ^P */
1317 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1326 case '\024': /* ^T */
1328 basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv));
1330 basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1333 case '\027': /* ^W */
1334 dowarn = (bool)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1338 if (localizing == 1)
1339 save_sptr((SV**)&last_in_gv);
1341 else if (SvOK(sv) && GvIO(last_in_gv))
1342 IoLINES(GvIOp(last_in_gv)) = (long)SvIV(sv);
1345 Safefree(IoTOP_NAME(GvIOp(defoutgv)));
1346 IoTOP_NAME(GvIOp(defoutgv)) = s = savepv(SvPV(sv,na));
1347 IoTOP_GV(GvIOp(defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1350 Safefree(IoFMT_NAME(GvIOp(defoutgv)));
1351 IoFMT_NAME(GvIOp(defoutgv)) = s = savepv(SvPV(sv,na));
1352 IoFMT_GV(GvIOp(defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1355 IoPAGE_LEN(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1358 IoLINES_LEFT(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1359 if (IoLINES_LEFT(GvIOp(defoutgv)) < 0L)
1360 IoLINES_LEFT(GvIOp(defoutgv)) = 0L;
1363 IoPAGE(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1367 IO *io = GvIOp(defoutgv);
1368 if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0)
1369 IoFLAGS(io) &= ~IOf_FLUSH;
1371 if (!(IoFLAGS(io) & IOf_FLUSH)) {
1372 PerlIO *ofp = IoOFP(io);
1374 (void)PerlIO_flush(ofp);
1375 IoFLAGS(io) |= IOf_FLUSH;
1381 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1382 multiline = (i != 0);
1388 rs = SvREFCNT_inc(nrs);
1393 if (SvOK(sv) || SvGMAGICAL(sv))
1394 ors = savepv(SvPV(sv,orslen));
1403 ofs = savepv(SvPV(sv, ofslen));
1408 ofmt = savepv(SvPV(sv,na));
1411 compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1414 #ifdef COMPLEX_STATUS
1415 if (localizing == 2) {
1416 statusvalue = LvTARGOFF(sv);
1417 statusvalue_vms = LvTARGLEN(sv);
1421 #ifdef VMSISH_STATUS
1423 STATUS_NATIVE_SET((U32)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)));
1426 STATUS_POSIX_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1429 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv),
1430 (SvIV(sv) == EVMSERR) ? 4 : vaxc$errno);
1433 uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1435 delaymagic |= DM_RUID;
1436 break; /* don't do magic till later */
1439 (void)setruid((Uid_t)uid);
1442 (void)setreuid((Uid_t)uid, (Uid_t)-1);
1444 #ifdef HAS_SETRESUID
1445 (void)setresuid((Uid_t)uid, (Uid_t)-1, (Uid_t)-1);
1447 if (uid == euid) /* special case $< = $> */
1450 uid = (I32)getuid();
1451 croak("setruid() not implemented");
1456 uid = (I32)getuid();
1457 tainting |= (uid && (euid != uid || egid != gid));
1460 euid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1462 delaymagic |= DM_EUID;
1463 break; /* don't do magic till later */
1466 (void)seteuid((Uid_t)euid);
1469 (void)setreuid((Uid_t)-1, (Uid_t)euid);
1471 #ifdef HAS_SETRESUID
1472 (void)setresuid((Uid_t)-1, (Uid_t)euid, (Uid_t)-1);
1474 if (euid == uid) /* special case $> = $< */
1477 euid = (I32)geteuid();
1478 croak("seteuid() not implemented");
1483 euid = (I32)geteuid();
1484 tainting |= (uid && (euid != uid || egid != gid));
1487 gid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1489 delaymagic |= DM_RGID;
1490 break; /* don't do magic till later */
1493 (void)setrgid((Gid_t)gid);
1496 (void)setregid((Gid_t)gid, (Gid_t)-1);
1498 #ifdef HAS_SETRESGID
1499 (void)setresgid((Gid_t)gid, (Gid_t)-1, (Gid_t) 1);
1501 if (gid == egid) /* special case $( = $) */
1504 gid = (I32)getgid();
1505 croak("setrgid() not implemented");
1510 gid = (I32)getgid();
1511 tainting |= (uid && (euid != uid || egid != gid));
1514 #ifdef HAS_SETGROUPS
1516 char *p = SvPV(sv, na);
1517 Groups_t gary[NGROUPS];
1519 SET_NUMERIC_STANDARD();
1522 egid = I_V(atof(p));
1523 for (i = 0; i < NGROUPS; ++i) {
1524 while (*p && !isSPACE(*p))
1530 gary[i] = I_V(atof(p));
1533 (void)setgroups(i, gary);
1535 #else /* HAS_SETGROUPS */
1536 egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1537 #endif /* HAS_SETGROUPS */
1539 delaymagic |= DM_EGID;
1540 break; /* don't do magic till later */
1543 (void)setegid((Gid_t)egid);
1546 (void)setregid((Gid_t)-1, (Gid_t)egid);
1548 #ifdef HAS_SETRESGID
1549 (void)setresgid((Gid_t)-1, (Gid_t)egid, (Gid_t)-1);
1551 if (egid == gid) /* special case $) = $( */
1554 egid = (I32)getegid();
1555 croak("setegid() not implemented");
1560 egid = (I32)getegid();
1561 tainting |= (uid && (euid != uid || egid != gid));
1564 chopset = SvPV_force(sv,na);
1570 /* See if all the arguments are contiguous in memory */
1571 for (i = 1; i < origargc; i++) {
1572 if (origargv[i] == s + 1)
1573 s += strlen(++s); /* this one is ok too */
1575 /* can grab env area too? */
1576 if (origenviron && origenviron[0] == s + 1) {
1577 my_setenv("NoNeSuCh", Nullch);
1578 /* force copy of environment */
1579 for (i = 0; origenviron[i]; i++)
1580 if (origenviron[i] == s + 1)
1583 origalen = s - origargv[0];
1585 s = SvPV_force(sv,len);
1587 if (i >= origalen) {
1591 Copy(s, origargv[0], i, char);
1594 Copy(s, origargv[0], i, char);
1597 while (++i < origalen)
1600 for (i = 1; i < origargc; i++)
1601 origargv[i] = Nullch;
1612 register char **sigv;
1614 for (sigv = sig_name+1; *sigv; sigv++)
1615 if (strEQ(sig,*sigv))
1616 return sig_num[sigv - sig_name];
1618 if (strEQ(sig,"CHLD"))
1622 if (strEQ(sig,"CLD"))
1640 die("Signal SIG%s received, but no signal handler set.\n",
1643 cv = sv_2cv(psig_ptr[sig],&st,&gv,TRUE);
1644 if (!cv || !CvROOT(cv)) {
1646 warn("SIG%s handler \"%s\" not defined.\n",
1647 sig_name[sig], GvENAME(gv) );
1651 oldstack = curstack;
1652 if (curstack != signalstack)
1653 AvFILL(signalstack) = 0;
1654 SWITCHSTACK(curstack, signalstack);
1657 sv = SvREFCNT_inc(psig_name[sig]);
1659 sv = sv_newmortal();
1660 sv_setpv(sv,sig_name[sig]);
1666 perl_call_sv((SV*)cv, G_DISCARD);
1668 SWITCHSTACK(signalstack, oldstack);