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)))
175 while (isSPACE(*name))
177 if (strEQ(name,"-")) {
182 fp = fopen(name,mode);
190 while (isSPACE(*name))
194 if (strEQ(name,"-")) {
199 fp = fopen(name,mode);
201 else if (name[len-1] == '|') {
203 while (len && isSPACE(name[len-1]))
206 for (; isSPACE(*name); name++) ;
209 TAINT_PROPER("piped open");
210 fp = my_popen(name,"r");
216 for (; isSPACE(*name); name++) ;
217 if (strEQ(name,"-")) {
222 fp = fopen(name,"r");
226 if (dowarn && IoTYPE(io) == '<' && strchr(name, '\n'))
227 warn(warn_nl, "open");
231 IoTYPE(io) != '|' && IoTYPE(io) != '-') {
232 if (Fstat(fileno(fp),&statbuf) < 0) {
236 if (S_ISSOCK(statbuf.st_mode))
237 IoTYPE(io) = 's'; /* in case a socket was passed in to us */
241 !(statbuf.st_mode & S_IFMT)
246 int buflen = sizeof tokenbuf;
247 if (getsockname(fileno(fp), (struct sockaddr *)tokenbuf, &buflen) >= 0
248 || errno != ENOTSOCK)
249 IoTYPE(io) = 's'; /* some OS's return 0 on fstat()ed socket */
250 /* but some return 0 for streams too, sigh */
254 if (saveifp) { /* must use old fp? */
255 fd = fileno(saveifp);
257 fflush(saveofp); /* emulate fclose() */
258 if (saveofp != saveifp) { /* was a socket? */
264 if (fd != fileno(fp)) {
268 dup2(fileno(fp), fd);
269 sv = *av_fetch(fdpid,fileno(fp),TRUE);
270 (void)SvUPGRADE(sv, SVt_IV);
273 sv = *av_fetch(fdpid,fd,TRUE);
274 (void)SvUPGRADE(sv, SVt_IV);
282 #if defined(HAS_FCNTL) && defined(F_SETFD)
284 fcntl(fd,F_SETFD,fd > maxsysfd);
288 if (IoTYPE(io) == 's'
289 || (IoTYPE(io) == '>' && S_ISCHR(statbuf.st_mode)) ) {
290 if (!(IoOFP(io) = fdopen(fileno(fp),"w"))) {
304 IoTYPE(io) = savetype;
313 #ifndef FLEXFILENAMES
321 argvoutgv = gv_fetchpv("ARGVOUT",TRUE,SVt_PVIO);
322 if (filemode & (S_ISUID|S_ISGID)) {
323 fflush(IoIFP(GvIOn(argvoutgv))); /* chmod must follow last write */
325 (void)fchmod(lastfd,filemode);
327 (void)chmod(oldname,filemode);
331 while (av_len(GvAV(gv)) >= 0) {
333 sv = av_shift(GvAV(gv));
335 sv_setsv(GvSV(gv),sv);
336 SvSETMAGIC(GvSV(gv));
337 oldname = SvPVx(GvSV(gv), len);
338 if (do_open(gv,oldname,len,Nullfp)) {
340 TAINT_PROPER("inplace open");
341 if (strEQ(oldname,"-")) {
342 defoutgv = gv_fetchpv("STDOUT",TRUE,SVt_PVIO);
343 return IoIFP(GvIOp(gv));
345 #ifndef FLEXFILENAMES
346 filedev = statbuf.st_dev;
347 fileino = statbuf.st_ino;
349 filemode = statbuf.st_mode;
350 fileuid = statbuf.st_uid;
351 filegid = statbuf.st_gid;
352 if (!S_ISREG(filemode)) {
353 warn("Can't do inplace edit: %s is not a regular file",
360 add_suffix(sv,inplace);
362 sv_catpv(sv,inplace);
364 #ifndef FLEXFILENAMES
365 if (Stat(SvPVX(sv),&statbuf) >= 0
366 && statbuf.st_dev == filedev
367 && statbuf.st_ino == fileino ) {
368 warn("Can't do inplace edit: %s > 14 characters",
376 if (rename(oldname,SvPVX(sv)) < 0) {
377 warn("Can't rename %s to %s: %s, skipping file",
378 oldname, SvPVX(sv), Strerror(errno) );
384 (void)unlink(SvPVX(sv));
385 (void)rename(oldname,SvPVX(sv));
386 do_open(gv,SvPVX(sv),SvCUR(GvSV(gv)),Nullfp);
389 (void)UNLINK(SvPVX(sv));
390 if (link(oldname,SvPVX(sv)) < 0) {
391 warn("Can't rename %s to %s: %s, skipping file",
392 oldname, SvPVX(sv), Strerror(errno) );
396 (void)UNLINK(oldname);
401 if (UNLINK(oldname) < 0) {
402 warn("Can't rename %s to %s: %s, skipping file",
403 oldname, SvPVX(sv), Strerror(errno) );
408 croak("Can't do inplace edit without backup");
413 sv_catpv(sv,oldname);
414 errno = 0; /* in case sprintf set errno */
415 if (!do_open(argvoutgv,SvPVX(sv),SvCUR(sv),Nullfp)) {
416 warn("Can't do inplace edit on %s: %s",
417 oldname, Strerror(errno) );
421 defoutgv = argvoutgv;
422 lastfd = fileno(IoIFP(GvIOp(argvoutgv)));
423 (void)Fstat(lastfd,&statbuf);
425 (void)fchmod(lastfd,filemode);
427 (void)chmod(oldname,filemode);
429 if (fileuid != statbuf.st_uid || filegid != statbuf.st_gid) {
431 (void)fchown(lastfd,fileuid,filegid);
434 (void)chown(oldname,fileuid,filegid);
439 return IoIFP(GvIOp(gv));
442 fprintf(stderr,"Can't open %s: %s\n",SvPV(sv, na), Strerror(errno));
445 (void)do_close(argvoutgv,FALSE);
446 defoutgv = gv_fetchpv("STDOUT",TRUE,SVt_PVIO);
453 do_pipe(sv, rgv, wgv)
477 IoIFP(rstio) = fdopen(fd[0], "r");
478 IoOFP(wstio) = fdopen(fd[1], "w");
479 IoIFP(wstio) = IoOFP(wstio);
482 if (!IoIFP(rstio) || !IoOFP(wstio)) {
483 if (IoIFP(rstio)) fclose(IoIFP(rstio));
485 if (IoOFP(wstio)) fclose(IoOFP(wstio));
490 sv_setsv(sv,&sv_yes);
494 sv_setsv(sv,&sv_undef);
500 #ifndef CAN_PROTOTYPE
501 do_close(gv,explicit)
505 do_close(GV *gv, bool explicit)
506 #endif /* CAN_PROTOTYPE */
514 if (!gv || SvTYPE(gv) != SVt_PVGV) {
519 if (!io) { /* never opened */
520 if (dowarn && explicit)
521 warn("Close on unopened file <%s>",GvENAME(gv));
525 if (IoTYPE(io) == '|') {
526 status = my_pclose(IoIFP(io));
527 retval = (status == 0);
528 statusvalue = (unsigned short)status & 0xffff;
530 else if (IoTYPE(io) == '-')
533 if (IoOFP(io) && IoOFP(io) != IoIFP(io)) { /* a socket */
534 retval = (fclose(IoOFP(io)) != EOF);
535 fclose(IoIFP(io)); /* clear stdio, fd already closed */
538 retval = (fclose(IoIFP(io)) != EOF);
540 IoOFP(io) = IoIFP(io) = Nullfp;
545 IoLINES_LEFT(io) = IoPAGE_LEN(io);
565 #ifdef USE_STD_STDIO /* (the code works without this) */
566 if (IoIFP(io)->_cnt > 0) /* cheat a little, since */
567 return FALSE; /* this is the most usual case */
570 ch = getc(IoIFP(io));
572 (void)ungetc(ch, IoIFP(io));
576 if (IoIFP(io)->_cnt < -1)
577 IoIFP(io)->_cnt = -1;
579 if (op->op_flags & OPf_SPECIAL) { /* not necessarily a real EOF yet? */
580 if (!nextargv(argvgv)) /* get another fp handy */
584 return TRUE; /* normal fp, definitely end of file */
599 if (!io || !IoIFP(io))
602 #ifdef ULTRIX_STDIO_BOTCH
604 (void)fseek (IoIFP(io), 0L, 2); /* ultrix 1.2 workaround */
607 return ftell(IoIFP(io));
611 warn("tell() on unopened file");
617 do_seek(gv, pos, whence)
628 if (!io || !IoIFP(io))
631 #ifdef ULTRIX_STDIO_BOTCH
633 (void)fseek (IoIFP(io), 0L, 2); /* ultrix 1.2 workaround */
636 return fseek(IoIFP(io), pos, whence) >= 0;
640 warn("seek() on unopened file");
645 #if !defined(HAS_TRUNCATE) && !defined(HAS_CHSIZE) && defined(F_FREESP)
646 /* code courtesy of William Kucharski */
649 I32 chsize(fd, length)
650 I32 fd; /* file descriptor */
651 Off_t length; /* length to set file to */
657 if (Fstat(fd, &filebuf) < 0)
660 if (filebuf.st_size < length) {
662 /* extend file length */
664 if ((lseek(fd, (length - 1), 0)) < 0)
667 /* write a "0" byte */
669 if ((write(fd, "", 1)) != 1)
673 /* truncate length */
678 fl.l_type = F_WRLCK; /* write lock on file space */
681 * This relies on the UNDOCUMENTED F_FREESP argument to
682 * fcntl(2), which truncates the file so that it ends at the
683 * position indicated by fl.l_start.
685 * Will minor miracles never cease?
688 if (fcntl(fd, F_FREESP, &fl) < 0)
695 #endif /* F_FREESP */
698 looks_like_number(sv)
713 send = s + SvCUR(sv);
719 if (*s == '+' || *s == '-')
727 else if (s == SvPVX(sv))
733 if (*s == 'e' || *s == 'E') {
735 if (*s == '+' || *s == '-')
755 /* assuming fp is checked earlier */
761 if (SvIOK(sv) && SvIVX(sv) != 0) {
762 fprintf(fp, ofmt, (double)SvIVX(sv));
765 if ( (SvNOK(sv) && SvNVX(sv) != 0.0)
766 || (looks_like_number(sv) && sv_2nv(sv) != 0.0) ) {
767 fprintf(fp, ofmt, SvNVX(sv));
771 switch (SvTYPE(sv)) {
780 fprintf(fp, "%ld", (long)SvIVX(sv));
785 tmps = SvPV(sv, len);
788 if (len && (fwrite1(tmps,1,len,fp) == 0 || ferror(fp)))
800 if (op->op_flags & OPf_REF) {
802 io = GvIO(cGVOP->op_gv);
803 if (io && IoIFP(io)) {
804 statgv = cGVOP->op_gv;
805 sv_setpv(statname,"");
807 return (laststatval = Fstat(fileno(IoIFP(io)), &statcache));
810 if (cGVOP->op_gv == defgv)
813 warn("Stat on unopened file <%s>",
814 GvENAME(cGVOP->op_gv));
816 sv_setpv(statname,"");
817 return (laststatval = -1);
824 sv_setpv(statname,SvPV(sv, na));
826 laststatval = Stat(SvPV(sv, na),&statcache);
827 if (laststatval < 0 && dowarn && strchr(SvPV(sv, na), '\n'))
828 warn(warn_nl, "stat");
839 if (op->op_flags & OPf_REF) {
841 if (cGVOP->op_gv == defgv) {
842 if (laststype != OP_LSTAT)
843 croak("The stat preceding -l _ wasn't an lstat");
846 croak("You can't use -l on a filehandle");
849 laststype = OP_LSTAT;
853 sv_setpv(statname,SvPV(sv, na));
855 laststatval = lstat(SvPV(sv, na),&statcache);
857 laststatval = Stat(SvPV(sv, na),&statcache);
859 if (laststatval < 0 && dowarn && strchr(SvPV(sv, na), '\n'))
860 warn(warn_nl, "lstat");
865 do_aexec(really,mark,sp)
874 New(401,Argv, sp - mark + 1, char*);
876 while (++mark <= sp) {
878 *a++ = SvPVx(*mark, na);
883 if (*Argv[0] != '/') /* will execvp use PATH? */
884 TAINT_ENV(); /* testing IFS here is overkill, probably */
885 if (really && *(tmps = SvPV(really, na)))
888 execvp(Argv[0],Argv);
890 warn("Can't exec \"%s\": %s", Argv[0], Strerror(errno));
901 Argv = Null(char **);
917 /* save an extra exec if possible */
920 if (strnEQ(cmd,cshname,cshlen) && strnEQ(cmd+cshlen," -c",3)) {
938 execl(cshname,"csh", flags,ncmd,(char*)0);
946 /* see if there are shell metacharacters in it */
949 for (s = cmd; *s && isALPHA(*s); s++) ; /* catch VAR=val gizmo */
952 for (s = cmd; *s; s++) {
953 if (*s != ' ' && !isALPHA(*s) && strchr("$&*(){}[]'\";\\|?<>~`\n",*s)) {
954 if (*s == '\n' && !s[1]) {
959 execl("/bin/sh","sh","-c",cmd,(char*)0);
963 New(402,Argv, (s - cmd) / 2 + 2, char*);
964 Cmd = savepvn(cmd, s-cmd);
967 while (*s && isSPACE(*s)) s++;
970 while (*s && !isSPACE(*s)) s++;
976 execvp(Argv[0],Argv);
977 if (errno == ENOEXEC) { /* for system V NIH syndrome */
982 warn("Can't exec \"%s\": %s", Argv[0], Strerror(errno));
996 register I32 tot = 0;
1001 while (++mark <= sp) {
1002 if (SvMAGICAL(*mark) && mg_find(*mark, 't'))
1009 TAINT_PROPER("chmod");
1013 while (++mark <= sp) {
1014 if (chmod(SvPVx(*mark, na),val))
1021 TAINT_PROPER("chown");
1022 if (sp - mark > 2) {
1023 val = SvIVx(*++mark);
1024 val2 = SvIVx(*++mark);
1026 while (++mark <= sp) {
1027 if (chown(SvPVx(*mark, na),val,val2))
1035 TAINT_PROPER("kill");
1036 s = SvPVx(*++mark, na);
1039 if (*s == 'S' && s[1] == 'I' && s[2] == 'G')
1041 if (!(val = whichsig(s)))
1042 croak("Unrecognized signal name \"%s\"",s);
1048 while (++mark <= sp) {
1049 I32 proc = SvIVx(*mark);
1051 if (killpg(proc,val)) /* BSD */
1053 if (kill(-proc,val)) /* SYSV */
1059 while (++mark <= sp) {
1060 if (kill(SvIVx(*mark),val))
1067 TAINT_PROPER("unlink");
1069 while (++mark <= sp) {
1070 s = SvPVx(*mark, na);
1071 if (euid || unsafe) {
1075 else { /* don't let root wipe out directories without -U */
1077 if (lstat(s,&statbuf) < 0 || S_ISDIR(statbuf.st_mode))
1079 if (Stat(s,&statbuf) < 0 || S_ISDIR(statbuf.st_mode))
1091 TAINT_PROPER("utime");
1092 if (sp - mark > 2) {
1094 struct utimbuf utbuf;
1102 Zero(&utbuf, sizeof utbuf, char);
1103 utbuf.actime = SvIVx(*++mark); /* time accessed */
1104 utbuf.modtime = SvIVx(*++mark); /* time modified */
1106 while (++mark <= sp) {
1107 if (utime(SvPVx(*mark, na),&utbuf))
1119 /* Do the permissions allow some operation? Assumes statcache already set. */
1120 #ifndef VMS /* VMS' cando is in vms.c */
1122 cando(bit, effective, statbufp)
1125 register struct stat *statbufp;
1128 /* [Comments and code from Len Reed]
1129 * MS-DOS "user" is similar to UNIX's "superuser," but can't write
1130 * to write-protected files. The execute permission bit is set
1131 * by the Miscrosoft C library stat() function for the following:
1136 * All files and directories are readable.
1137 * Directories and special files, e.g. "CON", cannot be
1139 * [Comment by Tom Dinger -- a directory can have the write-protect
1140 * bit set in the file system, but DOS permits changes to
1141 * the directory anyway. In addition, all bets are off
1142 * here for networked software, such as Novell and
1146 /* Atari stat() does pretty much the same thing. we set x_bit_set_in_stat
1147 * too so it will actually look into the files for magic numbers
1149 return (bit & statbufp->st_mode) ? TRUE : FALSE;
1152 if ((effective ? euid : uid) == 0) { /* root is special */
1153 if (bit == S_IXUSR) {
1154 if (statbufp->st_mode & 0111 || S_ISDIR(statbufp->st_mode))
1158 return TRUE; /* root reads and writes anything */
1161 if (statbufp->st_uid == (effective ? euid : uid) ) {
1162 if (statbufp->st_mode & bit)
1163 return TRUE; /* ok as "user" */
1165 else if (ingroup((I32)statbufp->st_gid,effective)) {
1166 if (statbufp->st_mode & bit >> 3)
1167 return TRUE; /* ok as "group" */
1169 else if (statbufp->st_mode & bit >> 6)
1170 return TRUE; /* ok as "other" */
1172 #endif /* ! MSDOS */
1177 ingroup(testgid,effective)
1181 if (testgid == (effective ? egid : gid))
1183 #ifdef HAS_GETGROUPS
1188 Groups_t gary[NGROUPS];
1191 anum = getgroups(NGROUPS,gary);
1193 if (gary[anum] == testgid)
1200 #if defined(HAS_MSG) || defined(HAS_SEM) || defined(HAS_SHM)
1203 do_ipcget(optype, mark, sp)
1211 key = (key_t)SvNVx(*++mark);
1212 n = (optype == OP_MSGGET) ? 0 : SvIVx(*++mark);
1213 flags = SvIVx(*++mark);
1219 return msgget(key, flags);
1223 return semget(key, n, flags);
1227 return shmget(key, n, flags);
1229 #if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM)
1231 croak("%s not implemented", op_name[optype]);
1234 return -1; /* should never happen */
1238 do_ipcctl(optype, mark, sp)
1245 I32 id, n, cmd, infosize, getinfo;
1248 id = SvIVx(*++mark);
1249 n = (optype == OP_SEMCTL) ? SvIVx(*++mark) : 0;
1250 cmd = SvIVx(*++mark);
1253 getinfo = (cmd == IPC_STAT);
1259 if (cmd == IPC_STAT || cmd == IPC_SET)
1260 infosize = sizeof(struct msqid_ds);
1265 if (cmd == IPC_STAT || cmd == IPC_SET)
1266 infosize = sizeof(struct shmid_ds);
1271 if (cmd == IPC_STAT || cmd == IPC_SET)
1272 infosize = sizeof(struct semid_ds);
1273 else if (cmd == GETALL || cmd == SETALL)
1275 struct semid_ds semds;
1276 if (semctl(id, 0, IPC_STAT, &semds) == -1)
1278 getinfo = (cmd == GETALL);
1279 infosize = semds.sem_nsems * sizeof(short);
1280 /* "short" is technically wrong but much more portable
1281 than guessing about u_?short(_t)? */
1285 #if !defined(HAS_MSG) || !defined(HAS_SEM) || !defined(HAS_SHM)
1287 croak("%s not implemented", op_name[optype]);
1296 SvPV_force(astr, len);
1297 a = SvGROW(astr, infosize+1);
1301 a = SvPV(astr, len);
1302 if (len != infosize)
1303 croak("Bad arg length for %s, is %d, should be %d",
1304 op_name[optype], len, infosize);
1310 a = (char *)i; /* ouch */
1317 ret = msgctl(id, cmd, (struct msqid_ds *)a);
1322 ret = semctl(id, n, cmd, (struct semid_ds *)a);
1327 ret = shmctl(id, cmd, (struct shmid_ds *)a);
1331 if (getinfo && ret >= 0) {
1332 SvCUR_set(astr, infosize);
1333 *SvEND(astr) = '\0';
1347 I32 id, msize, flags;
1350 id = SvIVx(*++mark);
1352 flags = SvIVx(*++mark);
1353 mbuf = SvPV(mstr, len);
1354 if ((msize = len - sizeof(long)) < 0)
1355 croak("Arg too short for msgsnd");
1357 return msgsnd(id, (struct msgbuf *)mbuf, msize, flags);
1359 croak("msgsnd not implemented");
1372 I32 id, msize, flags, ret;
1375 id = SvIVx(*++mark);
1377 msize = SvIVx(*++mark);
1378 mtype = (long)SvIVx(*++mark);
1379 flags = SvIVx(*++mark);
1380 if (SvTHINKFIRST(mstr)) {
1381 if (SvREADONLY(mstr))
1382 croak("Can't msgrcv to readonly var");
1386 SvPV_force(mstr, len);
1387 mbuf = SvGROW(mstr, sizeof(long)+msize+1);
1390 ret = msgrcv(id, (struct msgbuf *)mbuf, msize, mtype, flags);
1392 SvCUR_set(mstr, sizeof(long)+ret);
1393 *SvEND(mstr) = '\0';
1397 croak("msgrcv not implemented");
1412 id = SvIVx(*++mark);
1414 opbuf = SvPV(opstr, opsize);
1415 if (opsize < sizeof(struct sembuf)
1416 || (opsize % sizeof(struct sembuf)) != 0) {
1421 return semop(id, (struct sembuf *)opbuf, opsize/sizeof(struct sembuf));
1423 croak("semop not implemented");
1428 do_shmio(optype, mark, sp)
1436 I32 id, mpos, msize;
1438 struct shmid_ds shmds;
1440 id = SvIVx(*++mark);
1442 mpos = SvIVx(*++mark);
1443 msize = SvIVx(*++mark);
1445 if (shmctl(id, IPC_STAT, &shmds) == -1)
1447 if (mpos < 0 || msize < 0 || mpos + msize > shmds.shm_segsz) {
1448 errno = EFAULT; /* can't do as caller requested */
1451 shm = (Shmat_t)shmat(id, (char*)NULL, (optype == OP_SHMREAD) ? SHM_RDONLY : 0);
1452 if (shm == (char *)-1) /* I hate System V IPC, I really do */
1454 if (optype == OP_SHMREAD) {
1455 SvPV_force(mstr, len);
1456 mbuf = SvGROW(mstr, msize+1);
1458 Copy(shm + mpos, mbuf, msize, char);
1459 SvCUR_set(mstr, msize);
1460 *SvEND(mstr) = '\0';
1466 mbuf = SvPV(mstr, len);
1467 if ((n = len) > msize)
1469 Copy(mbuf, shm + mpos, n, char);
1471 memzero(shm + mpos + n, msize - n);
1475 croak("shm I/O not implemented");
1479 #endif /* SYSV IPC */