3 * Copyright (c) 1991-1994, 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 /* Omit -- it causes too much grief on mixed systems.
25 * Use the "DESTRUCTOR" scope cleanup to reinstate magic.
32 typedef struct magic_state MGS;
34 static void restore_magic _((void *p));
42 assert(SvMAGICAL(sv));
44 mgs = (MGS*)safemalloc(sizeof(MGS));
46 mgs->mgs_flags = SvMAGICAL(sv) | SvREADONLY(sv);
47 SAVEDESTRUCTOR(restore_magic, mgs);
51 SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT;
63 if (SvTYPE(sv) >= SVt_PVMG && SvMAGIC(sv))
66 SvFLAGS(sv) |= mgs->mgs_flags;
70 SvFLAGS(sv) &= ~(SVf_IOK|SVf_NOK|SVf_POK);
73 safefree((void *)mgs);
82 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
83 MGVTBL* vtbl = mg->mg_virtual;
85 if (vtbl->svt_get && !(mg->mg_flags & MGf_GSKIP))
89 if (!(SvFLAGS(sv) & (SVs_GMG|SVs_SMG)) || vtbl->svt_clear)
104 mgs = save_magic(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 (*mgp == mg && (mg->mg_flags & MGf_GSKIP))
115 /* Advance to next magic (complicated by possible deletion) */
117 mgp = &mg->mg_moremagic;
133 mgs = save_magic(sv);
135 for (mg = SvMAGIC(sv); mg; mg = nextmg) {
136 MGVTBL* vtbl = mg->mg_virtual;
137 nextmg = mg->mg_moremagic; /* it may delete itself */
138 if (mg->mg_flags & MGf_GSKIP) {
139 mg->mg_flags &= ~MGf_GSKIP; /* setting requires another read */
142 if (vtbl && vtbl->svt_set)
143 (*vtbl->svt_set)(sv, mg);
158 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
159 MGVTBL* vtbl = mg->mg_virtual;
160 if (vtbl && vtbl->svt_len) {
163 /* omit MGf_GSKIP -- not changed here */
164 len = (*vtbl->svt_len)(sv, mg);
170 junk = SvPV(sv, len);
183 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
184 MGVTBL* vtbl = mg->mg_virtual;
185 /* omit GSKIP -- never set here */
187 if (vtbl && vtbl->svt_clear)
188 (*vtbl->svt_clear)(sv, mg);
201 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
202 if (mg->mg_type == type)
209 mg_copy(sv, nsv, key, klen)
217 for (mg = SvMAGIC(sv); mg; mg = mg->mg_moremagic) {
218 if (isUPPER(mg->mg_type)) {
219 sv_magic(nsv, mg->mg_obj, toLOWER(mg->mg_type), key, klen);
232 for (mg = SvMAGIC(sv); mg; mg = moremagic) {
233 MGVTBL* vtbl = mg->mg_virtual;
234 moremagic = mg->mg_moremagic;
235 if (vtbl && vtbl->svt_free)
236 (*vtbl->svt_free)(sv, mg);
237 if (mg->mg_ptr && mg->mg_type != 'g')
239 Safefree(mg->mg_ptr);
240 else if (mg->mg_len == HEf_SVKEY)
241 SvREFCNT_dec((SV*)mg->mg_ptr);
242 if (mg->mg_flags & MGf_REFCOUNTED)
243 SvREFCNT_dec(mg->mg_obj);
250 #if !defined(NSIG) || defined(M_UNIX) || defined(M_XENIX)
264 switch (*mg->mg_ptr) {
265 case '1': case '2': case '3': case '4':
266 case '5': case '6': case '7': case '8': case '9': case '&':
268 paren = atoi(mg->mg_ptr);
270 if (curpm->op_pmregexp &&
271 paren <= curpm->op_pmregexp->nparens &&
272 (s = curpm->op_pmregexp->startp[paren]) &&
273 (t = curpm->op_pmregexp->endp[paren]) ) {
283 paren = curpm->op_pmregexp->lastparen;
292 if (curpm->op_pmregexp &&
293 (s = curpm->op_pmregexp->subbeg) ) {
294 i = curpm->op_pmregexp->startp[0] - s;
302 if (curpm->op_pmregexp &&
303 (s = curpm->op_pmregexp->endp[0]) ) {
304 return (STRLEN) (curpm->op_pmregexp->subend - s);
309 return (STRLEN)ofslen;
311 return (STRLEN)orslen;
314 if (!SvPOK(sv) && SvNIOK(sv))
331 switch (*mg->mg_ptr) {
332 case '\001': /* ^A */
333 sv_setsv(sv, bodytarget);
335 case '\004': /* ^D */
336 sv_setiv(sv,(I32)(debug & 32767));
338 case '\005': /* ^E */
341 # include <descrip.h>
342 # include <starlet.h>
344 $DESCRIPTOR(msgdsc,msg);
345 sv_setnv(sv,(double)vaxc$errno);
346 if (sys$getmsg(vaxc$errno,&msgdsc.dsc$w_length,&msgdsc,0,0) & 1)
347 sv_setpvn(sv,msgdsc.dsc$a_pointer,msgdsc.dsc$w_length);
353 sv_setnv(sv,(double)Perl_rc);
354 sv_setpv(sv, os2error(Perl_rc));
356 sv_setnv(sv,(double)errno);
357 sv_setpv(sv, errno ? Strerror(errno) : "");
360 SvNOK_on(sv); /* what a wonderful hack! */
362 case '\006': /* ^F */
363 sv_setiv(sv,(I32)maxsysfd);
365 case '\010': /* ^H */
366 sv_setiv(sv,(I32)hints);
370 sv_setpv(sv, inplace);
372 sv_setsv(sv,&sv_undef);
374 case '\017': /* ^O */
377 case '\020': /* ^P */
378 sv_setiv(sv,(I32)perldb);
380 case '\024': /* ^T */
382 sv_setnv(sv,basetime);
384 sv_setiv(sv,(I32)basetime);
387 case '\027': /* ^W */
388 sv_setiv(sv,(I32)dowarn);
390 case '1': case '2': case '3': case '4':
391 case '5': case '6': case '7': case '8': case '9': case '&':
393 paren = atoi(GvENAME((GV*)mg->mg_obj));
395 if (curpm->op_pmregexp &&
396 paren <= curpm->op_pmregexp->nparens &&
397 (s = curpm->op_pmregexp->startp[paren]) &&
398 (t = curpm->op_pmregexp->endp[paren]) ) {
403 if (tainting && (tmg = mg_find(sv,'t')))
404 tmg->mg_len = 0; /* guarantee $1 untainted */
409 sv_setsv(sv,&sv_undef);
413 paren = curpm->op_pmregexp->lastparen;
417 sv_setsv(sv,&sv_undef);
421 if (curpm->op_pmregexp &&
422 (s = curpm->op_pmregexp->subbeg) ) {
423 i = curpm->op_pmregexp->startp[0] - s;
430 sv_setsv(sv,&sv_undef);
434 if (curpm->op_pmregexp &&
435 (s = curpm->op_pmregexp->endp[0]) ) {
436 sv_setpvn(sv,s, curpm->op_pmregexp->subend - s);
440 sv_setsv(sv,&sv_undef);
444 if (GvIO(last_in_gv)) {
445 sv_setiv(sv,(I32)IoLINES(GvIO(last_in_gv)));
450 sv_setiv(sv,(I32)statusvalue);
453 s = IoTOP_NAME(GvIOp(defoutgv));
457 sv_setpv(sv,GvENAME(defoutgv));
462 s = IoFMT_NAME(GvIOp(defoutgv));
464 s = GvENAME(defoutgv);
469 sv_setiv(sv,(I32)IoPAGE_LEN(GvIOp(defoutgv)));
472 sv_setiv(sv,(I32)IoLINES_LEFT(GvIOp(defoutgv)));
475 sv_setiv(sv,(I32)IoPAGE(GvIOp(defoutgv)));
483 sv_setiv(sv,(I32)curcop->cop_arybase);
486 sv_setiv(sv, (IoFLAGS(GvIOp(defoutgv)) & IOf_FLUSH) != 0 );
489 sv_setpvn(sv,ofs,ofslen);
492 sv_setpvn(sv,ors,orslen);
499 sv_setnv(sv,(double)((errno == EVMSERR) ? vaxc$errno : errno));
500 sv_setpv(sv, errno ? Strerror(errno) : "");
503 int saveerrno = errno;
504 sv_setnv(sv,(double)errno);
506 if (errno == errno_isOS2) sv_setpv(sv, os2error(Perl_rc));
509 sv_setpv(sv, errno ? Strerror(errno) : "");
513 SvNOK_on(sv); /* what a wonderful hack! */
516 sv_setiv(sv,(I32)uid);
519 sv_setiv(sv,(I32)euid);
523 (void)sprintf(s,"%d",(int)gid);
527 (void)sprintf(s,"%d",(int)egid);
535 Groups_t gary[NGROUPS];
537 i = getgroups(NGROUPS,gary);
539 (void)sprintf(s," %ld", (long)gary[i]);
555 magic_getuvar(sv, mg)
559 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
561 if (uf && uf->uf_val)
562 (*uf->uf_val)(uf->uf_index, sv);
576 ptr = (mg->mg_len == HEf_SVKEY) ? SvPV((SV*)mg->mg_ptr, na) : mg->mg_ptr;
578 #ifdef DYNAMIC_ENV_FETCH
579 /* We just undefd an environment var. Is a replacement */
580 /* waiting in the wings? */
583 if (envhe = hv_fetch_ent(GvHVn(envgv),HeSVKEY((HE*)(mg->mg_ptr)),FALSE,0))
584 s = SvPV(HeVAL(envhe),len);
587 /* And you'll never guess what the dog had */
588 /* in its mouth... */
590 if (s && strEQ(ptr,"PATH")) {
591 char *strend = s + len;
594 s = cpytill(tokenbuf,s,strend,':',&i);
597 || (Stat(tokenbuf,&statbuf) && (statbuf.st_mode & 2)) )
606 magic_clearenv(sv,mg)
610 my_setenv(((mg->mg_len == HEf_SVKEY) ?
611 SvPV((SV*)mg->mg_ptr, na) : mg->mg_ptr),Nullch);
616 /* set up reliable signal() clone */
618 typedef void (*Sigfunc) _((int));
621 Sigfunc rsignal(signo,handler)
625 struct sigaction act,oact;
627 act.sa_handler = handler;
628 sigemptyset(&act.sa_mask);
631 act.sa_flags |= SA_RESTART; /* SVR4, 4.3+BSD */
633 if (sigaction(signo, &act, &oact) < 0)
636 return(oact.sa_handler);
641 /* ah well, so much for reliability */
643 #define rsignal(x,y) signal(x,y)
661 /* Are we fetching a signal entry? */
662 i = whichsig(mg->mg_ptr);
665 sv_setsv(sv,psig_ptr[i]);
667 void (*origsig)(int);
668 /* get signal state without losing signals */
670 origsig = rsignal(i,sig_trap);
674 /* cache state so we don't fetch it again */
675 if(origsig == SIG_IGN)
676 sv_setpv(sv,"IGNORE");
678 sv_setsv(sv,&sv_undef);
679 psig_ptr[i] = SvREFCNT_inc(sv);
686 magic_clearsig(sv,mg)
691 /* Are we clearing a signal entry? */
692 i = whichsig(mg->mg_ptr);
695 SvREFCNT_dec(psig_ptr[i]);
699 SvREFCNT_dec(psig_name[i]);
715 s = (mg->mg_len == HEf_SVKEY) ? SvPV((SV*)mg->mg_ptr, na) : mg->mg_ptr;
717 if (strEQ(s,"__DIE__"))
719 else if (strEQ(s,"__WARN__"))
721 else if (strEQ(s,"__PARSE__"))
724 croak("No such hook: %s", s);
732 i = whichsig(s); /* ...no, a brick */
734 if (dowarn || strEQ(s,"ALARM"))
735 warn("No such signal: SIG%s", s);
739 SvREFCNT_dec(psig_ptr[i]);
740 psig_ptr[i] = SvREFCNT_inc(sv);
742 SvREFCNT_dec(psig_name[i]);
743 psig_name[i] = newSVpv(mg->mg_ptr,strlen(mg->mg_ptr));
744 SvTEMP_off(sv); /* Make sure it doesn't go away on us */
745 SvREADONLY_on(psig_name[i]);
747 if (SvTYPE(sv) == SVt_PVGV || SvROK(sv)) {
749 (void)rsignal(i,sighandler);
751 *svp = SvREFCNT_inc(sv);
754 s = SvPV_force(sv,na);
755 if (strEQ(s,"IGNORE")) {
757 (void)rsignal(i,SIG_IGN);
761 else if (strEQ(s,"DEFAULT") || !*s) {
763 (void)rsignal(i,SIG_DFL);
768 if (!strchr(s,':') && !strchr(s,'\'')) {
769 sprintf(tokenbuf, "main::%s",s);
770 sv_setpv(sv,tokenbuf);
773 (void)rsignal(i,sighandler);
775 *svp = SvREFCNT_inc(sv);
792 magic_setamagic(sv,mg)
796 /* HV_badAMAGIC_on(Sv_STASH(sv)); */
801 #endif /* OVERLOAD */
804 magic_methpack(sv,mg,meth)
818 PUSHs(sv_2mortal(newSVpv(mg->mg_ptr, mg->mg_len)));
819 else if (mg->mg_len == HEf_SVKEY)
820 PUSHs((SV*)mg->mg_ptr);
822 else if (mg->mg_type == 'p')
823 PUSHs(sv_2mortal(newSViv(mg->mg_len)));
826 if (perl_call_method(meth, G_SCALAR))
827 sv_setsv(sv, *stack_sp--);
839 magic_methpack(sv,mg,"FETCH");
841 mg->mg_flags |= MGf_GSKIP;
857 PUSHs(sv_2mortal(newSVpv(mg->mg_ptr, mg->mg_len)));
858 else if (mg->mg_len == HEf_SVKEY)
859 PUSHs((SV*)mg->mg_ptr);
861 else if (mg->mg_type == 'p')
862 PUSHs(sv_2mortal(newSViv(mg->mg_len)));
866 perl_call_method("STORE", G_SCALAR|G_DISCARD);
872 magic_clearpack(sv,mg)
876 return magic_methpack(sv,mg,"DELETE");
879 int magic_wipepack(sv,mg)
889 perl_call_method("CLEAR", G_SCALAR|G_DISCARD);
895 magic_nextpack(sv,mg,key)
901 char *meth = SvOK(key) ? "NEXTKEY" : "FIRSTKEY";
912 if (perl_call_method(meth, G_SCALAR))
913 sv_setsv(key, *stack_sp--);
921 magic_existspack(sv,mg)
925 return magic_methpack(sv,mg,"EXISTS");
929 magic_setdbline(sv,mg)
940 svp = av_fetch(GvAV(gv),atoi(mg->mg_ptr), FALSE);
941 if (svp && SvIOKp(*svp) && (o = (OP*)SvSTASH(*svp)))
944 warn("Can't break at that line\n");
949 magic_getarylen(sv,mg)
953 sv_setiv(sv, AvFILL((AV*)mg->mg_obj) + curcop->cop_arybase);
958 magic_setarylen(sv,mg)
962 av_fill((AV*)mg->mg_obj, SvIV(sv) - curcop->cop_arybase);
971 SV* lsv = LvTARG(sv);
973 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv)) {
974 mg = mg_find(lsv, 'g');
975 if (mg && mg->mg_len >= 0) {
976 sv_setiv(sv, mg->mg_len + curcop->cop_arybase);
989 SV* lsv = LvTARG(sv);
995 if (SvTYPE(lsv) >= SVt_PVMG && SvMAGIC(lsv))
996 mg = mg_find(lsv, 'g');
1000 sv_magic(lsv, (SV*)0, 'g', Nullch, 0);
1001 mg = mg_find(lsv, 'g');
1003 else if (!SvOK(sv)) {
1007 len = SvPOK(lsv) ? SvCUR(lsv) : sv_len(lsv);
1009 pos = SvIV(sv) - curcop->cop_arybase;
1023 magic_getglob(sv,mg)
1027 gv_efullname(sv,((GV*)sv));/* a gv value, be nice */
1032 magic_setglob(sv,mg)
1042 if (*s == '*' && s[1])
1044 gv = gv_fetchpv(s,TRUE, SVt_PVGV);
1049 GvGP(sv) = gp_ref(GvGP(gv));
1055 GvIOp(gv) = newIO();
1060 magic_setsubstr(sv,mg)
1065 char *tmps = SvPV(sv,len);
1066 sv_insert(LvTARG(sv),LvTARGOFF(sv),LvTARGLEN(sv), tmps, len);
1071 magic_gettaint(sv,mg)
1077 else if (mg->mg_len & 2 && mg->mg_obj == sv) /* kludge */
1083 magic_settaint(sv,mg)
1088 if (localizing == 1)
1105 do_vecset(sv); /* XXX slurp this routine */
1110 magic_setmglob(sv,mg)
1124 sv_unmagic(sv, 'B');
1130 magic_setuvar(sv,mg)
1134 struct ufuncs *uf = (struct ufuncs *)mg->mg_ptr;
1136 if (uf && uf->uf_set)
1137 (*uf->uf_set)(uf->uf_index, sv);
1149 switch (*mg->mg_ptr) {
1150 case '\001': /* ^A */
1151 sv_setsv(bodytarget, sv);
1153 case '\004': /* ^D */
1154 debug = (SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) | 0x80000000;
1155 DEBUG_x(dump_all());
1157 case '\005': /* ^E */
1159 set_vaxc_errno(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1161 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv),4); /* will anyone ever use this? */
1164 case '\006': /* ^F */
1165 maxsysfd = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1167 case '\010': /* ^H */
1168 hints = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1174 inplace = savepv(SvPV(sv,na));
1178 case '\017': /* ^O */
1182 osname = savepv(SvPV(sv,na));
1186 case '\020': /* ^P */
1187 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1196 case '\024': /* ^T */
1198 basetime = (Time_t)(SvNOK(sv) ? SvNVX(sv) : sv_2nv(sv));
1200 basetime = (Time_t)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1203 case '\027': /* ^W */
1204 dowarn = (bool)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1208 if (localizing == 1)
1209 save_sptr((SV**)&last_in_gv);
1211 else if (SvOK(sv) && GvIO(last_in_gv))
1212 IoLINES(GvIOp(last_in_gv)) = (long)SvIV(sv);
1215 Safefree(IoTOP_NAME(GvIOp(defoutgv)));
1216 IoTOP_NAME(GvIOp(defoutgv)) = s = savepv(SvPV(sv,na));
1217 IoTOP_GV(GvIOp(defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1220 Safefree(IoFMT_NAME(GvIOp(defoutgv)));
1221 IoFMT_NAME(GvIOp(defoutgv)) = s = savepv(SvPV(sv,na));
1222 IoFMT_GV(GvIOp(defoutgv)) = gv_fetchpv(s,TRUE, SVt_PVIO);
1225 IoPAGE_LEN(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1228 IoLINES_LEFT(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1229 if (IoLINES_LEFT(GvIOp(defoutgv)) < 0L)
1230 IoLINES_LEFT(GvIOp(defoutgv)) = 0L;
1233 IoPAGE(GvIOp(defoutgv)) = (long)(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1236 IoFLAGS(GvIOp(defoutgv)) &= ~IOf_FLUSH;
1237 if ((SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv)) != 0) {
1238 IoFLAGS(GvIOp(defoutgv)) |= IOf_FLUSH;
1242 i = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1243 multiline = (i != 0);
1249 rs = SvREFCNT_inc(nrs);
1254 ors = savepv(SvPV(sv,orslen));
1259 ofs = savepv(SvPV(sv, ofslen));
1264 ofmt = savepv(SvPV(sv,na));
1267 compiling.cop_arybase = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1270 statusvalue = FIXSTATUS(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv));
1273 SETERRNO(SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv),SvIV(sv) == EVMSERR ? 4 : vaxc$errno); /* will anyone ever use this? */
1276 uid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1278 delaymagic |= DM_RUID;
1279 break; /* don't do magic till later */
1282 (void)setruid((Uid_t)uid);
1285 (void)setreuid((Uid_t)uid, (Uid_t)-1);
1287 #ifdef HAS_SETRESUID
1288 (void)setresuid((Uid_t)uid, (Uid_t)-1, (Uid_t)-1);
1290 if (uid == euid) /* special case $< = $> */
1293 uid = (I32)getuid();
1294 croak("setruid() not implemented");
1299 uid = (I32)getuid();
1300 tainting |= (uid && (euid != uid || egid != gid));
1303 euid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1305 delaymagic |= DM_EUID;
1306 break; /* don't do magic till later */
1309 (void)seteuid((Uid_t)euid);
1312 (void)setreuid((Uid_t)-1, (Uid_t)euid);
1314 #ifdef HAS_SETRESUID
1315 (void)setresuid((Uid_t)-1, (Uid_t)euid, (Uid_t)-1);
1317 if (euid == uid) /* special case $> = $< */
1320 euid = (I32)geteuid();
1321 croak("seteuid() not implemented");
1326 euid = (I32)geteuid();
1327 tainting |= (uid && (euid != uid || egid != gid));
1330 gid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1332 delaymagic |= DM_RGID;
1333 break; /* don't do magic till later */
1336 (void)setrgid((Gid_t)gid);
1339 (void)setregid((Gid_t)gid, (Gid_t)-1);
1341 #ifdef HAS_SETRESGID
1342 (void)setresgid((Gid_t)gid, (Gid_t)-1, (Gid_t) 1);
1344 if (gid == egid) /* special case $( = $) */
1347 gid = (I32)getgid();
1348 croak("setrgid() not implemented");
1353 gid = (I32)getgid();
1354 tainting |= (uid && (euid != uid || egid != gid));
1357 egid = SvIOK(sv) ? SvIVX(sv) : sv_2iv(sv);
1359 delaymagic |= DM_EGID;
1360 break; /* don't do magic till later */
1363 (void)setegid((Gid_t)egid);
1366 (void)setregid((Gid_t)-1, (Gid_t)egid);
1368 #ifdef HAS_SETRESGID
1369 (void)setresgid((Gid_t)-1, (Gid_t)egid, (Gid_t)-1);
1371 if (egid == gid) /* special case $) = $( */
1374 egid = (I32)getegid();
1375 croak("setegid() not implemented");
1380 egid = (I32)getegid();
1381 tainting |= (uid && (euid != uid || egid != gid));
1384 chopset = SvPV_force(sv,na);
1390 /* See if all the arguments are contiguous in memory */
1391 for (i = 1; i < origargc; i++) {
1392 if (origargv[i] == s + 1)
1393 s += strlen(++s); /* this one is ok too */
1395 if (origenviron[0] == s + 1) { /* can grab env area too? */
1396 my_setenv("NoNeSuCh", Nullch);
1397 /* force copy of environment */
1398 for (i = 0; origenviron[i]; i++)
1399 if (origenviron[i] == s + 1)
1402 origalen = s - origargv[0];
1404 s = SvPV_force(sv,len);
1406 if (i >= origalen) {
1410 Copy(s, origargv[0], i, char);
1413 Copy(s, origargv[0], i, char);
1416 while (++i < origalen)
1419 for (i = 1; i < origargc; i++)
1420 origargv[i] = Nullch;
1431 register char **sigv;
1433 for (sigv = sig_name+1; *sigv; sigv++)
1434 if (strEQ(sig,*sigv))
1435 return sig_num[sigv - sig_name];
1437 if (strEQ(sig,"CHLD"))
1441 if (strEQ(sig,"CLD"))
1458 cv = sv_2cv(psig_ptr[sig],&st,&gv,TRUE);
1459 if (!cv || !CvROOT(cv)) {
1461 warn("SIG%s handler \"%s\" not defined.\n",
1462 sig_name[sig], GvENAME(gv) );
1466 oldstack = curstack;
1467 if (curstack != signalstack)
1468 AvFILL(signalstack) = 0;
1469 SWITCHSTACK(curstack, signalstack);
1472 sv = SvREFCNT_inc(psig_name[sig]);
1474 sv = sv_newmortal();
1475 sv_setpv(sv,sig_name[sig]);
1481 perl_call_sv((SV*)cv, G_DISCARD);
1483 SWITCHSTACK(signalstack, oldstack);