util.c revision 1
/* util.c
*
* Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999,
* 2000, 2001, 2002, 2003, 2004, by Larry Wall and others
*
* You may distribute under the terms of either the GNU General Public
* License or the Artistic License, as specified in the README file.
*
*/
/*
* "Very useful, no doubt, that was to Saruman; yet it seems that he was
* not content." --Gandalf
*/
#include "EXTERN.h"
#define PERL_IN_UTIL_C
#include "perl.h"
#ifndef PERL_MICRO
#include <signal.h>
#ifndef SIG_ERR
#endif
#endif
#ifdef I_SYS_WAIT
#endif
#ifdef HAS_SELECT
# ifdef I_SYS_SELECT
# endif
#endif
#define FLUSH
#endif
/* NOTE: Do not call the next three routines directly. Use the macros
* in handy.h, so that we can easily redefine everything to do tracking of
* allocated hunks back to the original New to track down any memory leaks.
* XXX This advice seems to be widely ignored :-( --AD August 1996.
*/
/* paranoid version of system's malloc() */
{
dTHX;
#ifdef HAS_64K_LIMIT
if (size > 0xffff) {
my_exit(1);
}
#endif /* HAS_64K_LIMIT */
#ifdef DEBUGGING
if ((long)size < 0)
Perl_croak_nocontext("panic: malloc");
#endif
DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) malloc %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)size));
return ptr;
else if (PL_nomemok)
return Nullch;
else {
/* Can't use PerlIO to write as it allocates memory */
my_exit(1);
return Nullch;
}
/*NOTREACHED*/
}
/* paranoid version of system's realloc() */
{
dTHX;
#endif /* !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE) */
#ifdef HAS_64K_LIMIT
if (size > 0xffff) {
my_exit(1);
}
#endif /* HAS_64K_LIMIT */
if (!size) {
return NULL;
}
if (!where)
return safesysmalloc(size);
#ifdef DEBUGGING
if ((long)size < 0)
Perl_croak_nocontext("panic: realloc");
#endif
DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) realloc %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)size));
return ptr;
else if (PL_nomemok)
return Nullch;
else {
/* Can't use PerlIO to write as it allocates memory */
my_exit(1);
return Nullch;
}
/*NOTREACHED*/
}
/* safe version of system's free() */
{
#ifdef PERL_IMPLICIT_SYS
dTHX;
#endif
if (where) {
/*SUPPRESS 701*/
}
}
/* safe version of system's calloc() */
{
dTHX;
#ifdef HAS_64K_LIMIT
my_exit(1);
}
#endif /* HAS_64K_LIMIT */
#ifdef DEBUGGING
Perl_croak_nocontext("panic: calloc");
#endif
DEBUG_m(PerlIO_printf(Perl_debug_log, "0x%"UVxf": (%05ld) calloc %ld x %ld bytes\n",PTR2UV(ptr),(long)PL_an++,(long)count,(long)size));
return ptr;
}
else if (PL_nomemok)
return Nullch;
else {
/* Can't use PerlIO to write as it allocates memory */
my_exit(1);
return Nullch;
}
/*NOTREACHED*/
}
/* These must be defined when not using Perl's malloc for binary
* compatibility */
#ifndef MYMALLOC
{
}
{
}
{
}
{
}
#endif
/* copy a string up to some (non-backslashed) delimiter, if any */
char *
Perl_delimcpy(pTHX_ register char *to, register char *toend, register char *from, register char *fromend, register int delim, I32 *retlen)
{
if (*from == '\\') {
from++;
else {
tolen++;
from++;
}
}
break;
}
*to = '\0';
return from;
}
/* return ptr to little string in big string, NULL if not found */
/* This routine was donated by Corey Satten. */
char *
{
register const char *s, *x;
if (!little)
return (char*)big;
if (!first)
return (char*)big;
while (*big) {
continue;
if (!*x)
return Nullch;
if (*s++ != *x++) {
s--;
break;
}
}
if (!*s)
return (char*)(big-1);
}
return Nullch;
}
/* same as instr but allow embedded nulls */
char *
Perl_ninstr(pTHX_ register const char *big, register const char *bigend, const char *little, const char *lend)
{
register const char *s, *x;
return (char*)big;
return Nullch;
continue;
if (*s++ != *x++) {
s--;
break;
}
}
if (s >= littleend)
return (char*)(big-1);
}
return Nullch;
}
/* reverse of the above--find last substring */
char *
Perl_rninstr(pTHX_ register const char *big, const char *bigend, const char *little, const char *lend)
{
register const char *bigbeg;
register const char *s, *x;
return (char*)bigend;
continue;
if (*s++ != *x++) {
s--;
break;
}
}
if (s >= littleend)
return (char*)(big+1);
}
return Nullch;
}
/* As a space optimization, we do not compile tables for strings of length
0 and 1, and for strings of length 2 unless FBMcf_TAIL. These are
special-cased in fbm_instr().
If FBMcf_TAIL, the table is created as if the string has a trailing \n. */
/*
=head1 Miscellaneous Functions
=for apidoc fbm_compile
Analyses the string in order to make fast searches on it using fbm_instr()
-- the Boyer-Moore algorithm.
=cut
*/
void
{
register U8 *s;
register U32 i;
if (flags & FBMcf_TAIL) {
}
if (len == 0) /* TAIL might be on a zero-length string. */
return;
if (len > 2) {
unsigned char *sb;
if (len > 255)
mlen = 255;
else
i = 0;
while (s >= sb) {
s--, i++;
}
}
SvVALID_on(sv);
for (i = 0; i < len; i++) {
rarest = i;
}
}
if (flags & FBMcf_TAIL)
}
/* If SvTAIL(littlestr), it has a fake '\n' at end. */
/* If SvTAIL is actually due to \Z or \z, this gives false positives
if multiline */
/*
=for apidoc fbm_instr
Returns the location of the SV in the string delimited by C<str> and
C<strend>. It returns C<Nullch> if the string can't be found. The C<sv>
does not have to be fbm_compiled, but the search will not be as fast
then.
=cut
*/
char *
{
register unsigned char *s;
STRLEN l;
&& (littlelen == 1
return (char*)big;
return Nullch;
}
if (littlelen == 1) {
/* Know that bigend != big. */
return (char *)(bigend - 1);
return (char *) bigend;
}
s = big;
while (s < bigend) {
if (*s == *little)
return (char *)s;
s++;
}
return (char *) bigend;
return Nullch;
}
if (!littlelen)
return (char*)big; /* Cannot be SvTAIL! */
/* littlelen is 2 */
return (char*)bigend - 2;
return (char*)bigend - 1;
return Nullch;
}
{
/* This should be better than FBM if c1 == c2, and almost
as good otherwise: maybe better since we do less indirection.
And we save a lot of memory by caching no table. */
s = big + 1;
bigend--;
while (s <= bigend) {
if (s[0] == c2) {
if (s[-1] == c1)
return (char*)s - 1;
s += 2;
continue;
}
if (s[0] == c1) {
if (s == bigend)
goto check_1char_anchor;
if (s[1] == c2)
return (char*)s;
else {
s++;
goto next_chars;
}
}
else
s += 2;
}
goto check_1char_anchor;
}
/* Now c1 == c2 */
while (s <= bigend) {
if (s[0] == c1) {
if (s[-1] == c1)
return (char*)s - 1;
if (s == bigend)
goto check_1char_anchor;
if (s[1] == c1)
return (char*)s;
s += 3;
}
else
s += 2;
}
}
check_1char_anchor: /* One char and anchor! */
return (char *)bigend; /* bigend is already decremented. */
return Nullch;
}
/* Automatically of length > 2 */
{
return (char*)s; /* how sweet it is */
}
if (s[1] == *little
{
return (char*)s + 1; /* how sweet it is */
}
return Nullch;
}
/* Chop \n from littlestr: */
if (*s == *little
{
return (char*)s;
}
return Nullch;
}
return b;
}
{ /* Do actual FBM. */
register unsigned char *oldlittle;
return Nullch;
--littlelen; /* Last char found by table lookup */
if (s < bigend) {
top2:
/*SUPPRESS 560*/
goto top2;
goto check_end;
}
else { /* less expensive than calling strncmp() */
register unsigned char *olds = s;
while (tmp--) {
if (*--s == *--little)
continue;
if (s < bigend) /* fake up continue to outer loop */
goto top2;
goto check_end;
}
return (char *)s;
}
}
return Nullch;
}
}
/* start_shift, end_shift are positive quantities which give offsets
of ends of some substring of bigstr.
If `last' we want the last occurrence.
old_posp is the way of communication between consequent calls if
the next call needs to find the .
The initial *old_posp should be -1.
Note that we take into account SvTAIL, so one can get extra
optimizations if _ALL flag is set.
*/
/* If SvTAIL is actually due to \Z or \z, this gives false positives
if PL_multiline. In fact if !PL_multiline the authoritative answer
is not supported yet. */
char *
Perl_screaminstr(pTHX_ SV *bigstr, SV *littlestr, I32 start_shift, I32 end_shift, I32 *old_posp, I32 last)
{
register unsigned char *s, *x;
register unsigned char *big;
register unsigned char *little;
register unsigned char *littleend;
if (*old_posp == -1
goto check_tail;
}
return Nullch;
}
/* The value of pos we can start at: */
/* The value of pos we can stop at: */
/*
stop_pos does not include SvTAIL in the count, so this check is incorrect
*/
#if 0
goto check_tail;
#endif
return Nullch;
}
goto cant_find;
}
do {
continue;
if (*s++ != *x++) {
s--;
break;
}
}
if (s == littleend) {
found = 1;
}
return Nullch;
/* Ignore the trailing "\n". This code is not microoptimized */
if (stop_pos == 0)
return (char*)big;
&& ((stop_pos == 1) ||
return (char*)big;
return Nullch;
}
{
while (len--) {
if (*a != *b && *a != PL_fold[*b])
return 1;
a++,b++;
}
return 0;
}
{
while (len--) {
if (*a != *b && *a != PL_fold_locale[*b])
return 1;
a++,b++;
}
return 0;
}
/* copy a string to a safe spot */
/*
=head1 Memory Management
=for apidoc savepv
Perl's version of C<strdup()>. Returns a pointer to a newly allocated
string which is a duplicate of C<pv>. The size of the string is
determined by C<strlen()>. The memory allocated for the new string can
be freed with the C<Safefree()> function.
=cut
*/
char *
{
if (pv) {
}
return newaddr;
}
/* same thing but with a known length */
/*
=for apidoc savepvn
Perl's version of what C<strndup()> would be if it existed. Returns a
pointer to a newly allocated string which is a duplicate of the first
C<len> bytes from C<pv>. The memory allocated for the new string can be
freed with the C<Safefree()> function.
=cut
*/
char *
{
register char *newaddr;
/* Give a meaning to NULL pointer mainly for the use in sv_magic() */
if (pv) {
}
else {
}
return newaddr;
}
/*
=for apidoc savesharedpv
A version of C<savepv()> which allocates the duplicate string in memory
which is shared between threads.
=cut
*/
char *
{
if (pv) {
}
return newaddr;
}
/* the SV for Perl_form() and mess() is not kept in an arena */
{
if (!PL_dirty)
if (PL_mess_sv)
return PL_mess_sv;
/* Create as PVMG now, to avoid any upgrading later */
PL_mess_sv = sv;
return sv;
}
#if defined(PERL_IMPLICIT_CONTEXT)
char *
Perl_form_nocontext(const char* pat, ...)
{
dTHX;
char *retval;
return retval;
}
#endif /* PERL_IMPLICIT_CONTEXT */
/*
=head1 Miscellaneous Functions
=for apidoc form
Takes a sprintf-style format pattern and conventional
(non-SV) arguments and returns the formatted string.
(char *) Perl_form(pTHX_ const char* pat, ...)
can be used any place a string (char *) is required:
char * s = Perl_form("%d.%d",major,minor);
Uses a single private buffer so if you want to format several strings you
must explicitly copy the earlier strings away (and free the copies when you
are done).
=cut
*/
char *
{
char *retval;
return retval;
}
char *
{
}
#if defined(PERL_IMPLICIT_CONTEXT)
SV *
Perl_mess_nocontext(const char *pat, ...)
{
dTHX;
return retval;
}
#endif /* PERL_IMPLICIT_CONTEXT */
SV *
{
return retval;
}
{
/* Look for PL_op starting from o. cop is the last COP we've seen. */
{
/* If the OP_NEXTSTATE has been optimised away we can still use it
* the get the file and line number. */
/* Keep searching, and return when we've found something. */
}
}
/* Nothing found. */
return 0;
}
SV *
{
static char dgd[] = " during global destruction.\n";
/*
* Try and find the file and line for PL_op. This will usually be
* PL_curcop, but it might be a cop that has been optimised away. We
* can try to find such a cop by searching through the optree starting
* from the sibling of PL_curcop.
*/
PL_last_in_gv == PL_argvgv ?
}
#ifdef USE_5005THREADS
#endif
}
return sv;
}
void
{
{
dSP;
}
else {
#ifdef USE_SFIO
/* SFIO can really mess with your errno */
int e = errno;
#endif
(void)PerlIO_flush(serr);
#ifdef USE_SFIO
errno = e;
#endif
}
}
OP *
{
char *message;
int was_in_eval = PL_in_eval;
"%p: die: curstack = %p, mainstack = %p\n",
if (pat) {
}
else
}
else {
msglen = 0;
}
"%p: die: message = %s\ndiehook = %p\n",
if (PL_diehook) {
/* sv_2cv might call Perl_croak() */
PL_diehook = Nullsv;
dSP;
if (message) {
}
else {
}
}
}
"%p: die: restartop = %p, was_in_eval = %d, top_env = %p\n",
JMPENV_JUMP(3);
return PL_restartop;
}
#if defined(PERL_IMPLICIT_CONTEXT)
OP *
Perl_die_nocontext(const char* pat, ...)
{
dTHX;
OP *o;
return o;
}
#endif /* PERL_IMPLICIT_CONTEXT */
OP *
{
OP *o;
return o;
}
void
{
char *message;
if (pat) {
}
else
}
else {
msglen = 0;
}
if (PL_diehook) {
/* sv_2cv might call Perl_croak() */
PL_diehook = Nullsv;
dSP;
if (message) {
}
else {
}
}
}
if (PL_in_eval) {
JMPENV_JUMP(3);
}
else if (!message)
}
#if defined(PERL_IMPLICIT_CONTEXT)
void
Perl_croak_nocontext(const char *pat, ...)
{
dTHX;
/* NOTREACHED */
}
#endif /* PERL_IMPLICIT_CONTEXT */
/*
=head1 Warning and Dieing
=for apidoc croak
This is the XSUB-writer's interface to Perl's C<die> function.
Normally call this function the same way you call the C C<printf>
function. Calling C<croak> returns control directly to Perl,
sidestepping the normal C order of execution. See C<warn>.
If you want to throw an exception object, assign the object to
C<$@> and then pass C<Nullch> to croak():
errsv = get_sv("@", TRUE);
sv_setsv(errsv, exception_object);
croak(Nullch);
=cut
*/
void
{
/* NOTREACHED */
}
void
{
char *message;
if (PL_warnhook) {
/* sv_2cv might call Perl_warn() */
dSP;
return;
}
}
}
#if defined(PERL_IMPLICIT_CONTEXT)
void
Perl_warn_nocontext(const char *pat, ...)
{
dTHX;
}
#endif /* PERL_IMPLICIT_CONTEXT */
/*
=for apidoc warn
This is the XSUB-writer's interface to Perl's C<warn> function. Call this
function the same way you call the C C<printf> function. See C<croak>.
=cut
*/
void
{
}
#if defined(PERL_IMPLICIT_CONTEXT)
void
{
dTHX;
}
#endif /* PERL_IMPLICIT_CONTEXT */
void
{
}
void
{
char *message;
#ifdef USE_5005THREADS
#endif /* USE_5005THREADS */
if (PL_diehook) {
/* sv_2cv might call Perl_croak() */
PL_diehook = Nullsv;
dSP;
}
}
if (PL_in_eval) {
JMPENV_JUMP(3);
}
}
else {
if (PL_warnhook) {
/* sv_2cv might call Perl_warn() */
dSP;
return;
}
}
}
}
/* since we've already done strlen() for both nam and val
* we can use that info to make things faster than
* sprintf(s, "%s=%s", nam, val)
*/
*(s+nlen) = '='; \
#ifdef USE_ENVIRON_ARRAY
/* VMS' my_setenv() is in vms.c */
void
{
#ifdef USE_ITHREADS
/* only parent thread can modify process environment */
if (PL_curinterp == aTHX)
#endif
{
#ifndef PERL_USE_SAFE_PUTENV
/* most putenv()s leak, so we manipulate environ directly */
I32 j;
char **tmpenv;
/*SUPPRESS 530*/
for (j=0; j<max; j++) { /* copy environment */
}
}
if (!val) {
safesysfree(environ[i]);
while (environ[i]) {
i++;
}
return;
}
if (!environ[i]) { /* does not exist yet */
}
else
safesysfree(environ[i]);
/* all that work just for this */
#else /* PERL_USE_SAFE_PUTENV */
# if defined(__CYGWIN__) || defined( EPOC)
# else
char *new_env;
if (!val) {
val = "";
}
/* all that work just for this */
# endif /* __CYGWIN__ */
#endif /* PERL_USE_SAFE_PUTENV */
}
}
#else /* WIN32 || NETWARE */
void
{
register char *envstr;
if (!val) {
val = "";
}
(void)PerlEnv_putenv(envstr);
}
#endif /* WIN32 || NETWARE */
#ifndef PERL_MICRO
{
for (i = 0; environ[i]; i++) {
if (
#ifdef WIN32
#else
#endif
break; /* strnEQ must come first to avoid */
} /* potential SEGV's */
return i;
}
#endif /* !PERL_MICRO */
#endif /* !VMS && !EPOC*/
#ifdef UNLINK_ALL_VERSIONS
{
I32 i;
for (i = 0; PerlLIO_unlink(f) >= 0; i++) ;
return i ? 0 : -1;
}
#endif
/* this is a drop-in replacement for bcopy() */
#if (!defined(HAS_MEMCPY) && !defined(HAS_BCOPY)) || (!defined(HAS_MEMMOVE) && !defined(HAS_SAFE_MEMCPY) && !defined(HAS_SAFE_BCOPY))
char *
{
while (len--)
}
else {
while (len--)
}
return retval;
}
#endif
/* this is a drop-in replacement for memset() */
#ifndef HAS_MEMSET
void *
{
while (len--)
return retval;
}
#endif
/* this is a drop-in replacement for bzero() */
#if !defined(HAS_BZERO) && !defined(HAS_MEMSET)
char *
{
while (len--)
*loc++ = 0;
return retval;
}
#endif
/* this is a drop-in replacement for memcmp() */
#if !defined(HAS_MEMCMP) || !defined(HAS_SANE_MEMCMP)
{
while (len--) {
if (tmp = *a++ - *b++)
return tmp;
}
return 0;
}
#endif /* !HAS_MEMCMP || !HAS_SANE_MEMCMP */
#ifndef HAS_VPRINTF
#ifdef USE_CHAR_VSPRINTF
char *
#else
int
#endif
{
#ifndef _IOSTRG
#define _IOSTRG 0
#endif
#ifdef USE_CHAR_VSPRINTF
return(dest);
#else
return 0; /* perl doesn't use return value */
#endif
}
#endif /* HAS_VPRINTF */
#ifdef MYSWAP
#if BYTEORDER != 0x4321
short
Perl_my_swap(pTHX_ short s)
{
#if (BYTEORDER & 1) == 0
short result;
return result;
#else
return s;
#endif
}
long
Perl_my_htonl(pTHX_ long l)
{
union {
long result;
char c[sizeof(long)];
} u;
#if BYTEORDER == 0x1234
u.c[0] = (l >> 24) & 255;
u.c[1] = (l >> 16) & 255;
u.c[2] = (l >> 8) & 255;
u.c[3] = l & 255;
return u.result;
#else
#else
register I32 o;
register I32 s;
u.c[o & 0xf] = (l >> s) & 255;
}
return u.result;
#endif
#endif
}
long
Perl_my_ntohl(pTHX_ long l)
{
union {
long l;
char c[sizeof(long)];
} u;
#if BYTEORDER == 0x1234
u.c[0] = (l >> 24) & 255;
u.c[1] = (l >> 16) & 255;
u.c[2] = (l >> 8) & 255;
u.c[3] = l & 255;
return u.l;
#else
#else
register I32 o;
register I32 s;
u.l = l;
l = 0;
l |= (u.c[o & 0xf] & 255) << s;
}
return l;
#endif
#endif
}
#endif /* BYTEORDER != 0x4321 */
#endif /* MYSWAP */
/*
* Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'.
* If these functions are defined,
* the BYTEORDER is neither 0x1234 nor 0x4321.
* However, this is not assumed.
* -DWS
*/
type \
{ \
union { \
char c[sizeof(type)]; \
} u; \
register I32 i; \
register I32 s; \
for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
u.c[i] = (n >> s) & 0xFF; \
} \
return u.value; \
}
type \
{ \
union { \
char c[sizeof(type)]; \
} u; \
register I32 i; \
register I32 s; \
u.value = n; \
n = 0; \
for (i = 0, s = 0; i < sizeof(u.c); i++, s += 8) { \
n += (u.c[i] & 0xFF) << s; \
} \
return n; \
}
#endif
#endif
#endif
#endif
PerlIO *
{
#if (!defined(DOSISH) || defined(HAS_FORK) || defined(AMIGAOS)) && !defined(OS2) && !defined(VMS) && !defined(__OPEN_VM) && !defined(EPOC) && !defined(MACOS_TRADITIONAL) && !defined(NETWARE)
int p[2];
int pp[2];
if (PL_tainting) {
taint_env();
}
if (PerlProc_pipe(p) < 0)
return Nullfp;
/* Try for another pipe pair for error return */
if (PerlProc_pipe(pp) >= 0)
did_pipes = 1;
while ((pid = PerlProc_fork()) < 0) {
PerlLIO_close(p[This]);
PerlLIO_close(p[that]);
if (did_pipes) {
PerlLIO_close(pp[0]);
}
return Nullfp;
}
sleep(5);
}
if (pid == 0) {
/* Child */
/* Close parent's end of error status pipe (if any) */
if (did_pipes) {
PerlLIO_close(pp[0]);
/* Close error pipe automatically if exec works */
#endif
}
/* Now dup our end of _the_ pipe to right position */
PerlLIO_close(p[THIS]);
}
else
/* No automatic close - do it by hand */
# ifndef NOFILE
# define NOFILE 20
# endif
{
int fd;
}
}
#endif
PerlProc__exit(1);
}
/* Parent */
do_execfree(); /* free any memory malloced by child on fork */
if (did_pipes)
/* Keep the lower of the two fd numbers */
PerlLIO_close(p[This]);
}
else
/* If we managed to get status pipe check for exec fail */
int errkid;
int n = 0, n1;
while (n < sizeof(int)) {
(void*)(((char*)&errkid)+n),
(sizeof(int)) - n);
if (n1 <= 0)
break;
n += n1;
}
PerlLIO_close(pp[0]);
did_pipes = 0;
if (n) { /* Error */
PerlLIO_close(p[This]);
if (n != sizeof(int))
do {
return Nullfp;
}
}
if (did_pipes)
PerlLIO_close(pp[0]);
#else
#endif
}
/* VMS' my_popen() is in VMS.c, same with OS/2. */
#if (!defined(DOSISH) || defined(HAS_FORK) || defined(AMIGAOS)) && !defined(VMS) && !defined(__OPEN_VM) && !defined(EPOC) && !defined(MACOS_TRADITIONAL)
PerlIO *
{
int p[2];
int pp[2];
#ifdef OS2
if (doexec) {
}
#endif
if (doexec && PL_tainting) {
taint_env();
}
if (PerlProc_pipe(p) < 0)
return Nullfp;
did_pipes = 1;
while ((pid = PerlProc_fork()) < 0) {
PerlLIO_close(p[This]);
PerlLIO_close(p[that]);
if (did_pipes) {
PerlLIO_close(pp[0]);
}
if (!doexec)
return Nullfp;
}
sleep(5);
}
if (pid == 0) {
if (did_pipes) {
PerlLIO_close(pp[0]);
#endif
}
PerlLIO_close(p[THIS]);
PerlLIO_close(p[THAT]);
}
else
PerlLIO_close(p[THAT]);
#ifndef OS2
if (doexec) {
int fd;
#ifndef NOFILE
#define NOFILE 20
#endif
{
int fd;
}
#endif
/* may or may not use the shell */
PerlProc__exit(1);
}
#endif /* defined OS2 */
/*SUPPRESS 560*/
}
#ifdef THREADS_HAVE_PIDS
#endif
PL_forkprocess = 0;
return Nullfp;
}
do_execfree(); /* free any memory malloced by child on vfork */
if (did_pipes)
PerlLIO_close(p[This]);
}
else
PerlLIO_close(p[that]);
int errkid;
int n = 0, n1;
while (n < sizeof(int)) {
(void*)(((char*)&errkid)+n),
(sizeof(int)) - n);
if (n1 <= 0)
break;
n += n1;
}
PerlLIO_close(pp[0]);
did_pipes = 0;
if (n) { /* Error */
PerlLIO_close(p[This]);
if (n != sizeof(int))
do {
return Nullfp;
}
}
if (did_pipes)
PerlLIO_close(pp[0]);
}
#else
PerlIO *
{
/* Call system's popen() to get a FILE *, then import it.
used 0 for 2nd parameter to PerlIO_importFILE;
apparently not used
*/
}
#else
#if defined(DJGPP)
FILE *djgpp_popen();
PerlIO *
{
/* Call system's popen() to get a FILE *, then import it.
used 0 for 2nd parameter to PerlIO_importFILE;
apparently not used
*/
}
#endif
#endif
#endif /* !DOSISH */
/* this is called in parent before the fork() */
void
Perl_atfork_lock(void)
{
#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
/* locks must be held in locking order (if any) */
# ifdef MYMALLOC
# endif
#endif
}
/* this is called in both parent and child after the fork() */
void
Perl_atfork_unlock(void)
{
#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
/* locks must be released in same order as in atfork_lock() */
# ifdef MYMALLOC
# endif
#endif
}
Perl_my_fork(void)
{
#if defined(HAS_FORK)
atfork_lock();
#else
/* atfork_lock() and atfork_unlock() are installed as pthread_atfork()
* handlers elsewhere in the code */
#endif
return pid;
#else
/* this "canna happen" since nothing should be calling here if !HAS_FORK */
Perl_croak_nocontext("fork() not available");
return 0;
#endif /* HAS_FORK */
}
#ifdef DUMP_FDS
void
Perl_dump_fds(pTHX_ char *s)
{
int fd;
}
}
#endif /* DUMP_FDS */
#ifndef HAS_DUP2
int
{
return oldfd;
#else
#define DUP2_MAX_FDS 256
int fdtmp[DUP2_MAX_FDS];
int fd;
return oldfd;
/* good enough for low fd's... */
if (fdx >= DUP2_MAX_FDS) {
fd = -1;
break;
}
}
while (fdx > 0)
return fd;
#endif
}
#endif
#ifndef PERL_MICRO
#ifdef HAS_SIGACTION
#ifdef MACOS_TRADITIONAL
/* We don't want restart behavior on MacOS */
#endif
{
#ifdef USE_ITHREADS
/* only "parent" interpreter can diddle signals */
if (PL_curinterp != aTHX)
return SIG_ERR;
#endif
#ifdef SA_RESTART
#endif
#endif
return SIG_ERR;
else
return oact.sa_handler;
}
{
return SIG_ERR;
else
return oact.sa_handler;
}
int
{
#ifdef USE_ITHREADS
/* only "parent" interpreter can diddle signals */
if (PL_curinterp != aTHX)
return -1;
#endif
#ifdef SA_RESTART
#endif
#endif
}
int
{
#ifdef USE_ITHREADS
/* only "parent" interpreter can diddle signals */
if (PL_curinterp != aTHX)
return -1;
#endif
}
#else /* !HAS_SIGACTION */
{
#if defined(USE_ITHREADS) && !defined(WIN32)
/* only "parent" interpreter can diddle signals */
if (PL_curinterp != aTHX)
return SIG_ERR;
#endif
}
static int sig_trapped; /* XXX signals are process-wide anyway, so we
ignore the implications of this for threading */
static
{
sig_trapped++;
}
{
#if defined(USE_ITHREADS) && !defined(WIN32)
/* only "parent" interpreter can diddle signals */
if (PL_curinterp != aTHX)
return SIG_ERR;
#endif
sig_trapped = 0;
if (sig_trapped)
return oldsig;
}
int
{
#if defined(USE_ITHREADS) && !defined(WIN32)
/* only "parent" interpreter can diddle signals */
if (PL_curinterp != aTHX)
return -1;
#endif
}
int
{
#if defined(USE_ITHREADS) && !defined(WIN32)
/* only "parent" interpreter can diddle signals */
if (PL_curinterp != aTHX)
return -1;
#endif
}
#endif /* !HAS_SIGACTION */
#endif /* !PERL_MICRO */
/* VMS' my_pclose() is in VMS.c; same with OS/2 */
#if (!defined(DOSISH) || defined(HAS_FORK) || defined(AMIGAOS)) && !defined(VMS) && !defined(__OPEN_VM) && !defined(EPOC) && !defined(MACOS_TRADITIONAL)
{
int status;
bool close_failed;
int saved_errno = 0;
#ifdef VMS
int saved_vaxc_errno;
#endif
#ifdef WIN32
int saved_win32_errno;
#endif
SvREFCNT_dec(*svp);
*svp = &PL_sv_undef;
#ifdef OS2
return my_syspclose(ptr);
}
#endif
saved_errno = errno;
#ifdef VMS
#endif
#ifdef WIN32
#endif
}
#ifdef UTS
#endif
#ifndef PERL_MICRO
#endif
do {
#ifndef PERL_MICRO
#endif
if (close_failed) {
return -1;
}
}
#endif /* !DOSISH */
#if (!defined(DOSISH) || defined(OS2) || defined(WIN32) || defined(NETWARE)) && !defined(MACOS_TRADITIONAL)
{
if (!pid)
return -1;
{
char spid[TYPE_CHARS(int)];
if (pid > 0) {
return pid;
}
}
else {
char spid[TYPE_CHARS(int)];
return pid;
}
}
}
#endif
#ifdef HAS_WAITPID
# ifdef HAS_WAITPID_RUNTIME
if (!HAS_WAITPID_RUNTIME)
goto hard_way;
# endif
goto finish;
#endif
#if !defined(HAS_WAITPID) && defined(HAS_WAIT4)
goto finish;
#endif
{
if (flags)
else {
if (result < 0)
*statusp = -1;
}
}
#endif
}
return result;
}
#endif /* !DOSISH || OS2 || WIN32 || NETWARE */
void
/*SUPPRESS 590*/
{
char spid[TYPE_CHARS(int)];
return;
}
int pclose();
#ifdef HAS_FORK
int /* Cannot prototype with I32
in os2ish.h. */
#else
#endif
{
/* Needs work for PerlIO ! */
return result;
}
#endif
#if defined(DJGPP)
int djgpp_pclose();
{
/* Needs work for PerlIO ! */
return result;
}
#endif
void
{
if (len == 1) {
register const char c = *from;
while (count-- > 0)
*to++ = c;
return;
}
while (count-- > 0) {
}
}
}
#ifndef HAS_RENAME
Perl_same_dirent(pTHX_ char *a, char *b)
{
if (fa)
fa++;
else
fa = a;
if (fb)
fb++;
else
fb = b;
if (strNE(a,b))
return FALSE;
if (fa == a)
else
return FALSE;
if (fb == b)
else
return FALSE;
}
#endif /* !HAS_RENAME */
char*
{
char tmpbuf[MAXPATHLEN];
register char *s;
int retval;
# define MAX_EXT_LEN 4
#endif
#ifdef OS2
# define MAX_EXT_LEN 4
#endif
#ifdef VMS
# define MAX_EXT_LEN 4
#endif
/* additional extensions to try in each dir if scriptname not found */
#ifdef SEARCH_EXTS
char *exts[] = { SEARCH_EXTS };
int extidx = 0, i = 0;
#else
# define MAX_EXT_LEN 0
#endif
/*
* If dosearch is true and if scriptname does not contain path
* delimiters, search the PATH for scriptname.
*
* If SEARCH_EXTS is also defined, will look for each
* scriptname{SEARCH_EXTS} whenever scriptname is not found
* while searching the PATH.
*
* Assuming SEARCH_EXTS is C<".foo",".bar",NULL>, PATH search
* proceeds as follows:
* If DOSISH or VMSISH:
* + look for ./scriptname{,.foo,.bar}
* + search the PATH for scriptname{,.foo,.bar}
*
* If !DOSISH:
* + look *only* in the PATH for scriptname{,.foo,.bar} (note
* this will not look in '.' if it's not in the PATH)
*/
tmpbuf[0] = '\0';
#ifdef VMS
# ifdef ALWAYS_DEFTYPES
bool seen_dot = 1;
# else
if (dosearch) {
bool seen_dot = 1;
# endif
/* The first time through, just add SEARCH_EXTS to whatever we
* already have, so we can check for default file types. */
while (deftypes ||
{
if (deftypes) {
deftypes = 0;
*tmpbuf = '\0';
}
+ MAX_EXT_LEN) >= sizeof tmpbuf)
continue; /* don't search dir with too-long name */
#else /* !VMS */
#ifdef DOSISH
dosearch = 0;
if (dosearch) { /* Look in '.' first. */
char *cur = scriptname;
#ifdef SEARCH_EXTS
while (ext[i])
break;
}
do {
#endif
"Looking for %s\n",cur));
dosearch = 0;
scriptname = cur;
#ifdef SEARCH_EXTS
break;
#endif
}
#ifdef SEARCH_EXTS
if (cur == scriptname) {
break;
}
#endif
}
#endif
#ifdef MACOS_TRADITIONAL
(s = PerlEnv_getenv("Commands")))
#else
#ifdef DOSISH
#endif
&& (s = PerlEnv_getenv("PATH")))
#endif
{
bool seen_dot = 0;
while (s < PL_bufend) {
#ifdef MACOS_TRADITIONAL
',',
&len);
#else
for (len = 0; *s
# ifdef atarist
&& *s != ','
# endif
&& *s != ';'; len++, s++) {
}
#else /* ! (atarist || DOSISH) */
':',
&len);
#endif /* ! (atarist || DOSISH) */
#endif /* MACOS_TRADITIONAL */
if (s < PL_bufend)
s++;
continue; /* don't search dir with too-long name */
#ifdef MACOS_TRADITIONAL
#else
if (len
#endif
)
seen_dot = 1;
#endif
#endif /* !VMS */
#ifdef SEARCH_EXTS
if (extidx > 0) /* reset after previous loop */
extidx = 0;
do {
#endif
retval = -1;
}
#ifdef SEARCH_EXTS
} while ( retval < 0 /* not there */
);
#endif
if (retval < 0)
continue;
#if !defined(DOSISH) && !defined(MACOS_TRADITIONAL)
#endif
)
{
break;
}
if (!xfailed)
}
#ifndef DOSISH
#endif
if (!xfound) {
}
scriptname = Nullch;
}
if (xfailed)
scriptname = xfound;
}
}
#ifndef PERL_GET_CONTEXT_DEFINED
void *
Perl_get_context(void)
{
#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
# ifdef OLD_PTHREADS_API
if (pthread_getspecific(PL_thr_key, &t))
Perl_croak_nocontext("panic: pthread_getspecific");
return (void*)t;
# else
# ifdef I_MACH_CTHREADS
return (void*)cthread_data(cthread_self());
# else
return (void*)PTHREAD_GETSPECIFIC(PL_thr_key);
# endif
# endif
#else
return (void*)NULL;
#endif
}
void
Perl_set_context(void *t)
{
#if defined(USE_5005THREADS) || defined(USE_ITHREADS)
# ifdef I_MACH_CTHREADS
cthread_set_data(cthread_self(), t);
# else
if (pthread_setspecific(PL_thr_key, t))
Perl_croak_nocontext("panic: pthread_setspecific");
# endif
#endif
}
#endif /* !PERL_GET_CONTEXT_DEFINED */
#ifdef USE_5005THREADS
#ifdef FAKE_THREADS
/* Very simplistic scheduler for now */
void
schedule(void)
{
}
void
{
*cp = 0;
}
void
{
if (!cond)
return;
/* Insert t in the runnable queue just ahead of us */
thr->i.wait_queue = 0;
/* Remove from the wait queue */
}
void
{
/* Insert t in the runnable queue just ahead of us */
thr->i.wait_queue = 0;
/* Remove from the wait queue */
}
*cp = 0;
}
void
{
/* Remove ourselves from runnable queue */
}
#endif /* FAKE_THREADS */
MAGIC *
{
if (!mg) {
condpair_t *cp;
LOCK_CRED_MUTEX; /* XXX need separate mutex? */
if (mg) {
/* someone else beat us to initialising it */
UNLOCK_CRED_MUTEX; /* XXX need separate mutex? */
}
else {
UNLOCK_CRED_MUTEX; /* XXX need separate mutex? */
}
}
return mg;
}
SV *
{
}
else {
}
return sv;
}
/*
* Make a new perl thread structure using t as a prototype. Some of the
* fields for the new thread are copied from the prototype thread, t,
* so t should not be running in perl at the time this function is
* thread calling new_struct_thread) clearly satisfies this constraint.
*/
struct perl_thread *
{
#if !defined(PERL_IMPLICIT_CONTEXT)
struct perl_thread *thr;
#endif
I32 i;
#ifdef DEBUGGING
PL_markstack = 0;
PL_scopestack = 0;
PL_savestack = 0;
PL_retstack = 0;
PL_dirty = 0;
PL_localizing = 0;
PL_efloatbuf = (char*)NULL;
PL_efloatsize = 0;
#else
#endif
init_stacks();
PL_restartop = 0;
PL_maxscream = -1;
PL_regindent = 0;
PL_reginterp_cnt = 0;
PL_screamfirst = 0;
PL_screamnext = 0;
PL_reg_start_tmp = 0;
PL_reg_start_tmpl = 0;
/* parent thread's data needs to be locked while we make copy */
MUTEX_LOCK(&t->mutex);
#ifdef PERL_FLEXIBLE_EXCEPTIONS
PL_protect = t->Tprotect;
#endif
PL_tainted = t->Ttainted;
PL_chopset = t->Tchopset;
if (t->Tformtarget == t->Ttoptarget)
else
PL_watchaddr = 0; /* XXX */
PL_watchok = 0; /* XXX */
PL_comppad = 0;
PL_curpad = 0;
/* Initialise all per-thread SVs that the template thread used */
}
}
PL_nthreads++;
/* done copying parent's state */
MUTEX_UNLOCK(&t->mutex);
#ifdef HAVE_THREAD_INTERN
#endif /* HAVE_THREAD_INTERN */
return thr;
}
#endif /* USE_5005THREADS */
#ifdef PERL_GLOBAL_STRUCT
struct perl_vars *
{
return &PL_Vars;
}
#endif
char **
{
return PL_op_name;
}
char **
{
return PL_op_desc;
}
char *
{
return (char*)PL_no_modify;
}
U32 *
{
return PL_opargs;
}
{
}
#ifndef HAS_GETENV_LEN
char *
{
if (env_trans)
return env_trans;
}
#endif
{
switch(vtbl_id) {
case want_vtbl_sv:
result = &PL_vtbl_sv;
break;
case want_vtbl_env:
result = &PL_vtbl_env;
break;
case want_vtbl_envelem:
break;
case want_vtbl_sig:
result = &PL_vtbl_sig;
break;
case want_vtbl_sigelem:
break;
case want_vtbl_pack:
result = &PL_vtbl_pack;
break;
case want_vtbl_packelem:
break;
case want_vtbl_dbline:
result = &PL_vtbl_dbline;
break;
case want_vtbl_isa:
result = &PL_vtbl_isa;
break;
case want_vtbl_isaelem:
break;
case want_vtbl_arylen:
result = &PL_vtbl_arylen;
break;
case want_vtbl_glob:
result = &PL_vtbl_glob;
break;
case want_vtbl_mglob:
result = &PL_vtbl_mglob;
break;
case want_vtbl_nkeys:
result = &PL_vtbl_nkeys;
break;
case want_vtbl_taint:
result = &PL_vtbl_taint;
break;
case want_vtbl_substr:
result = &PL_vtbl_substr;
break;
case want_vtbl_vec:
result = &PL_vtbl_vec;
break;
case want_vtbl_pos:
result = &PL_vtbl_pos;
break;
case want_vtbl_bm:
result = &PL_vtbl_bm;
break;
case want_vtbl_fm:
result = &PL_vtbl_fm;
break;
case want_vtbl_uvar:
result = &PL_vtbl_uvar;
break;
#ifdef USE_5005THREADS
case want_vtbl_mutex:
result = &PL_vtbl_mutex;
break;
#endif
case want_vtbl_defelem:
break;
case want_vtbl_regexp:
result = &PL_vtbl_regexp;
break;
case want_vtbl_regdata:
break;
case want_vtbl_regdatum:
break;
#ifdef USE_LOCALE_COLLATE
case want_vtbl_collxfrm:
break;
#endif
case want_vtbl_amagic:
result = &PL_vtbl_amagic;
break;
case want_vtbl_amagicelem:
break;
case want_vtbl_backref:
break;
case want_vtbl_utf8:
result = &PL_vtbl_utf8;
break;
}
return result;
}
{
return PerlIO_flush(NULL);
#else
# if defined(HAS__FWALK)
/* undocumented, unprototyped, but very useful BSDism */
return 0;
# else
# if defined(FFLUSH_ALL) && defined(HAS_STDIO_STREAM_ARRAY)
long open_max = -1;
# ifdef PERL_FFLUSH_ALL_FOPEN_MAX
# else
# if defined(HAS_SYSCONF) && defined(_SC_OPEN_MAX)
# else
# ifdef FOPEN_MAX
# else
# ifdef OPEN_MAX
# else
# ifdef _NFILE
# endif
# endif
# endif
# endif
# endif
if (open_max > 0) {
long i;
for (i = 0; i < open_max; i++)
if (STDIO_STREAM_ARRAY[i]._file >= 0 &&
return 0;
}
# endif
return EOF;
# endif
#endif
}
void
{
char *func =
PL_op_desc[op];
? "socket" : "filehandle";
}
"Filehandle %s opened only for %sput",
else
"Filehandle opened only for %sput", direction);
}
}
else {
char *vile;
vile = "closed";
}
else {
vile = "unopened";
}
"\t(Are you trying to call %s%s on dirhandle %s?)\n",
);
}
else {
"\t(Are you trying to call %s%s on dirhandle?)\n",
);
}
}
}
}
#ifdef EBCDIC
/* in ASCII order, not that it matters */
static const char controllablechars[] = "?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
int
{
if (ch > 'a') {
char *ctlp;
}
if (ctlp == controllablechars)
return('\177'); /* DEL */
else
} else { /* Want uncontrol */
return('?');
else if (ch == '\157')
return('\177');
else if (ch == '\174')
return('\000');
return('\036');
else if (ch == '\155')
return('\037');
else
}
}
#endif
/* To workaround core dumps from the uninitialised tm_zone we get the
* system to give us a reasonable struct to copy. This fix means that
* strftime uses the tm_zone and tm_gmtoff values returned by
* localtime(time()). That should give the desired result most of the
* time. But probably not always!
*
* This does not address tzname aspects of NETaa14816.
*
*/
#ifdef HAS_GNULIBC
# ifndef STRUCT_TM_HASZONE
# define STRUCT_TM_HASZONE
# endif
#endif
#ifdef STRUCT_TM_HASZONE /* Backward compat */
# ifndef HAS_TM_TM_ZONE
# define HAS_TM_TM_ZONE
# endif
#endif
void
{
#ifdef HAS_TM_TM_ZONE
#endif
}
/*
* mini_mktime - normalise struct tm values without the localtime()
* semantics (and overhead) of mktime().
*/
void
{
int yearday;
int secs;
#define DAYS_PER_YEAR 365
/* parentheses deliberately absent on these two, otherwise they don't work */
/* as used here, the algorithm leaves Sunday as day 1 unless we adjust it */
/*
*
* With a suitable offset for numeric value of the month, one can find
* an offset into the year by considering months to have 30.6 (153/5) days,
* using integer arithmetic (i.e., with truncation). To avoid too much
* messing about with leap days, we consider January and February to be
* the 13th and 14th month of the previous year. After that transformation,
* we need the month index we use to be high by 1 from 'normal human' usage,
* so the month index values we use run from 4 through 15.
*
* Given that, and the rules for the Gregorian calendar (leap years are those
* divisible by 4 unless also divisible by 100, when they must be divisible
* by 400 instead), we can simply calculate the number of days since some
* arbitrary 'beginning of time' by futzing with the (adjusted) year number,
* the days we derive from our month index, and adding in the day of the
* month. The value used here is not adjusted for the actual origin which
* it normally would use (1 January A.D. 1), since we're not exposing it.
* We're only building the value so we can turn around and get the
* normalised values for the year, month, day-of-month, and day-of-year.
*
* For going backward, we need to bias the value we're using so that we find
* the right year value. (Basically, we don't want the contribution of
* March 1st to the number to apply while deriving the year). Having done
* that, we 'count up' the contribution to the year number by accounting for
* full quadracenturies (400-year periods) with their extra leap days, plus
* the contribution from full centuries (to avoid counting in the lost leap
* days), plus the contribution from full quad-years (to count in the normal
* leap days), plus the leftover contribution from any non-leap years.
* At this point, if we were working with an actual leap day, we'll have 0
* days left over. This is also true for March 1st, however. So, we have
* to special-case that result, and (earlier) keep track of the 'odd'
* century and year contributions. If we got 4 extra centuries in a qcent,
* or 4 extra years in a qyear, then it's a leap day and we call it 29 Feb.
* Otherwise, we add back in the earlier bias we removed (the 123 from
* figuring in March 1st), find the month index (integer division by 30.6),
* and the remainder is the day-of-month. We then have to convert back to
* 'real' months (including fixing January and February from being 14/15 in
* the previous year to being in the proper year). After that, to get
* tm_yday, we work with the normalised year and get a new yearday value for
* January 1st, which we subtract from the yearday value we had earlier,
* representing the date we've re-built. This is done from January 1
* because tm_yday is 0-origin.
*
* Since POSIX time routines are only guaranteed to work for times since the
* UNIX epoch (00:00:00 1 Jan 1970 UTC), the fact that this algorithm
* applies Gregorian calendar rules even to dates before the 16th century
* doesn't bother me. Besides, you'd need cultural context for a given
* date to know whether it was Julian or Gregorian calendar, and that's
* outside the scope for this routine. Since we convert back based on the
* same rules we used to build the yearday, you'll only get strange results
* for input which needed normalising, or for the 'odd' century years which
* were leap years in the Julian calander but not in the Gregorian one.
* I can live with that.
*
* This algorithm also fails to handle years before A.D. 1 gracefully, but
* that's still outside the scope for POSIX time manipulation, so I don't
* care.
*/
/* allow given yday with no month & mday to dominate the result */
month = 0;
mday = 0;
}
else {
jday = 0;
}
if (month >= 2)
month+=2;
else
/*
* Note that we don't know when leap-seconds were or will be,
* so we have to trust the user if we get something which looks
* like a sensible leap-second. Wild values for seconds will
* be rationalised, however.
*/
secs = 0;
}
else {
}
if (secs < 0) {
/* got negative remainder, but need positive time */
/* back off an extra day to compensate */
}
else {
}
}
else if (secs >= SECS_PER_DAY) {
secs %= SECS_PER_DAY;
}
secs %= SECS_PER_HOUR;
secs %= 60;
/* done with time of day effects */
/*
* The algorithm for yearday has (so far) left it high by 428.
* To avoid mistaking a legitimate Feb 29 as Mar 1, we need to
* bias it by 123 while trying to figure out what year it
* really represents. Even with this tweak, the reverse
* translation fails for years before A.D. 0001.
* It would still fail for Feb 29, but we catch that one below.
*/
yearday -= YEAR_ADJUST;
yearday %= DAYS_PER_CENT;
yearday %= DAYS_PER_YEAR;
month = 1;
yearday = 29;
}
else {
/* recover other leap-year adjustment */
if (month > 13) {
month-=14;
year++;
}
else {
month-=2;
}
}
if (yearday) {
}
else {
}
/* re-build yearday based on Jan 1 to get tm_yday */
year--;
/* fix tm_wday if not overridden by caller */
}
char *
Perl_my_strftime(pTHX_ char *fmt, int sec, int min, int hour, int mday, int mon, int year, int wday, int yday, int isdst)
{
#ifdef HAS_STRFTIME
char *buf;
int buflen;
int len;
mini_mktime(&mytm);
/* use libc to get the values for tm_gmtoff and tm_zone [perl #18238] */
#ifdef HAS_TM_TM_GMTOFF
#endif
#ifdef HAS_TM_TM_ZONE
#endif
} STMT_END;
#endif
buflen = 64;
/*
** The following is needed to handle to the situation where
** tmpbuf overflows. Basically we want to allocate a buffer
** and try repeatedly. The reason why it is so complicated
** is that getting a return value of 0 from strftime can indicate
** one of the following:
** 1. buffer overflowed,
** 2. illegal conversion specifier, or
** 3. the format string specifies nothing to be returned(not
** an error). This could be because format is an empty string
** or it specifies %p that yields an empty string in some locale.
** If there is a better way to make it portable, go ahead by
** all means.
*/
return buf;
else {
/* Possibly buf overflowed - try again with a bigger buf */
while (buf) {
break;
/* heuristic to prevent out-of-memory errors */
break;
}
bufsize *= 2;
}
return buf;
}
#else
#endif
}
#define SV_CWD_RETURN_UNDEF \
return FALSE
#define SV_CWD_ISDOT(dp) \
/*
=head1 Miscellaneous Functions
=for apidoc getcwd_sv
Fill the sv with current working directory
=cut
*/
/* Originally written in Perl by John Bazik; rewritten in C by Ben Sugars.
* rewritten again by dougm, optimized for use with xs TARG, and to prefer
* getcwd(3) if available
* Comments from the orignal:
* This is a faster version of getcwd. It's also more dangerous
* because you might chdir out of a directory that you can't chdir
* back into. */
int
{
#ifndef PERL_MICRO
#ifndef INCOMPLETE_TAINTS
#endif
#ifdef HAS_GETCWD
{
char buf[MAXPATHLEN];
/* Some getcwd()s automatically allocate a buffer of the given
* size from the heap if they are given a NULL buffer pointer.
* The problem is that this behaviour is not portable. */
return TRUE;
}
else {
return FALSE;
}
}
#else
Direntry_t *dp;
}
for (;;) {
if (PerlDir_chdir("..") < 0) {
}
}
break;
}
}
#ifdef DIRNAMLEN
#else
#endif
/* skip . and .. */
if (SV_CWD_ISDOT(dp)) {
continue;
}
}
break;
}
}
if (!dp) {
}
}
if (pathlen) {
/* shift down */
}
/* prepend current directory to the front */
#ifdef VOID_CLOSEDIR
#else
if (PerlDir_close(dir) < 0) {
}
#endif
}
if (pathlen) {
SvPOK_only(sv);
}
}
}
"current directory changed unexpectedly");
}
return TRUE;
#endif
#else
return FALSE;
#endif
}
#if !defined(HAS_SOCKETPAIR) && defined(HAS_SOCKET) && defined(AF_INET) && defined(PF_INET) && defined(SOCK_DGRAM) && defined(HAS_SELECT)
# define EMULATE_SOCKETPAIR_UDP
#endif
#ifdef EMULATE_SOCKETPAIR_UDP
static int
dTHX;
/* Fake a datagram socketpair using UDP to localhost. */
int i;
unsigned short port;
int got;
i = 1;
do {
if (sockets[i] == -1)
goto tidy_up_and_fail;
sizeof(struct sockaddr_in)) == -1)
goto tidy_up_and_fail;
} while (i--);
/* Now have 2 UDP sockets. Find out which port each is connected to, and
for each connect the other socket to it. */
i = 1;
do {
&size) == -1)
goto tidy_up_and_fail;
if (size != sizeof(struct sockaddr_in))
goto abort_tidy_up_and_fail;
/* !1 is 0, !0 is 1 */
sizeof(struct sockaddr_in)) == -1)
goto tidy_up_and_fail;
} while (i--);
/* Now we have 2 sockets connected to each other. I don't trust some other
process not to have already sent a packet to us (by random) so send
a packet from each to the other. */
i = 1;
do {
/* I'm going to send my own port number. As a short.
(Who knows if someone somewhere has sin_port as a bitfield and needs
this routine. (I'm assuming crays have socketpair)) */
if (got == -1)
goto tidy_up_and_fail;
goto abort_tidy_up_and_fail;
}
} while (i--);
/* Packets sent. I don't trust them to have arrived though.
(As I understand it Solaris TCP stack is multithreaded. Non-blocking
connect to localhost will use a second kernel thread. In 2.6 the
first thread running the connect() returns before the second completes,
so EINPROGRESS> In 2.7 the improved stack is faster and connect()
returns 0. Poor programs have tripped up. One poor program's authors'
had a 50-1 reverse stock split. Not sure how connected these were.)
So I don't trust someone not to have an unpredictable UDP stack.
*/
{
/* I hope this is portable and appropriate. */
if (got == -1)
goto tidy_up_and_fail;
goto abort_tidy_up_and_fail;
}
}
/* And the paranoia department even now doesn't trust it to have arrive
(hence MSG_DONTWAIT). Or that what arrives was sent by us. */
{
struct sockaddr_in readfrom;
unsigned short buffer[2];
i = 1;
do {
#ifdef MSG_DONTWAIT
sizeof(buffer), MSG_DONTWAIT,
#else
sizeof(buffer), 0,
#endif
if (got == -1)
goto tidy_up_and_fail;
|| size != sizeof(struct sockaddr_in)
/* Check other socket sent us its port. */
/* Check kernel says we got the datagram from that socket */
goto abort_tidy_up_and_fail;
} while (i--);
}
/* My caller (my_socketpair) has validated that this is non-NULL */
/* I hereby declare this connection open. May God bless all who cross
her. */
return 0;
{
int save_errno = errno;
if (sockets[0] != -1)
PerlLIO_close(sockets[0]);
errno = save_errno;
return -1;
}
}
#endif /* EMULATE_SOCKETPAIR_UDP */
int
/* Stevens says that family must be AF_LOCAL, protocol 0.
I'm going to enforce that, then ignore it, and use TCP (or UDP). */
dTHX;
int listener = -1;
int connector = -1;
int acceptor = -1;
struct sockaddr_in listen_addr;
struct sockaddr_in connect_addr;
if (protocol
#ifdef AF_UNIX
#endif
) {
return -1;
}
if (!fd) {
return -1;
}
#ifdef EMULATE_SOCKETPAIR_UDP
if (type == SOCK_DGRAM)
return S_socketpair_udp(fd);
#endif
if (listener == -1)
return -1;
sizeof(listen_addr)) == -1)
goto tidy_up_and_fail;
goto tidy_up_and_fail;
if (connector == -1)
goto tidy_up_and_fail;
/* We want to find out the port number to connect to. */
size = sizeof(connect_addr);
&size) == -1)
goto tidy_up_and_fail;
if (size != sizeof(connect_addr))
goto abort_tidy_up_and_fail;
sizeof(connect_addr)) == -1)
goto tidy_up_and_fail;
size = sizeof(listen_addr);
&size);
if (acceptor == -1)
goto tidy_up_and_fail;
if (size != sizeof(listen_addr))
goto abort_tidy_up_and_fail;
/* Now check we are talking to ourself by matching port and host on the
two sockets. */
&size) == -1)
goto tidy_up_and_fail;
if (size != sizeof(connect_addr)
goto abort_tidy_up_and_fail;
}
return 0;
{
int save_errno = errno;
if (listener != -1)
if (connector != -1)
if (acceptor != -1)
errno = save_errno;
return -1;
}
}
#else
/* In any case have a stub so that there's code corresponding
* to the my_socketpair in global.sym. */
int
#ifdef HAS_SOCKETPAIR
#else
return -1;
#endif
}
#endif
/*
=for apidoc sv_nosharing
Dummy routine which "shares" an SV when there is no sharing module present.
Exists to avoid test for a NULL function pointer and because it could potentially warn under
some level of strict-ness.
=cut
*/
void
{
}
/*
=for apidoc sv_nolocking
Dummy routine which "locks" an SV when there is no locking module present.
Exists to avoid test for a NULL function pointer and because it could potentially warn under
some level of strict-ness.
=cut
*/
void
{
}
/*
=for apidoc sv_nounlocking
Dummy routine which "unlocks" an SV when there is no locking module present.
Exists to avoid test for a NULL function pointer and because it could potentially warn under
some level of strict-ness.
=cut
*/
void
{
}
{
char *p = *popt;
if (*p) {
if (isDIGIT(*p)) {
while (isDIGIT(*p)) p++;
if (*p && *p != '\n' && *p != '\r')
}
else {
for (; *p; p++) {
switch (*p) {
case PERL_UNICODE_STDIN:
opt |= PERL_UNICODE_STDIN_FLAG; break;
case PERL_UNICODE_STDOUT:
opt |= PERL_UNICODE_STDOUT_FLAG; break;
case PERL_UNICODE_STDERR:
opt |= PERL_UNICODE_STDERR_FLAG; break;
case PERL_UNICODE_STD:
opt |= PERL_UNICODE_STD_FLAG; break;
case PERL_UNICODE_IN:
opt |= PERL_UNICODE_IN_FLAG; break;
case PERL_UNICODE_OUT:
opt |= PERL_UNICODE_OUT_FLAG; break;
case PERL_UNICODE_INOUT:
opt |= PERL_UNICODE_INOUT_FLAG; break;
case PERL_UNICODE_LOCALE:
opt |= PERL_UNICODE_LOCALE_FLAG; break;
case PERL_UNICODE_ARGV:
opt |= PERL_UNICODE_ARGV_FLAG; break;
default:
if (*p != '\n' && *p != '\r')
"Unknown Unicode option letter '%c'", *p);
}
}
}
}
else
if (opt & ~PERL_UNICODE_ALL_FLAGS)
*popt = p;
return opt;
}
{
/*
* This is really just a quick hack which grabs various garbage
* values. It really should be a real hash algorithm which
* spreads the effect of every input bit onto every output bit,
* if someone who knows about such things would bother to write it.
* Might be a good idea to add that function to CORE as well.
* No numbers below come from careful analysis or anything here,
* except they are primes and SEED_C1 > 1E6 to get a full-width
* value from (tv_sec * SEED_C1 + tv_usec). The multipliers should
* probably be bigger too.
*/
#if RANDBITS > 16
# define SEED_C1 1000003
#define SEED_C4 73819
#else
# define SEED_C1 25747
#define SEED_C4 20639
#endif
#define SEED_C2 3
#define SEED_C3 269
#define SEED_C5 26107
#ifndef PERL_NO_DEV_RANDOM
int fd;
#endif
U32 u;
#ifdef VMS
# include <starlet.h>
/* when[] = (low 32 bits, high 32 bits) of time since epoch
* in 100-ns units, typically incremented ever 10 ms. */
unsigned int when[2];
#else
# ifdef HAS_GETTIMEOFDAY
# else
# endif
#endif
/* This test is an escape hatch, this symbol isn't set by Configure. */
#ifndef PERL_NO_DEV_RANDOM
#ifndef PERL_RANDOM_DEVICE
* if there isn't enough entropy available. You can compile with
* PERL_RANDOM_DEVICE to it if you'd prefer Perl to block until there
* is enough real entropy to fill the seed. */
# define PERL_RANDOM_DEVICE "/dev/urandom"
#endif
if (fd != -1) {
if (PerlLIO_read(fd, &u, sizeof u) != sizeof u)
u = 0;
if (u)
return u;
}
#endif
#ifdef VMS
#else
# ifdef HAS_GETTIMEOFDAY
# else
# endif
#endif
#ifndef PLAN9 /* XXX Plan9 assembler chokes on this; fix needed */
#endif
return u;
}
{
char *s = PerlEnv_getenv("PERL_HASH_SEED");
if (s)
while (isSPACE(*s)) s++;
if (s && isDIGIT(*s))
else
#ifdef USE_HASH_SEED_EXPLICIT
if (s)
#endif
{
/* Compute a random seed */
/* Since there are not enough randbits to to reach all
* the bits of a UV, the low bits might need extra
* help. Sum in another random number that will
* fill in the low bits. */
myseed +=
#endif /* RANDBITS < (UVSIZE * 8) */
if (myseed == 0) { /* Superparanoia. */
if (myseed == 0)
}
}
return myseed;
}