#include "EXTERN.h"
#include "perl.h"
-/* Omit this -- it causes too much grief on mixed systems.
-#ifdef I_UNISTD
-#include <unistd.h>
-#endif
+/* XXX Omit this -- it causes too much grief on mixed systems.
+ Next time, I should force broken systems to unset i_unistd in
+ hint files.
*/
+#if 0
+# ifdef I_UNISTD
+# include <unistd.h>
+# endif
+#endif
/* Put this after #includes because fork and vfork prototypes may
conflict.
#include <sys/file.h>
#endif
-#ifdef HAS_GETPGRP2
-# define getpgrp getpgrp2
-#endif
-
-#ifdef HAS_SETPGRP2
-# define setpgrp setpgrp2
-#endif
-
#if !defined(HAS_MKDIR) || !defined(HAS_RMDIR)
static int dooneliner _((char *cmd, char *filename));
#endif
}
}
}
- statusvalue = my_pclose(fp);
+ statusvalue = FIXSTATUS(my_pclose(fp));
}
else {
statusvalue = -1;
{
OP *result;
ENTER;
- SAVEINT(rschar);
- SAVEINT(rslen);
SAVESPTR(last_in_gv); /* We don't want this to be permanent. */
last_in_gv = (GV*)*stack_sp--;
- rslen = 1;
-#ifdef DOSISH
- rschar = 0;
-#else
-#ifdef CSH
- rschar = 0;
-#else
- rschar = '\n';
+ SAVESPTR(rs); /* This is not permanent, either. */
+ rs = sv_2mortal(newSVpv("", 1));
+#ifndef DOSISH
+#ifndef CSH
+ *SvPVX(rs) = '\n';
#endif /* !CSH */
#endif /* !MSDOS */
+
result = do_readline();
LEAVE;
return result;
tmps = SvPV(TOPs, na);
}
if (!tmps || !*tmps) {
- SV *error = GvSV(gv_fetchpv("@", TRUE, SVt_PV));
+ SV *error = GvSV(errgv);
(void)SvUPGRADE(error, SVt_PV);
if (SvPOK(error) && SvCUR(error))
sv_catpv(error, "\t...caught");
tmps = SvPV(TOPs, na);
}
if (!tmps || !*tmps) {
- SV *error = GvSV(gv_fetchpv("@", TRUE, SVt_PV));
+ SV *error = GvSV(errgv);
(void)SvUPGRADE(error, SVt_PV);
if (SvPOK(error) && SvCUR(error))
sv_catpv(error, "\t...propagated");
if (MAXARG > 1)
sv = POPs;
- else
+ else if (SvTYPE(TOPs) == SVt_PVGV)
sv = GvSV(TOPs);
+ else
+ DIE(no_usym, "filehandle");
gv = (GV*)POPs;
tmps = SvPV(sv, len);
- if (do_open(gv, tmps, len,Nullfp)) {
+ if (do_open(gv, tmps, len, FALSE, 0, 0, Nullfp)) {
IoLINES(GvIOp(gv)) = 0;
PUSHi( (I32)forkprocess );
}
if (!rgv || !wgv)
goto badexit;
+ if (SvTYPE(rgv) != SVt_PVGV || SvTYPE(wgv) != SVt_PVGV)
+ DIE(no_usym, "filehandle");
rstio = GvIOn(rgv);
wstio = GvIOn(wgv);
#ifdef DOSISH
#ifdef atarist
- if (!fflush(fp) && (fp->_flag |= _IOBIN))
+ if (!Fflush(fp) && (fp->_flag |= _IOBIN))
RETPUSHYES;
else
RETPUSHUNDEF;
PUTBACK;
if (op = pp_entersub())
- run();
+ runops();
SPAGAIN;
sv = TOPs;
RETSETYES;
}
+PP(pp_tied)
+{
+ dSP;
+ SV * sv ;
+ MAGIC * mg ;
+
+ sv = POPs;
+ if (SvMAGICAL(sv)) {
+ if (SvTYPE(sv) == SVt_PVHV || SvTYPE(sv) == SVt_PVAV)
+ mg = mg_find(sv, 'P') ;
+ else
+ mg = mg_find(sv, 'q') ;
+
+ if (mg) {
+ PUSHs(sv_2mortal(newSVsv(mg->mg_obj))) ;
+ RETURN ;
+ }
+ }
+
+ RETPUSHUNDEF;
+}
+
PP(pp_dbmopen)
{
dSP;
stash = gv_stashsv(sv, FALSE);
if (!stash || !(gv = gv_fetchmethod(stash, "TIEHASH")) || !GvCV(gv)) {
PUTBACK;
- perl_requirepv("AnyDBM_File.pm");
+ perl_require_pv("AnyDBM_File.pm");
SPAGAIN;
if (!(gv = gv_fetchmethod(stash, "TIEHASH")) || !GvCV(gv))
DIE("No dbm on this machine");
PUTBACK;
if (op = pp_entersub())
- run();
+ runops();
SPAGAIN;
if (!sv_isobject(TOPs)) {
PUTBACK;
if (op = pp_entersub())
- run();
+ runops();
SPAGAIN;
}
}
#if BYTEORDER == 0x1234 || BYTEORDER == 0x12345678
+#ifdef __linux__
+ growsize = sizeof(fd_set);
+#else
growsize = maxlen; /* little endians can use vecs directly */
+#endif
#else
#ifdef NFDBITS
j = SvLEN(sv);
if (j < growsize) {
Sv_Grow(sv, growsize);
- s = SvPVX(sv) + j;
- while (++j <= growsize) {
- *s++ = '\0';
- }
}
+ j = SvCUR(sv);
+ s = SvPVX(sv) + j;
+ while (++j <= growsize) {
+ *s++ = '\0';
+ }
+
#if BYTEORDER != 0x1234 && BYTEORDER != 0x12345678
s = SvPVX(sv);
New(403, fd_sets[i], growsize, char);
#endif
}
+void
+setdefout(gv)
+GV *gv;
+{
+ if (gv)
+ (void)SvREFCNT_inc(gv);
+ if (defoutgv)
+ SvREFCNT_dec(defoutgv);
+ defoutgv = gv;
+}
+
PP(pp_select)
{
dSP; dTARGET;
- GV *oldgv = defoutgv;
- if (op->op_private > 0) {
- defoutgv = (GV*)POPs;
- if (!GvIO(defoutgv))
- gv_IOadd(defoutgv);
+ GV *newdefout, *egv;
+ HV *hv;
+
+ newdefout = (op->op_private > 0) ? ((GV *) POPs) : NULL;
+
+ egv = GvEGV(defoutgv);
+ if (!egv)
+ egv = defoutgv;
+ hv = GvSTASH(egv);
+ if (! hv)
+ XPUSHs(&sv_undef);
+ else {
+ GV **gvp = hv_fetch(hv, GvNAME(egv), GvNAMELEN(egv), FALSE);
+ if (gvp && *gvp == egv)
+ gv_efullname(TARG, defoutgv);
+ else
+ sv_setsv(TARG, sv_2mortal(newRV(egv)));
+ XPUSHTARG;
+ }
+
+ if (newdefout) {
+ if (!GvIO(newdefout))
+ gv_IOadd(newdefout);
+ setdefout(newdefout);
}
- gv_efullname(TARG, oldgv);
- XPUSHTARG;
+
RETURN;
}
SAVESPTR(curpad);
curpad = AvARRAY((AV*)svp[1]);
- defoutgv = gv; /* locally select filehandle so $% et al work */
+ setdefout(gv); /* locally select filehandle so $% et al work */
return CvSTART(cv);
}
if (IoLINES_LEFT(io) < FmLINES(formtarget) &&
formtarget != toptarget)
{
+ GV *fgv;
+ CV *cv;
if (!IoTOP_GV(io)) {
GV *topgv;
char tmpbuf[256];
if (IoFLAGS(io) & IOf_DIDTOP) { /* Oh dear. It still doesn't fit. */
I32 lines = IoLINES_LEFT(io);
char *s = SvPVX(formtarget);
+ if (lines <= 0) /* Yow, header didn't even fit!!! */
+ goto forget_top;
while (lines-- > 0) {
s = strchr(s, '\n');
if (!s)
IoPAGE(io)++;
formtarget = toptarget;
IoFLAGS(io) |= IOf_DIDTOP;
- return doform(GvFORM(IoTOP_GV(io)),gv,op);
+ fgv = IoTOP_GV(io);
+ if (!fgv)
+ DIE("bad top format reference");
+ cv = GvFORM(fgv);
+ if (!cv) {
+ SV *tmpsv = sv_newmortal();
+ gv_efullname(tmpsv, fgv);
+ DIE("Undefined top format \"%s\" called",SvPVX(tmpsv));
+ }
+ return doform(cv,gv,op);
}
forget_top:
SvCUR_set(formtarget, 0);
*SvEND(formtarget) = '\0';
if (IoFLAGS(io) & IOf_FLUSH)
- (void)fflush(fp);
+ (void)Fflush(fp);
PUSHs(&sv_yes);
}
}
goto just_say_no;
if (IoFLAGS(io) & IOf_FLUSH)
- if (fflush(fp) == EOF)
+ if (Fflush(fp) == EOF)
goto just_say_no;
}
SvREFCNT_dec(sv);
RETURN;
}
+PP(pp_sysopen)
+{
+ dSP;
+ GV *gv;
+ SV *sv;
+ char *tmps;
+ STRLEN len;
+ int mode, perm;
+
+ if (MAXARG > 3)
+ perm = POPi;
+ else
+ perm = 0666;
+ mode = POPi;
+ sv = POPs;
+ gv = (GV *)POPs;
+
+ tmps = SvPV(sv, len);
+ if (do_open(gv, tmps, len, TRUE, mode, perm, Nullfp)) {
+ IoLINES(GvIOp(gv)) = 0;
+ PUSHs(&sv_yes);
+ }
+ else {
+ PUSHs(&sv_undef);
+ }
+ RETURN;
+}
+
PP(pp_sysread)
{
dSP; dMARK; dORIGMARK; dTARGET;
DIE("ioctl is not implemented");
#endif
else
-#ifdef DOSISH
+#if defined(DOSISH) && !defined(OS2)
DIE("fcntl is not implemented");
#else
# ifdef HAS_FCNTL
+# if defined(OS2) && defined(__EMX__)
+ retval = fcntl(fileno(IoIFP(io)), func, (int)s);
+# else
retval = fcntl(fileno(IoIFP(io)), func, s);
+# endif
# else
DIE("fcntl is not implemented");
# endif
int argtype;
GV *gv;
FILE *fp;
-#ifdef HAS_FLOCK
+
+#if !defined(HAS_FLOCK) && defined(HAS_LOCKF)
+# define flock lockf_emulate_flock
+#endif
+
+#if defined(HAS_FLOCK) || defined(flock)
argtype = POPi;
if (MAXARG <= 0)
gv = last_in_gv;
PUSHi(value);
RETURN;
#else
-# ifdef HAS_LOCKF
- DIE(no_func, "flock()"); /* XXX emulate flock() with lockf()? */
-# else
DIE(no_func, "flock()");
-# endif
#endif
}
PP(pp_accept)
{
- struct sockaddr_in saddr; /* use a struct to avoid alignment problems */
dSP; dTARGET;
#ifdef HAS_SOCKET
GV *ngv;
GV *ggv;
register IO *nstio;
register IO *gstio;
+ struct sockaddr saddr; /* use a struct to avoid alignment problems */
int len = sizeof saddr;
int fd;
dSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHn( (basetime - statcache.st_mtime) / 86400.0 );
+ PUSHn( ((I32)basetime - (I32)statcache.st_mtime) / 86400.0 );
RETURN;
}
dSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHn( (basetime - statcache.st_atime) / 86400.0 );
+ PUSHn( ((I32)basetime - (I32)statcache.st_atime) / 86400.0 );
RETURN;
}
dSP; dTARGET;
if (result < 0)
RETPUSHUNDEF;
- PUSHn( (basetime - statcache.st_ctime) / 86400.0 );
+ PUSHn( ((I32)basetime - (I32)statcache.st_ctime) / 86400.0 );
RETURN;
}
RETPUSHNO;
}
-#if defined(USE_STD_STDIO) || defined(atarist) /* this will work with atariST */
-# define FBASE(f) ((f)->_base)
-# define FSIZE(f) ((f)->_cnt + ((f)->_ptr - (f)->_base))
-# define FPTR(f) ((f)->_ptr)
-# define FCOUNT(f) ((f)->_cnt)
-#else
-# if defined(USE_LINUX_STDIO)
-# define FBASE(f) ((f)->_IO_read_base)
-# define FSIZE(f) ((f)->_IO_read_end - FBASE(f))
-# define FPTR(f) ((f)->_IO_read_ptr)
-# define FCOUNT(f) ((f)->_IO_read_end - FPTR(f))
-# endif
+#if defined(atarist) /* this will work with atariST. Configure will
+ make guesses for other systems. */
+# define FILE_base(f) ((f)->_base)
+# define FILE_ptr(f) ((f)->_ptr)
+# define FILE_cnt(f) ((f)->_cnt)
+# define FILE_bufsiz(f) ((f)->_cnt + ((f)->_ptr - (f)->_base))
#endif
PP(pp_fttext)
io = GvIO(statgv);
}
if (io && IoIFP(io)) {
-#ifdef FBASE
+#ifdef FILE_base
Fstat(fileno(IoIFP(io)), &statcache);
if (S_ISDIR(statcache.st_mode)) /* handle NFS glitch */
if (op->op_type == OP_FTTEXT)
RETPUSHNO;
else
RETPUSHYES;
- if (FCOUNT(IoIFP(io)) <= 0) {
+ if (FILE_cnt(IoIFP(io)) <= 0) {
i = getc(IoIFP(io));
if (i != EOF)
(void)ungetc(i, IoIFP(io));
}
- if (FCOUNT(IoIFP(io)) <= 0) /* null file is anything */
+ if (FILE_cnt(IoIFP(io)) <= 0) /* null file is anything */
RETPUSHYES;
- len = FSIZE(IoIFP(io));
- s = FBASE(IoIFP(io));
+ len = FILE_bufsiz(IoIFP(io));
+ s = FILE_base(IoIFP(io));
#else
DIE("-T and -B not implemented on filehandles");
#endif
}
/* now scan s to look for textiness */
+ /* XXX ASCII dependent code */
for (i = 0; i < len; i++, s++) {
if (!*s) { /* null never allowed in text */
odd++;
}
- if ((odd * 30 > len) == (op->op_type == OP_FTTEXT)) /* allow 30% odd */
+ if ((odd * 3 > len) == (op->op_type == OP_FTTEXT)) /* allow 1/3 odd */
RETPUSHNO;
else
RETPUSHYES;
#ifdef VMS
/* Clear the DEFAULT element of ENV so we'll get the new value
* in the future. */
- hv_delete(GvHVn(envgv),"DEFAULT",7);
+ hv_delete(GvHVn(envgv),"DEFAULT",7,G_DISCARD);
#endif
RETURN;
}
char *filename;
{
char mybuf[8192];
- char *s,
+ char *s,
*save_filename = filename;
int anum = 1;
FILE *myfp;
Signal_t (*ihand)(); /* place to save signal during system() */
Signal_t (*qhand)(); /* place to save signal during system() */
-#if defined(HAS_FORK) && !defined(VMS)
+#if defined(HAS_FORK) && !defined(VMS) && !defined(OS2)
if (SP - MARK == 1) {
if (tainting) {
char *junk = SvPV(TOPs, na);
value = (I32)do_exec(SvPVx(sv_mortalcopy(*SP), na));
}
_exit(-1);
-#else /* ! FORK or VMS */
+#else /* ! FORK or VMS or OS/2 */
if (op->op_flags & OPf_STACKED) {
SV *really = *++MARK;
value = (I32)do_aspawn(really, MARK, SP);
else {
value = (I32)do_spawn(SvPVx(sv_mortalcopy(*SP), na));
}
+ statusvalue = FIXSTATUS(value);
do_execfree();
SP = ORIGMARK;
PUSHi(value);
pid = 0;
else
pid = SvIVx(POPs);
-#ifdef USE_BSDPGRP
- value = (I32)getpgrp(pid);
+#ifdef BSD_GETPGRP
+ value = (I32)BSD_GETPGRP(pid);
#else
if (pid != 0)
DIE("POSIX getpgrp can't take an argument");
}
TAINT_PROPER("setpgrp");
-#ifdef USE_BSDPGRP
- SETi( setpgrp(pid, pgrp) >= 0 );
+#ifdef BSD_SETPGRP
+ SETi( BSD_SETPGRP(pid, pgrp) >= 0 );
#else
if ((pgrp != 0) || (pid != 0)) {
DIE("POSIX setpgrp can't take an argument");
(void)times((tbuffer_t *)×buf); /* time.h uses different name for */
/* struct tms, though same data */
/* is returned. */
+#undef HZ
+#define HZ CLK_TCK
#endif
PUSHs(sv_2mortal(newSVnv(((double)timesbuf.tms_utime)/HZ)));
PUSHs(sv = sv_newmortal());
if (hent) {
if (which == OP_GHBYNAME) {
- sv_setpvn(sv, hent->h_addr, hent->h_length);
+ if (hent->h_addr)
+ sv_setpvn(sv, hent->h_addr, hent->h_length);
}
else
sv_setpv(sv, (char*)hent->h_name);
}
#else
PUSHs(sv = sv_mortalcopy(&sv_no));
- sv_setpvn(sv, hent->h_addr, len);
+ if (hent->h_addr)
+ sv_setpvn(sv, hent->h_addr, len);
#endif /* h_addr */
}
RETURN;
#endif
}
+#if !defined(HAS_FLOCK) && defined(HAS_LOCKF)
+
+/* XXX Emulate flock() with lockf(). This is just to increase
+ portability of scripts. The calls are not completely
+ interchangeable. What's really needed is a good file
+ locking module.
+*/
+
+/* We might need <unistd.h> because it sometimes defines the lockf()
+ constants. Unfortunately, <unistd.h> causes troubles on some mixed
+ (BSD/POSIX) systems, such as SunOS 4.1.3. We could just try including
+ <unistd.h> here in this part of the file, but that might
+ conflict with various other #defines and includes above, such as
+ #define vfork fork above.
+
+ Further, the lockf() constants aren't POSIX, so they might not be
+ visible if we're compiling with _POSIX_SOURCE defined. Thus, we'll
+ just stick in the SVID values and be done with it. Sigh.
+*/
+
+# ifndef F_ULOCK
+# define F_ULOCK 0 /* Unlock a previously locked region */
+# endif
+# ifndef F_LOCK
+# define F_LOCK 1 /* Lock a region for exclusive use */
+# endif
+# ifndef F_TLOCK
+# define F_TLOCK 2 /* Test and lock a region for exclusive use */
+# endif
+# ifndef F_TEST
+# define F_TEST 3 /* Test a region for other processes locks */
+# endif
+
+/* These are the flock() constants. Since this sytems doesn't have
+ flock(), the values of the constants are probably not available.
+*/
+# ifndef LOCK_SH
+# define LOCK_SH 1
+# endif
+# ifndef LOCK_EX
+# define LOCK_EX 2
+# endif
+# ifndef LOCK_NB
+# define LOCK_NB 4
+# endif
+# ifndef LOCK_UN
+# define LOCK_UN 8
+# endif
+
+int
+lockf_emulate_flock (fd, operation)
+int fd;
+int operation;
+{
+ int i;
+ switch (operation) {
+
+ /* LOCK_SH - get a shared lock */
+ case LOCK_SH:
+ /* LOCK_EX - get an exclusive lock */
+ case LOCK_EX:
+ i = lockf (fd, F_LOCK, 0);
+ break;
+
+ /* LOCK_SH|LOCK_NB - get a non-blocking shared lock */
+ case LOCK_SH|LOCK_NB:
+ /* LOCK_EX|LOCK_NB - get a non-blocking exclusive lock */
+ case LOCK_EX|LOCK_NB:
+ i = lockf (fd, F_TLOCK, 0);
+ if (i == -1)
+ if ((errno == EAGAIN) || (errno == EACCES))
+ errno = EWOULDBLOCK;
+ break;
+
+ /* LOCK_UN - unlock */
+ case LOCK_UN:
+ i = lockf (fd, F_ULOCK, 0);
+ break;
+
+ /* Default - can't decipher operation */
+ default:
+ i = -1;
+ errno = EINVAL;
+ break;
+ }
+ return (i);
+}
+#endif