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);
657 magic_clear_all_env(sv,mg)
662 die("Can't make list assignment to %%ENV on this system");
665 char *envv = GetEnvironmentStrings();
669 char *end = strchr(cur,'=');
670 if (end && end != cur) {
672 my_setenv(cur,Nullch);
674 cur += strlen(end+1)+1;
676 else if ((len = strlen(cur)))
679 FreeEnvironmentStrings(envv);
683 if (environ == origenviron)
684 New(901, environ, 1, char*);
686 for (i = 0; environ[i]; i++)
687 Safefree(environ[i]);
701 /* Are we fetching a signal entry? */
702 i = whichsig(MgPV(mg,na));
705 sv_setsv(sv,psig_ptr[i]);
707 Sighandler_t sigstate = rsignal_state(i);
709 /* cache state so we don't fetch it again */
710 if(sigstate == SIG_IGN)
711 sv_setpv(sv,"IGNORE");
713 sv_setsv(sv,&sv_undef);
714 psig_ptr[i] = SvREFCNT_inc(sv);
721 magic_clearsig(sv,mg)
726 /* Are we clearing a signal entry? */
727 i = whichsig(MgPV(mg,na));
730 SvREFCNT_dec(psig_ptr[i]);
734 SvREFCNT_dec(psig_name[i]);
752 if (strEQ(s,"__DIE__"))
754 else if (strEQ(s,"__WARN__"))
756 else if (strEQ(s,"__PARSE__"))
759 croak("No such hook: %s", s);
767 i = whichsig(s); /* ...no, a brick */
769 if (dowarn || strEQ(s,"ALARM"))
770 warn("No such signal: SIG%s", s);
773 SvREFCNT_dec(psig_name[i]);
774 SvREFCNT_dec(psig_ptr[i]);
775 psig_ptr[i] = SvREFCNT_inc(sv);
776 SvTEMP_off(sv); /* Make sure it doesn't go away on us */
777 psig_name[i] = newSVpv(s, strlen(s));
778 SvREADONLY_on(psig_name[i]);
780 if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) {
782 (void)rsignal(i, sighandler);
784 *svp = SvREFCNT_inc(sv);
787 s = SvPV_force(sv,na);
788 if (strEQ(s,"IGNORE")) {
790 (void)rsignal(i, SIG_IGN);
794 else if (strEQ(s,"DEFAULT") || !*s) {
796 (void)rsignal(i, SIG_DFL);
802 * We should warn if HINT_STRICT_REFS, but without
803 * access to a known hint bit in a known OP, we can't
804 * tell whether HINT_STRICT_REFS is in force or not.
806 if (!strchr(s,':') && !strchr(s,'\''))
807 sv_setpv(sv, form("main::%s", s));
809 (void)rsignal(i, sighandler);
811 *svp = SvREFCNT_inc(sv);
828 magic_setamagic(sv,mg)
832 /* HV_badAMAGIC_on(Sv_STASH(sv)); */
837 #endif /* OVERLOAD */
840 magic_setnkeys(sv,mg)
845 hv_ksplit((HV*)LvTARG(sv), SvIV(sv));
846 LvTARG(sv) = Nullsv; /* Don't allow a ref to reassign this. */
852 magic_methpack(sv,mg,meth)
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)));
874 if (perl_call_method(meth, G_SCALAR))
875 sv_setsv(sv, *stack_sp--);
887 magic_methpack(sv,mg,"FETCH");
889 mg->mg_flags |= MGf_GSKIP;
905 PUSHs(sv_2mortal(newSVpv(mg->mg_ptr, mg->mg_len)));
906 else if (mg->mg_len == HEf_SVKEY)
907 PUSHs((SV*)mg->mg_ptr);
909 else if (mg->mg_type == 'p')
910 PUSHs(sv_2mortal(newSViv(mg->mg_len)));
914 perl_call_method("STORE", G_SCALAR|G_DISCARD);
920 magic_clearpack(sv,mg)
924 return magic_methpack(sv,mg,"DELETE");
927 int magic_wipepack(sv,mg)
937 perl_call_method("CLEAR", G_SCALAR|G_DISCARD);
943 magic_nextpack(sv,mg,key)
949 char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY";
960 if (perl_call_method(meth, G_SCALAR))
961 sv_setsv(key, *stack_sp--);
969 magic_existspack(sv,mg)
973 return magic_methpack(sv,mg,"EXISTS");
977 magic_setdbline(sv,mg)
988 svp = av_fetch(GvAV(gv),
989 atoi(MgPV(mg,na)), FALSE);
990 if (svp && SvIOKp(*svp) && (o = (OP*)SvSTASH(*svp)))
993 warn("Can't break at that line\n");
998 magic_getarylen(sv,mg)
1002 sv_setiv(sv, AvFILL((AV*)mg->mg_obj) + curcop->cop_arybase);
1007 magic_setarylen(sv,mg)
1011 av_fill((AV*)mg->mg_obj, SvIV(sv) - curcop->cop_arybase);
1020 SV* lsv = LvTARG(sv);
1022 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv)) {
1023 mg = mg_find(lsv, 'g');
1024 if (mg && mg->mg_len >= 0) {
1025 sv_setiv(sv, mg->mg_len + curcop->cop_arybase);
1038 SV* lsv = LvTARG(sv);
1044 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv))
1045 mg = mg_find(lsv, 'g');
1049 sv_magic(lsv, (SV*)0, 'g', Nullch, 0);
1050 mg = mg_find(lsv, 'g');
1052 else if (!SvOK(sv)) {
1056 len = SvPOK(lsv) ? SvCUR(lsv) : sv_len(lsv);
1058 pos = SvIV(sv) - curcop->cop_arybase;
1067 mg->mg_flags &= ~MGf_MINMATCH;
1073 magic_getglob(sv,mg)
1077 if (SvFAKE(sv)) { /* FAKE globs can get coerced */
1079 gv_efullname3(sv,((GV*)sv), "*");
1083 gv_efullname3(sv,((GV*)sv), "*"); /* a gv value, be nice */
1088 magic_setglob(sv,mg)
1098 if (*s == '*' && s[1])
1100 gv = gv_fetchpv(s,TRUE, SVt_PVGV);
1105 GvGP(sv) = gp_ref(GvGP(gv));
1110 magic_setsubstr(sv,mg)
1115 char *tmps = SvPV(sv,len);
1116 sv_insert(LvTARG(sv),LvTARGOFF(sv),LvTARGLEN(sv), tmps, len);
1121 magic_gettaint(sv,mg)
1125 TAINT_IF((mg->mg_len & 1) ||
1126 (mg->mg_len & 2) && mg->mg_obj == sv); /* kludge */
1131 magic_settaint(sv,mg)
1136 if (localizing == 1)
1153 do_vecset(sv); /* XXX slurp this routine */
1158 magic_getdefelem(sv,mg)
1163 if (LvTARGLEN(sv)) {
1165 HV* hv = (HV*)LvTARG(sv);
1166 HE* he = hv_fetch_ent(hv, mg->mg_obj, FALSE, 0);
1171 AV* av = (AV*)LvTARG(sv);
1172 if ((I32)LvTARGOFF(sv) <= AvFILL(av))
1173 targ = AvARRAY(av)[LvTARGOFF(sv)];
1175 if (targ && targ != &sv_undef) {
1176 /* somebody else defined it for us */
1177 SvREFCNT_dec(LvTARG(sv));
1178 LvTARG(sv) = SvREFCNT_inc(targ);
1180 SvREFCNT_dec(mg->mg_obj);
1181 mg->mg_obj = Nullsv;
1182 mg->mg_flags &= ~MGf_REFCOUNTED;
1187 sv_setsv(sv, targ ? targ : &sv_undef);
1192 magic_setdefelem(sv,mg)
1199 sv_setsv(LvTARG(sv), sv);
1200 SvSETMAGIC(LvTARG(sv));
1206 magic_freedefelem(sv,mg)
1210 SvREFCNT_dec(LvTARG(sv));
1221 if (!LvTARGLEN(sv) || !(mg = mg_find(sv, 'y')))
1224 HV* hv = (HV*)LvTARG(sv);
1225 HE* he = hv_fetch_ent(hv, mg->mg_obj, TRUE, 0);
1226 if (!he || (value = HeVAL(he)) == &sv_undef)
1227 croak(no_helem, SvPV(mg->mg_obj, na));
1230 AV* av = (AV*)LvTARG(sv);
1231 if ((I32)LvTARGLEN(sv) < 0 && (I32)LvTARGOFF(sv) > AvFILL(av))
1232 LvTARG(sv) = Nullsv; /* array can't be extended */
1234 SV** svp = av_fetch(av, LvTARGOFF(sv), TRUE);
1235 if (!svp || (value = *svp) == &sv_undef)
1236 croak(no_aelem, (I32)LvTARGOFF(sv));
1239 (void)SvREFCNT_inc(value);
1240 SvREFCNT_dec(LvTARG(sv));
1243 SvREFCNT_dec(mg->mg_obj);
1244 mg->mg_obj = Nullsv;
1245 mg->mg_flags &= ~MGf_REFCOUNTED;
1249 magic_setmglob(sv,mg)
1263 sv_unmagic(sv, 'B');
1273 sv_unmagic(sv, 'f');
1279 magic_setuvar(sv,mg)
1283 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
1285 if (uf && uf->uf_set)
1286 (*uf->uf_set)(uf->uf_index, sv);
1290 #ifdef USE_LOCALE_COLLATE
1292 magic_setcollxfrm(sv,mg)
1297 * René Descartes said "I think not."
1298 * and vanished with a faint plop.
1301 Safefree(mg->mg_ptr);
1307 #endif /* USE_LOCALE_COLLATE */
1317 switch (*mg->mg_ptr) {
1318 case '\001': /* ^A */
1319 sv_setsv(bodytarget, sv);
1321 case '\004': /* ^D */
1322 debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | 0x80000000;
1323 DEBUG_x(dump_all());
1325 case '\005': /* ^E */
1327 set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1329 /* will anyone ever use this? */
1330 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv), 4);
1333 case '\006': /* ^F */
1334 maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1336 case '\010': /* ^H */
1337 hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1343 inplace = savepv(SvPV(sv,na));
1347 case '\017': /* ^O */
1351 osname = savepv(SvPV(sv,na));
1355 case '\020': /* ^P */
1356 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1365 case '\024': /* ^T */
1367 basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv));
1369 basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1372 case '\027': /* ^W */
1373 dowarn = (bool)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1377 if (localizing == 1)
1378 save_sptr((SV**)&last_in_gv);
1380 else if (SvOK(sv) && GvIO(last_in_gv))
1381 IoLINES(GvIOp(last_in_gv)) = (long)SvIV(sv);
1384 Safefree(IoTOP_NAME(GvIOp(defoutgv)));
1385 IoTOP_NAME(GvIOp(defoutgv)) = s = savepv(SvPV(sv,na));
1386 IoTOP_GV(GvIOp(defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1389 Safefree(IoFMT_NAME(GvIOp(defoutgv)));
1390 IoFMT_NAME(GvIOp(defoutgv)) = s = savepv(SvPV(sv,na));
1391 IoFMT_GV(GvIOp(defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1394 IoPAGE_LEN(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1397 IoLINES_LEFT(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1398 if (IoLINES_LEFT(GvIOp(defoutgv)) < 0L)
1399 IoLINES_LEFT(GvIOp(defoutgv)) = 0L;
1402 IoPAGE(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1406 IO *io = GvIOp(defoutgv);
1407 if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) == 0)
1408 IoFLAGS(io) &= ~IOf_FLUSH;
1410 if (!(IoFLAGS(io) & IOf_FLUSH)) {
1411 PerlIO *ofp = IoOFP(io);
1413 (void)PerlIO_flush(ofp);
1414 IoFLAGS(io) |= IOf_FLUSH;
1420 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1421 multiline = (i != 0);
1427 rs = SvREFCNT_inc(nrs);
1432 if (SvOK(sv) || SvGMAGICAL(sv))
1433 ors = savepv(SvPV(sv,orslen));
1442 ofs = savepv(SvPV(sv, ofslen));
1447 ofmt = savepv(SvPV(sv,na));
1450 compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1453 #ifdef COMPLEX_STATUS
1454 if (localizing == 2) {
1455 statusvalue = LvTARGOFF(sv);
1456 statusvalue_vms = LvTARGLEN(sv);
1460 #ifdef VMSISH_STATUS
1462 STATUS_NATIVE_SET((U32)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)));
1465 STATUS_POSIX_SET(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1468 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv),
1469 (SvIV(sv) == EVMSERR) ? 4 : vaxc$errno);
1472 uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1474 delaymagic |= DM_RUID;
1475 break; /* don't do magic till later */
1478 (void)setruid((Uid_t)uid);
1481 (void)setreuid((Uid_t)uid, (Uid_t)-1);
1483 #ifdef HAS_SETRESUID
1484 (void)setresuid((Uid_t)uid, (Uid_t)-1, (Uid_t)-1);
1486 if (uid == euid) /* special case $< = $> */
1489 uid = (I32)getuid();
1490 croak("setruid() not implemented");
1495 uid = (I32)getuid();
1496 tainting |= (uid && (euid != uid || egid != gid));
1499 euid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1501 delaymagic |= DM_EUID;
1502 break; /* don't do magic till later */
1505 (void)seteuid((Uid_t)euid);
1508 (void)setreuid((Uid_t)-1, (Uid_t)euid);
1510 #ifdef HAS_SETRESUID
1511 (void)setresuid((Uid_t)-1, (Uid_t)euid, (Uid_t)-1);
1513 if (euid == uid) /* special case $> = $< */
1516 euid = (I32)geteuid();
1517 croak("seteuid() not implemented");
1522 euid = (I32)geteuid();
1523 tainting |= (uid && (euid != uid || egid != gid));
1526 gid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1528 delaymagic |= DM_RGID;
1529 break; /* don't do magic till later */
1532 (void)setrgid((Gid_t)gid);
1535 (void)setregid((Gid_t)gid, (Gid_t)-1);
1537 #ifdef HAS_SETRESGID
1538 (void)setresgid((Gid_t)gid, (Gid_t)-1, (Gid_t) 1);
1540 if (gid == egid) /* special case $( = $) */
1543 gid = (I32)getgid();
1544 croak("setrgid() not implemented");
1549 gid = (I32)getgid();
1550 tainting |= (uid && (euid != uid || egid != gid));
1553 #ifdef HAS_SETGROUPS
1555 char *p = SvPV(sv, na);
1556 Groups_t gary[NGROUPS];
1558 SET_NUMERIC_STANDARD();
1561 egid = I_V(atof(p));
1562 for (i = 0; i < NGROUPS; ++i) {
1563 while (*p && !isSPACE(*p))
1569 gary[i] = I_V(atof(p));
1572 (void)setgroups(i, gary);
1574 #else /* HAS_SETGROUPS */
1575 egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1576 #endif /* HAS_SETGROUPS */
1578 delaymagic |= DM_EGID;
1579 break; /* don't do magic till later */
1582 (void)setegid((Gid_t)egid);
1585 (void)setregid((Gid_t)-1, (Gid_t)egid);
1587 #ifdef HAS_SETRESGID
1588 (void)setresgid((Gid_t)-1, (Gid_t)egid, (Gid_t)-1);
1590 if (egid == gid) /* special case $) = $( */
1593 egid = (I32)getegid();
1594 croak("setegid() not implemented");
1599 egid = (I32)getegid();
1600 tainting |= (uid && (euid != uid || egid != gid));
1603 chopset = SvPV_force(sv,na);
1609 /* See if all the arguments are contiguous in memory */
1610 for (i = 1; i < origargc; i++) {
1611 if (origargv[i] == s + 1)
1612 s += strlen(++s); /* this one is ok too */
1614 /* can grab env area too? */
1615 if (origenviron && origenviron[0] == s + 1) {
1616 my_setenv("NoNe SuCh", Nullch);
1617 /* force copy of environment */
1618 for (i = 0; origenviron[i]; i++)
1619 if (origenviron[i] == s + 1)
1622 origalen = s - origargv[0];
1624 s = SvPV_force(sv,len);
1626 if (i >= origalen) {
1630 Copy(s, origargv[0], i, char);
1633 Copy(s, origargv[0], i, char);
1636 while (++i < origalen)
1639 for (i = 1; i < origargc; i++)
1640 origargv[i] = Nullch;
1651 register char **sigv;
1653 for (sigv = sig_name+1; *sigv; sigv++)
1654 if (strEQ(sig,*sigv))
1655 return sig_num[sigv - sig_name];
1657 if (strEQ(sig,"CHLD"))
1661 if (strEQ(sig,"CLD"))
1679 die("Signal SIG%s received, but no signal handler set.\n",
1682 cv = sv_2cv(psig_ptr[sig],&st,&gv,TRUE);
1683 if (!cv || !CvROOT(cv)) {
1685 warn("SIG%s handler \"%s\" not defined.\n",
1686 sig_name[sig], GvENAME(gv) );
1690 oldstack = curstack;
1691 if (curstack != signalstack)
1692 AvFILL(signalstack) = 0;
1693 SWITCHSTACK(curstack, signalstack);
1696 sv = SvREFCNT_inc(psig_name[sig]);
1698 sv = sv_newmortal();
1699 sv_setpv(sv,sig_name[sig]);
1705 perl_call_sv((SV*)cv, G_DISCARD);
1707 SWITCHSTACK(signalstack, oldstack);