summaryrefslogtreecommitdiff
path: root/pp_sys.c
diff options
context:
space:
mode:
authorPerl 5 Porters <perl5-porters@africa.nicoh.com>1996-11-30 05:31:00 +1200
committerChip Salzenberg <chip@atlantic.net>1996-11-30 05:31:00 +1200
commitff68c7194e176ca1907544a3a65684b76834d0fe (patch)
tree4124d603a6b2a937f4ce1d9469426f84421f93e0 /pp_sys.c
parenteff9c6e2f5bda63e4dc69fc15e237a9843954369 (diff)
downloadperl-ff68c7194e176ca1907544a3a65684b76834d0fe.tar.gz
[inseparable changes from patch from perl5.003_09 to perl5.003_10]
CORE LANGUAGE CHANGES Subject: Allow &{sub {...}} without warning From: Chip Salzenberg <chip@atlantic.net> Files: toke.c Subject: Make parens optional on [gs]ethost and [gs]et{pw,gr} function From: Chip Salzenberg <chip@atlantic.net> Files: toke.c Subject: Fix syntax error with "$x [0]" and "$x {y}" and "@x {y}" From: Chip Salzenberg <chip@atlantic.net> Files: toke.c DOCUMENTATION Subject: Improve documentation for sysread() and syswrite() From: Chip Salzenberg <chip@atlantic.net> Files: pod/perlfunc.pod Subject: Document how to use $SIG{ALRM} and alarm() Date: Tue, 26 Nov 1996 11:42:49 -0500 From: Roderick Schertler <roderick@ibcinc.com> Files: pod/perlfunc.pod Msg-ID: <5898.849026569@eeyore.ibcinc.com> (applied based on p5p patch as commit 5fa5e7dfc2abaaadd377c97cd1ebe78ea844da88) OTHER CORE CHANGES Subject: Hash key memory corruption fix and naming cleanup From: Chip Salzenberg <chip@atlantic.net> Files: hv.c hv.h perl.h Subject: Undo broken perf. patch (PADTMP stealing) From: Chip Salzenberg <chip@atlantic.net> Files: sv.c Subject: Make SV unstudied in sv_gets() From: Chip Salzenberg <chip@atlantic.net> Files: sv.c Subject: Better support for UVs From: Paul Marquess <pmarquess@bfsec.bt.co.uk> Files: global.sym old_global.sym perl.h pp.c pp.h proto.h sv.c sv.h Subject: Minor locale cleanups From: Chip Salzenberg <chip@atlantic.net> Files: t/lib/posix.t util.c Accept "POSIX" locale as standard like "C". Reset locale to 'C' when testing strtod() in t/lib/posix.t. Subject: Always taint result of sprintf() on float From: Chip Salzenberg <chip@atlantic.net> Files: doop.c Subject: Fix spurious warning from bitwise string ops From: Chip Salzenberg <chip@atlantic.net> Files: doop.c Subject: Eliminate warning on {,sys}read(,$newvar,) From: Chip Salzenberg <chip@atlantic.net> Files: doop.c pp_sys.c Subject: Namespace cleanup From: Chip Salzenberg <chip@atlantic.net> Files: global.sym old_global.sym perl.h Subject: Modify perl_exp.SH; create old_perl_exp.SH; document old_* From: Chip Salzenberg <chip@atlantic.net> Files: Configure INSTALL MANIFEST old_perl_exp.SH perl_exp.SH PORTABILITY Subject: Reliable signal patch Date: Tue, 26 Nov 1996 05:40:50 -0500 (EST) From: Kenneth Albanowski <kjahds@kjahds.com> Files: global.sym mg.c old_global.sym perl.h pp_sys.c proto.h util.c Msg-ID: <Pine.LNX.3.93.961126053209.294J-100000@kjahds.com> (applied based on p5p patch as commit 679728958e74b0ccd6d61567d84851f1ef994e1f) Subject: Emulate missing flock() with either fcntl() or lockf() From: Chip Salzenberg <chip@atlantic.net> Files: pp_sys.c Subject: 3_09: minor patches for OS/2 Date: Wed, 27 Nov 1996 03:30:05 -0500 (EST) From: Ilya Zakharevich <ilya@math.ohio-state.edu> Files: doio.c global.sym malloc.c old_global.sym os2/Makefile.SHs os2/OS2/ExtAttr/Makefile.PL os2/OS2/PrfDB/Makefile.PL os2/OS2/Process/Makefile.PL os2/OS2/REXX/Makefile.PL os2/os2.c os2/os2ish.h perl.h Subject: 3_09: minor patches This patches mostly enable commpilation under OS/2, and fix malloc.c. Enjoy, p5p-msgid: <199611270830.DAA04985@monk.mps.ohio-state.edu> Subject: Re: 5.003_09 and QNX Date: Wed, 27 Nov 96 13:36:06 est From: Norton Allen <nort@bottesini.harvard.edu> Files: Configure MANIFEST README.qnx hints/qnx.sh qnx/ar qnx/cpp t/TEST toke.c util.c x2p/proto.h Msg-ID: <9611271836.AA14460@bottesini.harvard.edu> (applied based on p5p patch as commit c5117498be098729dc2af28089bd130c88c8d42b)
Diffstat (limited to 'pp_sys.c')
-rw-r--r--pp_sys.c116
1 files changed, 85 insertions, 31 deletions
diff --git a/pp_sys.c b/pp_sys.c
index d580fba438..8af00722c8 100644
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -98,10 +98,42 @@ static int dooneliner _((char *cmd, char *filename));
# define my_chsize chsize
#endif
-#if !defined(HAS_FLOCK) && defined(HAS_LOCKF)
- static int lockf_emulate_flock _((int fd, int operation));
-# define flock lockf_emulate_flock
-#endif
+#ifdef HAS_FLOCK
+# define FLOCK flock
+#else /* no flock() */
+
+# if defined(HAS_FCNTL) && defined(F_SETLK) && defined (F_SETLKW)
+# define FLOCK fcntl_emulate_flock
+# define FCNTL_EMULATE_FLOCK
+# else /* no flock() or fcntl(F_SETLK,...) */
+# ifdef HAS_LOCKF
+# define FLOCK lockf_emulate_flock
+# define LOCKF_EMULATE_FLOCK
+# endif /* lockf */
+# endif /* no flock() or fcntl(F_SETLK,...) */
+
+# ifdef FLOCK
+ static int FLOCK(int, int);
+
+ /*
+ * 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
+# endif /* emulating flock() */
+
+#endif /* no flock() */
/* Pushy I/O. */
@@ -1077,6 +1109,8 @@ PP(pp_sysread)
if (!gv)
goto say_undef;
bufsv = *++MARK;
+ if (! SvOK(bufsv))
+ sv_setpvn(bufsv, "", 0);
buffer = SvPV_force(bufsv, blen);
length = SvIVx(*++MARK);
if (length < 0)
@@ -1418,7 +1452,7 @@ PP(pp_flock)
GV *gv;
PerlIO *fp;
-#if defined(HAS_FLOCK) || defined(flock)
+#ifdef FLOCK
argtype = POPi;
if (MAXARG <= 0)
gv = last_in_gv;
@@ -1429,7 +1463,7 @@ PP(pp_flock)
else
fp = Nullfp;
if (fp) {
- value = (I32)(flock(PerlIO_fileno(fp), argtype) >= 0);
+ value = (I32)(FLOCK(PerlIO_fileno(fp), argtype) >= 0);
}
else
value = 0;
@@ -2856,8 +2890,7 @@ PP(pp_system)
int childpid;
int result;
int status;
- Signal_t (*ihand)(); /* place to save signal during system() */
- Signal_t (*qhand)(); /* place to save signal during system() */
+ Sigsave_t ihand,qhand; /* place to save signals during system() */
#if (defined(HAS_FORK) || defined(AMIGAOS)) && !defined(VMS) && !defined(OS2)
if (SP - MARK == 1) {
@@ -2877,13 +2910,13 @@ PP(pp_system)
sleep(5);
}
if (childpid > 0) {
- ihand = signal(SIGINT, SIG_IGN);
- qhand = signal(SIGQUIT, SIG_IGN);
+ rsignal_save(SIGINT, SIG_IGN, &ihand);
+ rsignal_save(SIGQUIT, SIG_IGN, &qhand);
do {
result = wait4pid(childpid, &status, 0);
} while (result == -1 && errno == EINTR);
- (void)signal(SIGINT, ihand);
- (void)signal(SIGQUIT, qhand);
+ (void)rsignal_restore(SIGINT, &ihand);
+ (void)rsignal_restore(SIGQUIT, &qhand);
statusvalue = FIXSTATUS(status);
if (result < 0)
value = -1;
@@ -4079,7 +4112,42 @@ PP(pp_syscall)
#endif
}
-#if !defined(HAS_FLOCK) && defined(HAS_LOCKF)
+#ifdef FCNTL_EMULATE_FLOCK
+
+/* XXX Emulate flock() with fcntl().
+ What's really needed is a good file locking module.
+*/
+
+static int
+fcntl_emulate_flock(fd, operation)
+int fd;
+int operation;
+{
+ struct flock flock;
+
+ switch (operation & ~LOCK_NB) {
+ case LOCK_SH:
+ flock.l_type = F_RDLCK;
+ break;
+ case LOCK_EX:
+ flock.l_type = F_WRLCK;
+ break;
+ case LOCK_UN:
+ flock.l_type = F_UNLCK;
+ break;
+ default:
+ errno = EINVAL;
+ return -1;
+ }
+ flock.l_whence = SEEK_SET;
+ flock.l_start = flock.l_len = 0L;
+
+ return fcntl(fd, (operation & LOCK_NB) ? F_SETLK : F_SETLKW, &flock);
+}
+
+#endif /* FCNTL_EMULATE_FLOCK */
+
+#ifdef LOCKF_EMULATE_FLOCK
/* XXX Emulate flock() with lockf(). This is just to increase
portability of scripts. The calls are not completely
@@ -4109,22 +4177,6 @@ PP(pp_syscall)
# 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
-
static int
lockf_emulate_flock (fd, operation)
int fd;
@@ -4150,8 +4202,9 @@ int operation;
errno = EWOULDBLOCK;
break;
- /* LOCK_UN - unlock */
+ /* LOCK_UN - unlock (non-blocking is a no-op) */
case LOCK_UN:
+ case LOCK_UN|LOCK_NB:
i = lockf (fd, F_ULOCK, 0);
break;
@@ -4163,4 +4216,5 @@ int operation;
}
return (i);
}
-#endif
+
+#endif /* LOCKF_EMULATE_FLOCK */