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 * "Far below them they saw the white waters pour into a foaming bowl, and
12 * then swirl darkly about a deep oval basin in the rocks, until they found
13 * their way out again through a narrow gate, and flowed away, fuming and
14 * chattering, into calmer and more level reaches."
20 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
30 # ifndef HAS_SHMAT_PROTOTYPE
31 extern Shmat_t shmat _((int, char *, int));
46 /* Omit -- it causes too much grief on mixed systems.
53 do_open(gv,name,len,supplied_fp)
60 register IO *io = GvIOn(gv);
61 char *myname = savepv(name);
66 char mode[3]; /* stdio file mode ("r\0" or "r+\0") */
67 FILE *saveifp = Nullfp;
68 FILE *saveofp = Nullfp;
72 mode[0] = mode[1] = mode[2] = '\0';
74 forkprocess = 1; /* assume true if no fork */
75 while (len && isSPACE(name[len-1]))
78 fd = fileno(IoIFP(io));
79 if (IoTYPE(io) == '-')
81 else if (fd <= maxsysfd) {
84 savetype = IoTYPE(io);
87 else if (IoTYPE(io) == '|')
88 result = my_pclose(IoIFP(io));
89 else if (IoIFP(io) != IoOFP(io)) {
91 result = fclose(IoOFP(io));
92 fclose(IoIFP(io)); /* clear stdio, fd already closed */
95 result = fclose(IoIFP(io));
98 result = fclose(IoIFP(io));
99 if (result == EOF && fd > maxsysfd)
100 fprintf(stderr,"Warning: unable to close filehandle %s properly.\n",
102 IoOFP(io) = IoIFP(io) = Nullfp;
104 if (*name == '+' && len > 1 && name[len-1] != '|') { /* scary */
116 for (name++; isSPACE(*name); name++) ;
119 TAINT_PROPER("piped open");
120 if (dowarn && name[strlen(name)-1] == '|')
121 warn("Can't do bidirectional pipe");
122 fp = my_popen(name,"w");
125 else if (*name == '>') {
126 TAINT_PROPER("open");
129 mode[0] = IoTYPE(io) = 'a';
143 if (!*name && supplied_fp)
146 while (isSPACE(*name))
152 gv = gv_fetchpv(name,FALSE,SVt_PVIO);
161 fd = fileno(IoIFP(thatio));
162 if (IoTYPE(thatio) == 's')
170 if (!(fp = fdopen(fd,mode)))
176 while (isSPACE(*name))
178 if (strEQ(name,"-")) {
183 fp = fopen(name,mode);
191 while (isSPACE(*name))
195 if (strEQ(name,"-")) {
200 fp = fopen(name,mode);
202 else if (name[len-1] == '|') {
204 while (len && isSPACE(name[len-1]))
207 for (; isSPACE(*name); name++) ;
210 TAINT_PROPER("piped open");
211 fp = my_popen(name,"r");
217 for (; isSPACE(*name); name++) ;
218 if (strEQ(name,"-")) {
223 fp = fopen(name,"r");
227 if (dowarn && IoTYPE(io) == '<' && strchr(name, '\n'))
228 warn(warn_nl, "open");
232 IoTYPE(io) != '|' && IoTYPE(io) != '-') {
233 if (Fstat(fileno(fp),&statbuf) < 0) {
237 if (S_ISSOCK(statbuf.st_mode))
238 IoTYPE(io) = 's'; /* in case a socket was passed in to us */
242 !(statbuf.st_mode & S_IFMT)
247 int buflen = sizeof tokenbuf;
248 if (getsockname(fileno(fp), (struct sockaddr *)tokenbuf, &buflen) >= 0
249 || errno != ENOTSOCK)
250 IoTYPE(io) = 's'; /* some OS's return 0 on fstat()ed socket */
251 /* but some return 0 for streams too, sigh */
255 if (saveifp) { /* must use old fp? */
256 fd = fileno(saveifp);
258 fflush(saveofp); /* emulate fclose() */
259 if (saveofp != saveifp) { /* was a socket? */
265 if (fd != fileno(fp)) {
269 dup2(fileno(fp), fd);
270 sv = *av_fetch(fdpid,fileno(fp),TRUE);
271 (void)SvUPGRADE(sv, SVt_IV);
274 sv = *av_fetch(fdpid,fd,TRUE);
275 (void)SvUPGRADE(sv, SVt_IV);
283 #if defined(HAS_FCNTL) && defined(F_SETFD)
285 fcntl(fd,F_SETFD,fd > maxsysfd);
289 if (IoTYPE(io) == 's'
290 || (IoTYPE(io) == '>' && S_ISCHR(statbuf.st_mode)) ) {
291 if (!(IoOFP(io) = fdopen(fileno(fp),"w"))) {
305 IoTYPE(io) = savetype;
314 #ifndef FLEXFILENAMES
322 argvoutgv = gv_fetchpv("ARGVOUT",TRUE,SVt_PVIO);
323 if (filemode & (S_ISUID|S_ISGID)) {
324 fflush(IoIFP(GvIOn(argvoutgv))); /* chmod must follow last write */
326 (void)fchmod(lastfd,filemode);
328 (void)chmod(oldname,filemode);
332 while (av_len(GvAV(gv)) >= 0) {
334 sv = av_shift(GvAV(gv));
336 sv_setsv(GvSV(gv),sv);
337 SvSETMAGIC(GvSV(gv));
338 oldname = SvPVx(GvSV(gv), len);
339 if (do_open(gv,oldname,len,Nullfp)) {
341 TAINT_PROPER("inplace open");
342 if (strEQ(oldname,"-")) {
343 defoutgv = gv_fetchpv("STDOUT",TRUE,SVt_PVIO);
344 return IoIFP(GvIOp(gv));
346 #ifndef FLEXFILENAMES
347 filedev = statbuf.st_dev;
348 fileino = statbuf.st_ino;
350 filemode = statbuf.st_mode;
351 fileuid = statbuf.st_uid;
352 filegid = statbuf.st_gid;
353 if (!S_ISREG(filemode)) {
354 warn("Can't do inplace edit: %s is not a regular file",
361 add_suffix(sv,inplace);
363 sv_catpv(sv,inplace);
365 #ifndef FLEXFILENAMES
366 if (Stat(SvPVX(sv),&statbuf) >= 0
367 && statbuf.st_dev == filedev
368 && statbuf.st_ino == fileino ) {
369 warn("Can't do inplace edit: %s > 14 characters",
377 if (rename(oldname,SvPVX(sv)) < 0) {
378 warn("Can't rename %s to %s: %s, skipping file",
379 oldname, SvPVX(sv), Strerror(errno) );
385 (void)unlink(SvPVX(sv));
386 (void)rename(oldname,SvPVX(sv));
387 do_open(gv,SvPVX(sv),SvCUR(GvSV(gv)),Nullfp);
390 (void)UNLINK(SvPVX(sv));
391 if (link(oldname,SvPVX(sv)) < 0) {
392 warn("Can't rename %s to %s: %s, skipping file",
393 oldname, SvPVX(sv), Strerror(errno) );
397 (void)UNLINK(oldname);
402 if (UNLINK(oldname) < 0) {
403 warn("Can't rename %s to %s: %s, skipping file",
404 oldname, SvPVX(sv), Strerror(errno) );
409 croak("Can't do inplace edit without backup");
414 sv_catpv(sv,oldname);
415 errno = 0; /* in case sprintf set errno */
416 if (!do_open(argvoutgv,SvPVX(sv),SvCUR(sv),Nullfp)) {
417 warn("Can't do inplace edit on %s: %s",
418 oldname, Strerror(errno) );
422 defoutgv = argvoutgv;
423 lastfd = fileno(IoIFP(GvIOp(argvoutgv)));
424 (void)Fstat(lastfd,&statbuf);
426 (void)fchmod(lastfd,filemode);
428 (void)chmod(oldname,filemode);
430 if (fileuid != statbuf.st_uid || filegid != statbuf.st_gid) {
432 (void)fchown(lastfd,fileuid,filegid);
435 (void)chown(oldname,fileuid,filegid);
440 return IoIFP(GvIOp(gv));
443 fprintf(stderr,"Can't open %s: %s\n",SvPV(sv, na), Strerror(errno));
446 (void)do_close(argvoutgv,FALSE);
447 defoutgv = gv_fetchpv("STDOUT",TRUE,SVt_PVIO);
454 do_pipe(sv, rgv, wgv)
478 IoIFP(rstio) = fdopen(fd[0], "r");
479 IoOFP(wstio) = fdopen(fd[1], "w");
480 IoIFP(wstio) = IoOFP(wstio);
483 if (!IoIFP(rstio) || !IoOFP(wstio)) {
484 if (IoIFP(rstio)) fclose(IoIFP(rstio));
486 if (IoOFP(wstio)) fclose(IoOFP(wstio));
491 sv_setsv(sv,&sv_yes);
495 sv_setsv(sv,&sv_undef);
501 #ifndef CAN_PROTOTYPE
502 do_close(gv,explicit)
506 do_close(GV *gv, bool explicit)
507 #endif /* CAN_PROTOTYPE */
515 if (!gv || SvTYPE(gv) != SVt_PVGV) {
520 if (!io) { /* never opened */
521 if (dowarn && explicit)
522 warn("Close on unopened file <%s>",GvENAME(gv));
526 if (IoTYPE(io) == '|') {
527 status = my_pclose(IoIFP(io));
528 retval = (status == 0);
529 statusvalue = (unsigned short)status & 0xffff;
531 else if (IoTYPE(io) == '-')
534 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) { /* a socket */
535 retval = (fclose(IoOFP(io)) != EOF);
536 fclose(IoIFP(io)); /* clear stdio, fd already closed */
539 retval = (fclose(IoIFP(io)) != EOF);
541 IoOFP(io) = IoIFP(io) = Nullfp;
546 IoLINES_LEFT(io) = IoPAGE_LEN(io);
566 #ifdef USE_STD_STDIO /* (the code works without this) */
567 if (IoIFP(io)->_cnt > 0) /* cheat a little, since */
568 return FALSE; /* this is the most usual case */
571 ch = getc(IoIFP(io));
573 (void)ungetc(ch, IoIFP(io));
577 if (IoIFP(io)->_cnt < -1)
578 IoIFP(io)->_cnt = -1;
580 if (op->op_flags & OPf_SPECIAL) { /* not necessarily a real EOF yet? */
581 if (!nextargv(argvgv)) /* get another fp handy */
585 return TRUE; /* normal fp, definitely end of file */
600 if (!io || !IoIFP(io))
603 #ifdef ULTRIX_STDIO_BOTCH
605 (void)fseek (IoIFP(io), 0L, 2); /* ultrix 1.2 workaround */
608 return ftell(IoIFP(io));
612 warn("tell() on unopened file");
618 do_seek(gv, pos, whence)
629 if (!io || !IoIFP(io))
632 #ifdef ULTRIX_STDIO_BOTCH
634 (void)fseek (IoIFP(io), 0L, 2); /* ultrix 1.2 workaround */
637 return fseek(IoIFP(io), pos, whence) >= 0;
641 warn("seek() on unopened file");
646 #if !defined(HAS_TRUNCATE) && !defined(HAS_CHSIZE) && defined(F_FREESP)
647 /* code courtesy of William Kucharski */
650 I32 chsize(fd, length)
651 I32 fd; /* file descriptor */
652 Off_t length; /* length to set file to */
658 if (Fstat(fd, &filebuf) < 0)
661 if (filebuf.st_size < length) {
663 /* extend file length */
665 if ((lseek(fd, (length - 1), 0)) < 0)
668 /* write a "0" byte */
670 if ((write(fd, "", 1)) != 1)
674 /* truncate length */
679 fl.l_type = F_WRLCK; /* write lock on file space */
682 * This relies on the UNDOCUMENTED F_FREESP argument to
683 * fcntl(2), which truncates the file so that it ends at the
684 * position indicated by fl.l_start.
686 * Will minor miracles never cease?
689 if (fcntl(fd, F_FREESP, &fl) < 0)
696 #endif /* F_FREESP */
699 looks_like_number(sv)
714 send = s + SvCUR(sv);
720 if (*s == '+' || *s == '-')
728 else if (s == SvPVX(sv))
734 if (*s == 'e' || *s == 'E') {
736 if (*s == '+' || *s == '-')
756 /* assuming fp is checked earlier */
762 if (SvIOK(sv) && SvIVX(sv) != 0) {
763 fprintf(fp, ofmt, (double)SvIVX(sv));
766 if ( (SvNOK(sv) && SvNVX(sv) != 0.0)
767 || (looks_like_number(sv) && sv_2nv(sv) != 0.0) ) {
768 fprintf(fp, ofmt, SvNVX(sv));
772 switch (SvTYPE(sv)) {
781 fprintf(fp, "%ld", (long)SvIVX(sv));
786 tmps = SvPV(sv, len);
789 if (len && (fwrite1(tmps,1,len,fp) == 0 || ferror(fp)))
801 if (op->op_flags & OPf_REF) {
803 io = GvIO(cGVOP->op_gv);
804 if (io && IoIFP(io)) {
805 statgv = cGVOP->op_gv;
806 sv_setpv(statname,"");
808 return (laststatval = Fstat(fileno(IoIFP(io)), &statcache));
811 if (cGVOP->op_gv == defgv)
814 warn("Stat on unopened file <%s>",
815 GvENAME(cGVOP->op_gv));
817 sv_setpv(statname,"");
818 return (laststatval = -1);
825 sv_setpv(statname,SvPV(sv, na));
827 laststatval = Stat(SvPV(sv, na),&statcache);
828 if (laststatval < 0 && dowarn && strchr(SvPV(sv, na), '\n'))
829 warn(warn_nl, "stat");
840 if (op->op_flags & OPf_REF) {
842 if (cGVOP->op_gv == defgv) {
843 if (laststype != OP_LSTAT)
844 croak("The stat preceding -l _ wasn't an lstat");
847 croak("You can't use -l on a filehandle");
850 laststype = OP_LSTAT;
854 sv_setpv(statname,SvPV(sv, na));
856 laststatval = lstat(SvPV(sv, na),&statcache);
858 laststatval = Stat(SvPV(sv, na),&statcache);
860 if (laststatval < 0 && dowarn && strchr(SvPV(sv, na), '\n'))
861 warn(warn_nl, "lstat");
866 do_aexec(really,mark,sp)
875 New(401,Argv, sp - mark + 1, char*);
877 while (++mark <= sp) {
879 *a++ = SvPVx(*mark, na);
884 if (*Argv[0] != '/') /* will execvp use PATH? */
885 TAINT_ENV(); /* testing IFS here is overkill, probably */
886 if (really && *(tmps = SvPV(really, na)))
889 execvp(Argv[0],Argv);
891 warn("Can't exec \"%s\": %s", Argv[0], Strerror(errno));
902 Argv = Null(char **);
918 /* save an extra exec if possible */
921 if (strnEQ(cmd,cshname,cshlen) && strnEQ(cmd+cshlen," -c",3)) {
939 execl(cshname,"csh", flags,ncmd,(char*)0);
947 /* see if there are shell metacharacters in it */
950 for (s = cmd; *s && isALPHA(*s); s++) ; /* catch VAR=val gizmo */
953 for (s = cmd; *s; s++) {
954 if (*s != ' ' && !isALPHA(*s) && strchr("$&*(){}[]'\";\\|?<>~`\n",*s)) {
955 if (*s == '\n' && !s[1]) {
960 execl("/bin/sh","sh","-c",cmd,(char*)0);
964 New(402,Argv, (s - cmd) / 2 + 2, char*);
965 Cmd = savepvn(cmd, s-cmd);
968 while (*s && isSPACE(*s)) s++;
971 while (*s && !isSPACE(*s)) s++;
977 execvp(Argv[0],Argv);
978 if (errno == ENOEXEC) { /* for system V NIH syndrome */
983 warn("Can't exec \"%s\": %s", Argv[0], Strerror(errno));
997 register I32 tot = 0;
1002 while (++mark <= sp) {
1003 if (SvMAGICAL(*mark) && mg_find(*mark, 't'))
1010 TAINT_PROPER("chmod");
1014 while (++mark <= sp) {
1015 if (chmod(SvPVx(*mark, na),val))
1022 TAINT_PROPER("chown");
1023 if (sp - mark > 2) {
1024 val = SvIVx(*++mark);
1025 val2 = SvIVx(*++mark);
1027 while (++mark <= sp) {
1028 if (chown(SvPVx(*mark, na),val,val2))
1036 TAINT_PROPER("kill");
1037 s = SvPVx(*++mark, na);
1040 if (*s == 'S' && s[1] == 'I' && s[2] == 'G')
1042 if (!(val = whichsig(s)))
1043 croak("Unrecognized signal name \"%s\"",s);
1049 while (++mark <= sp) {
1050 I32 proc = SvIVx(*mark);
1052 if (killpg(proc,val)) /* BSD */
1054 if (kill(-proc,val)) /* SYSV */
1060 while (++mark <= sp) {
1061 if (kill(SvIVx(*mark),val))
1068 TAINT_PROPER("unlink");
1070 while (++mark <= sp) {
1071 s = SvPVx(*mark, na);
1072 if (euid || unsafe) {
1076 else { /* don't let root wipe out directories without -U */
1078 if (lstat(s,&statbuf) < 0 || S_ISDIR(statbuf.st_mode))
1080 if (Stat(s,&statbuf) < 0 || S_ISDIR(statbuf.st_mode))
1092 TAINT_PROPER("utime");
1093 if (sp - mark > 2) {
1095 struct utimbuf utbuf;
1103 Zero(&utbuf, sizeof utbuf, char);
1104 utbuf.actime = SvIVx(*++mark); /* time accessed */
1105 utbuf.modtime = SvIVx(*++mark); /* time modified */
1107 while (++mark <= sp) {
1108 if (utime(SvPVx(*mark, na),&utbuf))
1120 /* Do the permissions allow some operation? Assumes statcache already set. */
1121 #ifndef VMS /* VMS' cando is in vms.c */
1123 cando(bit, effective, statbufp)
1126 register struct stat *statbufp;
1129 /* [Comments and code from Len Reed]
1130 * MS-DOS "user" is similar to UNIX's "superuser," but can't write
1131 * to write-protected files. The execute permission bit is set
1132 * by the Miscrosoft C library stat() function for the following:
1137 * All files and directories are readable.
1138 * Directories and special files, e.g. "CON", cannot be
1140 * [Comment by Tom Dinger -- a directory can have the write-protect
1141 * bit set in the file system, but DOS permits changes to
1142 * the directory anyway. In addition, all bets are off
1143 * here for networked software, such as Novell and
1147 /* Atari stat() does pretty much the same thing. we set x_bit_set_in_stat
1148 * too so it will actually look into the files for magic numbers
1150 return (bit & statbufp->st_mode) ? TRUE : FALSE;
1153 if ((effective ? euid : uid) == 0) { /* root is special */
1154 if (bit == S_IXUSR) {
1155 if (statbufp->st_mode & 0111 || S_ISDIR(statbufp->st_mode))
1159 return TRUE; /* root reads and writes anything */
1162 if (statbufp->st_uid == (effective ? euid : uid) ) {
1163 if (statbufp->st_mode & bit)
1164 return TRUE; /* ok as "user" */
1166 else if (ingroup((I32)statbufp->st_gid,effective)) {
1167 if (statbufp->st_mode & bit >> 3)
1168 return TRUE; /* ok as "group" */
1170 else if (statbufp->st_mode & bit >> 6)
1171 return TRUE; /* ok as "other" */
1173 #endif /* ! MSDOS */
1178 ingroup(testgid,effective)
1182 if (testgid == (effective ? egid : gid))
1184 #ifdef HAS_GETGROUPS
1189 Groups_t gary[NGROUPS];
1192 anum = getgroups(NGROUPS,gary);
1194 if (gary[anum] == testgid)
1201 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
1204 do_ipcget(optype, mark, sp)
1212 key = (key_t)SvNVx(*++mark);
1213 n = (optype == OP_MSGGET) ? 0 : SvIVx(*++mark);
1214 flags = SvIVx(*++mark);
1220 return msgget(key, flags);
1224 return semget(key, n, flags);
1228 return shmget(key, n, flags);
1230 #if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM)
1232 croak("%s not implemented", op_name[optype]);
1235 return -1; /* should never happen */
1239 do_ipcctl(optype, mark, sp)
1246 I32 id, n, cmd, infosize, getinfo;
1249 id = SvIVx(*++mark);
1250 n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0;
1251 cmd = SvIVx(*++mark);
1254 getinfo = (cmd == IPC_STAT);
1260 if (cmd == IPC_STAT || cmd == IPC_SET)
1261 infosize = sizeof(struct msqid_ds);
1266 if (cmd == IPC_STAT || cmd == IPC_SET)
1267 infosize = sizeof(struct shmid_ds);
1272 if (cmd == IPC_STAT || cmd == IPC_SET)
1273 infosize = sizeof(struct semid_ds);
1274 else if (cmd == GETALL || cmd == SETALL)
1276 struct semid_ds semds;
1277 if (semctl(id, 0, IPC_STAT, &semds) == -1)
1279 getinfo = (cmd == GETALL);
1280 infosize = semds.sem_nsems * sizeof(short);
1281 /* "short" is technically wrong but much more portable
1282 than guessing about u_?short(_t)? */
1286 #if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM)
1288 croak("%s not implemented", op_name[optype]);
1297 SvPV_force(astr, len);
1298 a = SvGROW(astr, infosize+1);
1302 a = SvPV(astr, len);
1303 if (len != infosize)
1304 croak("Bad arg length for %s, is %d, should be %d",
1305 op_name[optype], len, infosize);
1311 a = (char *)i; /* ouch */
1318 ret = msgctl(id, cmd, (struct msqid_ds *)a);
1323 ret = semctl(id, n, cmd, (struct semid_ds *)a);
1328 ret = shmctl(id, cmd, (struct shmid_ds *)a);
1332 if (getinfo && ret >= 0) {
1333 SvCUR_set(astr, infosize);
1334 *SvEND(astr) = '\0';
1348 I32 id, msize, flags;
1351 id = SvIVx(*++mark);
1353 flags = SvIVx(*++mark);
1354 mbuf = SvPV(mstr, len);
1355 if ((msize = len - sizeof(long)) < 0)
1356 croak("Arg too short for msgsnd");
1358 return msgsnd(id, (struct msgbuf *)mbuf, msize, flags);
1360 croak("msgsnd not implemented");
1373 I32 id, msize, flags, ret;
1376 id = SvIVx(*++mark);
1378 msize = SvIVx(*++mark);
1379 mtype = (long)SvIVx(*++mark);
1380 flags = SvIVx(*++mark);
1381 if (SvTHINKFIRST(mstr)) {
1382 if (SvREADONLY(mstr))
1383 croak("Can't msgrcv to readonly var");
1387 SvPV_force(mstr, len);
1388 mbuf = SvGROW(mstr, sizeof(long)+msize+1);
1391 ret = msgrcv(id, (struct msgbuf *)mbuf, msize, mtype, flags);
1393 SvCUR_set(mstr, sizeof(long)+ret);
1394 *SvEND(mstr) = '\0';
1398 croak("msgrcv not implemented");
1413 id = SvIVx(*++mark);
1415 opbuf = SvPV(opstr, opsize);
1416 if (opsize < sizeof(struct sembuf)
1417 || (opsize % sizeof(struct sembuf)) != 0) {
1422 return semop(id, (struct sembuf *)opbuf, opsize/sizeof(struct sembuf));
1424 croak("semop not implemented");
1429 do_shmio(optype, mark, sp)
1437 I32 id, mpos, msize;
1439 struct shmid_ds shmds;
1441 id = SvIVx(*++mark);
1443 mpos = SvIVx(*++mark);
1444 msize = SvIVx(*++mark);
1446 if (shmctl(id, IPC_STAT, &shmds) == -1)
1448 if (mpos < 0 || msize < 0 || mpos + msize > shmds.shm_segsz) {
1449 errno = EFAULT; /* can't do as caller requested */
1452 shm = (Shmat_t)shmat(id, (char*)NULL, (optype == OP_SHMREAD) ? SHM_RDONLY : 0);
1453 if (shm == (char *)-1) /* I hate System V IPC, I really do */
1455 if (optype == OP_SHMREAD) {
1456 SvPV_force(mstr, len);
1457 mbuf = SvGROW(mstr, msize+1);
1459 Copy(shm + mpos, mbuf, msize, char);
1460 SvCUR_set(mstr, msize);
1461 *SvEND(mstr) = '\0';
1467 mbuf = SvPV(mstr, len);
1468 if ((n = len) > msize)
1470 Copy(mbuf, shm + mpos, n, char);
1472 memzero(shm + mpos + n, msize - n);
1476 croak("shm I/O not implemented");
1480 #endif /* SYSV IPC */