1N/A * Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 1N/A * 2000, 2001, 2002, 2003, 2004, by Larry Wall and others 1N/A * You may distribute under the terms of either the GNU General Public 1N/A * License or the Artistic License, as specified in the README file. 1N/A * "Very useful, no doubt, that was to Saruman; yet it seems that he was 1N/A * not content." --Gandalf 1N/A/* NOTE: Do not call the next three routines directly. Use the macros 1N/A * in handy.h, so that we can easily redefine everything to do tracking of 1N/A * allocated hunks back to the original New to track down any memory leaks. 1N/A * XXX This advice seems to be widely ignored :-( --AD August 1996. 1N/A/* paranoid version of system's malloc() */ 1N/A#
endif /* HAS_64K_LIMIT */ 1N/A /* Can't use PerlIO to write as it allocates memory */ 1N/A/* paranoid version of system's realloc() */ 1N/A#
endif /* !defined(STANDARD_C) && !defined(HAS_REALLOC_PROTOTYPE) */ 1N/A#
endif /* HAS_64K_LIMIT */ 1N/A /* Can't use PerlIO to write as it allocates memory */ 1N/A/* safe version of system's free() */ 1N/A/* safe version of system's calloc() */ 1N/A#
endif /* HAS_64K_LIMIT */ 1N/A /* Can't use PerlIO to write as it allocates memory */ 1N/A/* These must be defined when not using Perl's malloc for binary 1N/A/* copy a string up to some (non-backslashed) delimiter, if any */ 1N/A/* return ptr to little string in big string, NULL if not found */ 1N/A/* This routine was donated by Corey Satten. */ 1N/A register const char *s, *x;
1N/A/* same as instr but allow embedded nulls */ 1N/A register const char *s, *x;
1N/A/* reverse of the above--find last substring */ 1N/A register const char *s, *x;
1N/A/* As a space optimization, we do not compile tables for strings of length 1N/A 0 and 1, and for strings of length 2 unless FBMcf_TAIL. These are 1N/A special-cased in fbm_instr(). 1N/A If FBMcf_TAIL, the table is created as if the string has a trailing \n. */ 1N/A=head1 Miscellaneous Functions 1N/A=for apidoc fbm_compile 1N/AAnalyses the string in order to make fast searches on it using fbm_instr() 1N/A-- the Boyer-Moore algorithm. 1N/A if (
len == 0)
/* TAIL might be on a zero-length string. */ 1N/A s = (
unsigned char*)(
SvPVX(
sv));
/* deeper magic */ 1N/A/* If SvTAIL(littlestr), it has a fake '\n' at end. */ 1N/A/* If SvTAIL is actually due to \Z or \z, this gives false positives 1N/A=for apidoc fbm_instr 1N/AReturns the location of the SV in the string delimited by C<str> and 1N/AC<strend>. It returns C<Nullch> if the string can't be found. The C<sv> 1N/Adoes not have to be fbm_compiled, but the search will not be as fast 1N/A register unsigned char *s;
1N/A /* Know that bigend != big. */ 1N/A return (
char*)
big;
/* Cannot be SvTAIL! */ 1N/A /* littlelen is 2 */ 1N/A /* This should be better than FBM if c1 == c2, and almost 1N/A as good otherwise: maybe better since we do less indirection. 1N/A And we save a lot of memory by caching no table. */ 1N/A return (
char*)s -
1;
1N/A return (
char*)s -
1;
1N/A return (
char *)
bigend;
/* bigend is already decremented. */ 1N/A /* Automatically of length > 2 */ 1N/A return (
char*)s;
/* how sweet it is */ 1N/A return (
char*)s +
1;
/* how sweet it is */ 1N/A /* Chop \n from littlestr: */ 1N/A {
/* Do actual FBM. */ 1N/A else {
/* less expensive than calling strncmp() */ 1N/A s =
olds +
1;
/* here we pay the price for failure */ 1N/A if (s <
bigend)
/* fake up continue to outer loop */ 1N/A/* start_shift, end_shift are positive quantities which give offsets 1N/A of ends of some substring of bigstr. 1N/A If `last' we want the last occurrence. 1N/A old_posp is the way of communication between consequent calls if 1N/A the next call needs to find the . 1N/A The initial *old_posp should be -1. 1N/A Note that we take into account SvTAIL, so one can get extra 1N/A optimizations if _ALL flag is set. 1N/A/* If SvTAIL is actually due to \Z or \z, this gives false positives 1N/A if PL_multiline. In fact if !PL_multiline the authoritative answer 1N/A is not supported yet. */ 1N/A register unsigned char *s, *x;
1N/A /* The value of pos we can start at: */ 1N/A /* The value of pos we can stop at: */ 1N/A stop_pos does not include SvTAIL in the count, so this check is incorrect 1N/A (I think) - see [ID 20010618.006] and t/op/study.t. HVDS 2001/06/19 1N/A /* Ignore the trailing "\n". This code is not microoptimized */ 1N/A/* copy a string to a safe spot */ 1N/A=head1 Memory Management 1N/APerl's version of C<strdup()>. Returns a pointer to a newly allocated 1N/Astring which is a duplicate of C<pv>. The size of the string is 1N/Adetermined by C<strlen()>. The memory allocated for the new string can 1N/Abe freed with the C<Safefree()> function. 1N/A/* same thing but with a known length */ 1N/APerl's version of what C<strndup()> would be if it existed. Returns a 1N/Apointer to a newly allocated string which is a duplicate of the first 1N/AC<len> bytes from C<pv>. The memory allocated for the new string can be 1N/Afreed with the C<Safefree()> function. 1N/A /* Give a meaning to NULL pointer mainly for the use in sv_magic() */ 1N/A=for apidoc savesharedpv 1N/AA version of C<savepv()> which allocates the duplicate string in memory 1N/Awhich is shared between threads. 1N/A/* the SV for Perl_form() and mess() is not kept in an arena */ 1N/A /* Create as PVMG now, to avoid any upgrading later */ 1N/A#
endif /* PERL_IMPLICIT_CONTEXT */ 1N/A=head1 Miscellaneous Functions 1N/ATakes a sprintf-style format pattern and conventional 1N/A(non-SV) arguments and returns the formatted string. 1N/A (char *) Perl_form(pTHX_ const char* pat, ...) 1N/Acan be used any place a string (char *) is required: 1N/A char * s = Perl_form("%d.%d",major,minor); 1N/AUses a single private buffer so if you want to format several strings you 1N/Amust explicitly copy the earlier strings away (and free the copies when you 1N/A#
endif /* PERL_IMPLICIT_CONTEXT */ 1N/A /* Look for PL_op starting from o. cop is the last COP we've seen. */ 1N/A /* If the OP_NEXTSTATE has been optimised away we can still use it 1N/A * the get the file and line number. */ 1N/A /* Keep searching, and return when we've found something. */ 1N/A /* Nothing found. */ 1N/A static char dgd[] =
" during global destruction.\n";
1N/A * Try and find the file and line for PL_op. This will usually be 1N/A * PL_curcop, but it might be a cop that has been optimised away. We 1N/A * can try to find such a cop by searching through the optree starting 1N/A * from the sibling of PL_curcop. 1N/A /* SFIO can really mess with your errno */ 1N/A "%p: die: curstack = %p, mainstack = %p\n",
1N/A "%p: die: message = %s\ndiehook = %p\n",
1N/A /* sv_2cv might call Perl_croak() */ 1N/A "%p: die: restartop = %p, was_in_eval = %d, top_env = %p\n",
1N/A#
endif /* PERL_IMPLICIT_CONTEXT */ 1N/A /* sv_2cv might call Perl_croak() */ 1N/A#
endif /* PERL_IMPLICIT_CONTEXT */ 1N/A=head1 Warning and Dieing 1N/AThis is the XSUB-writer's interface to Perl's C<die> function. 1N/ANormally call this function the same way you call the C C<printf> 1N/Afunction. Calling C<croak> returns control directly to Perl, 1N/Asidestepping the normal C order of execution. See C<warn>. 1N/AIf you want to throw an exception object, assign the object to 1N/AC<$@> and then pass C<Nullch> to croak(): 1N/A errsv = get_sv("@", TRUE); 1N/A sv_setsv(errsv, exception_object); 1N/A /* sv_2cv might call Perl_warn() */ 1N/A#
endif /* PERL_IMPLICIT_CONTEXT */ 1N/AThis is the XSUB-writer's interface to Perl's C<warn> function. Call this 1N/Afunction the same way you call the C C<printf> function. See C<croak>. 1N/A#
endif /* PERL_IMPLICIT_CONTEXT */ 1N/A#
endif /* USE_5005THREADS */ 1N/A /* sv_2cv might call Perl_croak() */ 1N/A /* sv_2cv might call Perl_warn() */ 1N/A/* since we've already done strlen() for both nam and val 1N/A * we can use that info to make things faster than 1N/A * sprintf(s, "%s=%s", nam, val) 1N/A /* only parent thread can modify process environment */ 1N/A /* most putenv()s leak, so we manipulate environ directly */ 1N/A for (j=0; j<
max; j++) {
/* copy environment */ 1N/A /* all that work just for this */ 1N/A#
else /* PERL_USE_SAFE_PUTENV */ 1N/A /* all that work just for this */ 1N/A#
endif /* __CYGWIN__ */ 1N/A#
endif /* PERL_USE_SAFE_PUTENV */ 1N/A#
else /* WIN32 || NETWARE */ 1N/A#
endif /* WIN32 || NETWARE */ 1N/A break;
/* strnEQ must come first to avoid */ 1N/A }
/* potential SEGV's */ 1N/A#
endif /* !PERL_MICRO */ 1N/A#
endif /* !VMS && !EPOC*/ 1N/A/* this is a drop-in replacement for bcopy() */ 1N/A/* this is a drop-in replacement for memset() */ 1N/A/* this is a drop-in replacement for bzero() */ 1N/A/* this is a drop-in replacement for memcmp() */ 1N/A#
endif /* !HAS_MEMCMP || !HAS_SANE_MEMCMP */ 1N/A return 0;
/* perl doesn't use return value */ 1N/A#
endif /* HAS_VPRINTF */ 1N/A result = ((s &
255) <<
8) + ((s >>
8) &
255);
1N/A char c[
sizeof(
long)];
1N/A u.c[0] = (l >>
24) &
255;
1N/A u.c[
1] = (l >>
16) &
255;
1N/A u.c[
2] = (l >>
8) &
255;
1N/A for (o =
BYTEORDER -
0x1111, s = 0; s < (
sizeof(
long)*
8); o >>=
4, s +=
8) {
1N/A u.c[o &
0xf] = (l >> s) &
255;
1N/A char c[
sizeof(
long)];
1N/A u.c[0] = (l >>
24) &
255;
1N/A u.c[
1] = (l >>
16) &
255;
1N/A u.c[
2] = (l >>
8) &
255;
1N/A for (o =
BYTEORDER -
0x1111, s = 0; s < (
sizeof(
long)*
8); o >>=
4, s +=
8) {
1N/A l |= (u.c[o &
0xf] &
255) << s;
1N/A#
endif /* BYTEORDER != 0x4321 */ 1N/A * Little-endian byte order functions - 'v' for 'VAX', or 'reVerse'. 1N/A * If these functions are defined, 1N/A * the BYTEORDER is neither 0x1234 nor 0x4321. 1N/A * However, this is not assumed. 1N/A for (i = 0, s = 0; i <
sizeof(u.c); i++, s +=
8) { \
1N/A u.c[i] = (n >> s) &
0xFF; \
1N/A for (i = 0, s = 0; i <
sizeof(u.c); i++, s +=
8) { \
1N/A n += (u.c[i] &
0xFF) << s; \
1N/A /* Try for another pipe pair for error return */ 1N/A /* Close parent's end of error status pipe (if any) */ 1N/A /* Close error pipe automatically if exec works */ 1N/A /* Now dup our end of _the_ pipe to right position */ 1N/A if (p[
THAT] != (*
mode ==
'r'))
/* if dup2() didn't close it */ 1N/A /* No automatic close - do it by hand */ 1N/A /* Keep the lower of the two fd numbers */ 1N/A /* If we managed to get status pipe check for exec fail */ 1N/A while (n <
sizeof(
int)) {
1N/A if (n) {
/* Error */ 1N/A if (n !=
sizeof(
int))
1N/A /* VMS' my_popen() is in VMS.c, same with OS/2. */ 1N/A if (p[
THAT] != (*
mode ==
'r'))
/* if dup2() didn't close it */ 1N/A /* may or may not use the shell */ 1N/A#
endif /* defined OS2 */ 1N/A while (n <
sizeof(
int)) {
1N/A if (n) {
/* Error */ 1N/A if (n !=
sizeof(
int))
1N/A /* Call system's popen() to get a FILE *, then import it. 1N/A used 0 for 2nd parameter to PerlIO_importFILE; 1N/A /* Call system's popen() to get a FILE *, then import it. 1N/A used 0 for 2nd parameter to PerlIO_importFILE; 1N/A/* this is called in parent before the fork() */ 1N/A /* locks must be held in locking order (if any) */ 1N/A/* this is called in both parent and child after the fork() */ 1N/A /* locks must be released in same order as in atfork_lock() */ 1N/A /* atfork_lock() and atfork_unlock() are installed as pthread_atfork() 1N/A * handlers elsewhere in the code */ 1N/A /* this "canna happen" since nothing should be calling here if !HAS_FORK */ 1N/A#
endif /* HAS_FORK */ 1N/A#
endif /* DUMP_FDS */ 1N/A /* good enough for low fd's... */ 1N/A/* We don't want restart behavior on MacOS */ 1N/A /* only "parent" interpreter can diddle signals */ 1N/A /* only "parent" interpreter can diddle signals */ 1N/A /* only "parent" interpreter can diddle signals */ 1N/A#
else /* !HAS_SIGACTION */ 1N/A /* only "parent" interpreter can diddle signals */ 1N/A ignore the implications of this for threading */ 1N/A /* only "parent" interpreter can diddle signals */ 1N/A /* only "parent" interpreter can diddle signals */ 1N/A /* only "parent" interpreter can diddle signals */ 1N/A#
endif /* !HAS_SIGACTION */ 1N/A#
endif /* !PERL_MICRO */ 1N/A /* VMS' my_pclose() is in VMS.c; same with OS/2 */ 1N/A if (
pid == -
1) {
/* Opened by popen. */ 1N/A#
endif /* !DOSISH || OS2 || WIN32 || NETWARE */ 1N/Aint /* Cannot prototype with I32 1N/A /* Needs work for PerlIO ! */ 1N/A /* Needs work for PerlIO ! */ 1N/A#
endif /* !HAS_RENAME */ 1N/A /* additional extensions to try in each dir if scriptname not found */ 1N/A * If dosearch is true and if scriptname does not contain path 1N/A * delimiters, search the PATH for scriptname. 1N/A * If SEARCH_EXTS is also defined, will look for each 1N/A * scriptname{SEARCH_EXTS} whenever scriptname is not found 1N/A * while searching the PATH. 1N/A * Assuming SEARCH_EXTS is C<".foo",".bar",NULL>, PATH search 1N/A * proceeds as follows: 1N/A * If DOSISH or VMSISH: 1N/A * + look for ./scriptname{,.foo,.bar} 1N/A * + search the PATH for scriptname{,.foo,.bar} 1N/A * + look *only* in the PATH for scriptname{,.foo,.bar} (note 1N/A * this will not look in '.' if it's not in the PATH) 1N/A /* The first time through, just add SEARCH_EXTS to whatever we 1N/A * already have, so we can check for default file types. */ 1N/A continue;
/* don't search dir with too-long name */ 1N/A#
else /* ! (atarist || DOSISH) */ 1N/A#
endif /* ! (atarist || DOSISH) */ 1N/A#
endif /* MACOS_TRADITIONAL */ 1N/A continue;
/* don't search dir with too-long name */ 1N/A if (
extidx > 0)
/* reset after previous loop */ 1N/A#
endif /* !PERL_GET_CONTEXT_DEFINED */ 1N/A/* Very simplistic scheduler for now */ 1N/A /* Insert t in the runnable queue just ahead of us */ 1N/A /* Remove from the wait queue */ 1N/A /* Insert t in the runnable queue just ahead of us */ 1N/A /* Remove from the wait queue */ 1N/A /* Remove ourselves from runnable queue */ 1N/A#
endif /* FAKE_THREADS */ 1N/A /* someone else beat us to initialising it */ 1N/A * Make a new perl thread structure using t as a prototype. Some of the 1N/A * fields for the new thread are copied from the prototype thread, t, 1N/A * so t should not be running in perl at the time this function is 1N/A * thread calling new_struct_thread) clearly satisfies this constraint. 1N/A /* parent thread's data needs to be locked while we make copy */ 1N/A /* Initialise all per-thread SVs that the template thread used */ 1N/A "new_struct_thread: copied threadsv %"IVdf" %p->%p\n",
1N/A /* done copying parent's state */ 1N/A#
endif /* HAVE_THREAD_INTERN */ 1N/A#
endif /* USE_5005THREADS */ 1N/A /* undocumented, unprototyped, but very useful BSDism */ 1N/A ?
"socket" :
"filehandle";
1N/A "Filehandle %s opened only for %sput",
1N/A "\t(Are you trying to call %s%s on dirhandle %s?)\n",
1N/A "\t(Are you trying to call %s%s on dirhandle?)\n",
1N/A/* in ASCII order, not that it matters */ 1N/A return(
'\177');
/* DEL */ 1N/A }
else {
/* Want uncontrol */ 1N/A else if (
ch ==
'^')
/* '\137' in 1047, '\260' in 819 */ 1N/A/* To workaround core dumps from the uninitialised tm_zone we get the 1N/A * system to give us a reasonable struct to copy. This fix means that 1N/A * strftime uses the tm_zone and tm_gmtoff values returned by 1N/A * localtime(time()). That should give the desired result most of the 1N/A * time. But probably not always! 1N/A * This does not address tzname aspects of NETaa14816. 1N/A * mini_mktime - normalise struct tm values without the localtime() 1N/A * semantics (and overhead) of mktime(). 1N/A/* parentheses deliberately absent on these two, otherwise they don't work */ 1N/A/* offset to bias by March (month 4) 1st between month/mday & year finding */ 1N/A/* as used here, the algorithm leaves Sunday as day 1 unless we adjust it */ 1N/A * With a suitable offset for numeric value of the month, one can find 1N/A * an offset into the year by considering months to have 30.6 (153/5) days, 1N/A * using integer arithmetic (i.e., with truncation). To avoid too much 1N/A * messing about with leap days, we consider January and February to be 1N/A * the 13th and 14th month of the previous year. After that transformation, 1N/A * we need the month index we use to be high by 1 from 'normal human' usage, 1N/A * so the month index values we use run from 4 through 15. 1N/A * Given that, and the rules for the Gregorian calendar (leap years are those 1N/A * divisible by 4 unless also divisible by 100, when they must be divisible 1N/A * by 400 instead), we can simply calculate the number of days since some 1N/A * arbitrary 'beginning of time' by futzing with the (adjusted) year number, 1N/A * the days we derive from our month index, and adding in the day of the 1N/A * month. The value used here is not adjusted for the actual origin which 1N/A * it normally would use (1 January A.D. 1), since we're not exposing it. 1N/A * We're only building the value so we can turn around and get the 1N/A * normalised values for the year, month, day-of-month, and day-of-year. 1N/A * For going backward, we need to bias the value we're using so that we find 1N/A * the right year value. (Basically, we don't want the contribution of 1N/A * March 1st to the number to apply while deriving the year). Having done 1N/A * that, we 'count up' the contribution to the year number by accounting for 1N/A * full quadracenturies (400-year periods) with their extra leap days, plus 1N/A * the contribution from full centuries (to avoid counting in the lost leap 1N/A * days), plus the contribution from full quad-years (to count in the normal 1N/A * leap days), plus the leftover contribution from any non-leap years. 1N/A * At this point, if we were working with an actual leap day, we'll have 0 1N/A * days left over. This is also true for March 1st, however. So, we have 1N/A * to special-case that result, and (earlier) keep track of the 'odd' 1N/A * century and year contributions. If we got 4 extra centuries in a qcent, 1N/A * or 4 extra years in a qyear, then it's a leap day and we call it 29 Feb. 1N/A * Otherwise, we add back in the earlier bias we removed (the 123 from 1N/A * figuring in March 1st), find the month index (integer division by 30.6), 1N/A * and the remainder is the day-of-month. We then have to convert back to 1N/A * 'real' months (including fixing January and February from being 14/15 in 1N/A * the previous year to being in the proper year). After that, to get 1N/A * tm_yday, we work with the normalised year and get a new yearday value for 1N/A * January 1st, which we subtract from the yearday value we had earlier, 1N/A * representing the date we've re-built. This is done from January 1 1N/A * because tm_yday is 0-origin. 1N/A * Since POSIX time routines are only guaranteed to work for times since the 1N/A * UNIX epoch (00:00:00 1 Jan 1970 UTC), the fact that this algorithm 1N/A * applies Gregorian calendar rules even to dates before the 16th century 1N/A * doesn't bother me. Besides, you'd need cultural context for a given 1N/A * date to know whether it was Julian or Gregorian calendar, and that's 1N/A * outside the scope for this routine. Since we convert back based on the 1N/A * same rules we used to build the yearday, you'll only get strange results 1N/A * for input which needed normalising, or for the 'odd' century years which 1N/A * were leap years in the Julian calander but not in the Gregorian one. 1N/A * I can live with that. 1N/A * This algorithm also fails to handle years before A.D. 1 gracefully, but 1N/A * that's still outside the scope for POSIX time manipulation, so I don't 1N/A /* allow given yday with no month & mday to dominate the result */ 1N/A * Note that we don't know when leap-seconds were or will be, 1N/A * so we have to trust the user if we get something which looks 1N/A * like a sensible leap-second. Wild values for seconds will 1N/A * be rationalised, however. 1N/A /* got negative remainder, but need positive time */ 1N/A /* back off an extra day to compensate */ 1N/A /* done with time of day effects */ 1N/A * The algorithm for yearday has (so far) left it high by 428. 1N/A * To avoid mistaking a legitimate Feb 29 as Mar 1, we need to 1N/A * bias it by 123 while trying to figure out what year it 1N/A * really represents. Even with this tweak, the reverse 1N/A * translation fails for years before A.D. 0001. 1N/A * It would still fail for Feb 29, but we catch that one below. 1N/A /* recover other leap-year adjustment */ 1N/A /* re-build yearday based on Jan 1 to get tm_yday */ 1N/A /* fix tm_wday if not overridden by caller */ 1N/A /* use libc to get the values for tm_gmtoff and tm_zone [perl #18238] */ 1N/A ** The following is needed to handle to the situation where 1N/A ** tmpbuf overflows. Basically we want to allocate a buffer 1N/A ** and try repeatedly. The reason why it is so complicated 1N/A ** is that getting a return value of 0 from strftime can indicate 1N/A ** one of the following: 1N/A ** 1. buffer overflowed, 1N/A ** 2. illegal conversion specifier, or 1N/A ** 3. the format string specifies nothing to be returned(not 1N/A ** an error). This could be because format is an empty string 1N/A ** or it specifies %p that yields an empty string in some locale. 1N/A ** If there is a better way to make it portable, go ahead by 1N/A /* Possibly buf overflowed - try again with a bigger buf */ 1N/A /* heuristic to prevent out-of-memory errors */ 1N/A=head1 Miscellaneous Functions 1N/A=for apidoc getcwd_sv 1N/AFill the sv with current working directory 1N/A/* Originally written in Perl by John Bazik; rewritten in C by Ben Sugars. 1N/A * rewritten again by dougm, optimized for use with xs TARG, and to prefer 1N/A * getcwd(3) if available 1N/A * Comments from the orignal: 1N/A * This is a faster version of getcwd. It's also more dangerous 1N/A * because you might chdir out of a directory that you can't chdir 1N/A /* Some getcwd()s automatically allocate a buffer of the given 1N/A * size from the heap if they are given a NULL buffer pointer. 1N/A * The problem is that this behaviour is not portable. */ 1N/A /* prepend current directory to the front */ 1N/A "current directory changed unexpectedly");
1N/A /* Fake a datagram socketpair using UDP to localhost. */ 1N/A /* Now have 2 UDP sockets. Find out which port each is connected to, and 1N/A for each connect the other socket to it. */ 1N/A /* !1 is 0, !0 is 1 */ 1N/A /* Now we have 2 sockets connected to each other. I don't trust some other 1N/A process not to have already sent a packet to us (by random) so send 1N/A a packet from each to the other. */ 1N/A /* I'm going to send my own port number. As a short. 1N/A (Who knows if someone somewhere has sin_port as a bitfield and needs 1N/A this routine. (I'm assuming crays have socketpair)) */ 1N/A /* Packets sent. I don't trust them to have arrived though. 1N/A (As I understand it Solaris TCP stack is multithreaded. Non-blocking 1N/A connect to localhost will use a second kernel thread. In 2.6 the 1N/A first thread running the connect() returns before the second completes, 1N/A so EINPROGRESS> In 2.7 the improved stack is faster and connect() 1N/A returns 0. Poor programs have tripped up. One poor program's authors' 1N/A had a 50-1 reverse stock split. Not sure how connected these were.) 1N/A So I don't trust someone not to have an unpredictable UDP stack. 1N/A /* I hope this is portable and appropriate. */ 1N/A /* And the paranoia department even now doesn't trust it to have arrive 1N/A (hence MSG_DONTWAIT). Or that what arrives was sent by us. */ 1N/A /* Check other socket sent us its port. */ 1N/A /* Check kernel says we got the datagram from that socket */ 1N/A /* My caller (my_socketpair) has validated that this is non-NULL */ 1N/A /* I hereby declare this connection open. May God bless all who cross 1N/A#
endif /* EMULATE_SOCKETPAIR_UDP */ 1N/A /* Stevens says that family must be AF_LOCAL, protocol 0. 1N/A I'm going to enforce that, then ignore it, and use TCP (or UDP). */ 1N/A /* We want to find out the port number to connect to. */ 1N/A /* Now check we are talking to ourself by matching port and host on the 1N/A/* In any case have a stub so that there's code corresponding 1N/A=for apidoc sv_nosharing 1N/ADummy routine which "shares" an SV when there is no sharing module present. 1N/AExists to avoid test for a NULL function pointer and because it could potentially warn under 1N/Asome level of strict-ness. 1N/A=for apidoc sv_nolocking 1N/ADummy routine which "locks" an SV when there is no locking module present. 1N/AExists to avoid test for a NULL function pointer and because it could potentially warn under 1N/Asome level of strict-ness. 1N/A=for apidoc sv_nounlocking 1N/ADummy routine which "unlocks" an SV when there is no locking module present. 1N/AExists to avoid test for a NULL function pointer and because it could potentially warn under 1N/Asome level of strict-ness. 1N/A if (*p && *p !=
'\n' && *p !=
'\r')
1N/A if (*p !=
'\n' && *p !=
'\r')
1N/A "Unknown Unicode option letter '%c'", *p);
1N/A * This is really just a quick hack which grabs various garbage 1N/A * values. It really should be a real hash algorithm which 1N/A * spreads the effect of every input bit onto every output bit, 1N/A * if someone who knows about such things would bother to write it. 1N/A * Might be a good idea to add that function to CORE as well. 1N/A * No numbers below come from careful analysis or anything here, 1N/A * except they are primes and SEED_C1 > 1E6 to get a full-width 1N/A * value from (tv_sec * SEED_C1 + tv_usec). The multipliers should 1N/A * probably be bigger too. 1N/A /* when[] = (low 32 bits, high 32 bits) of time since epoch 1N/A * in 100-ns units, typically incremented ever 10 ms. */ 1N/A/* This test is an escape hatch, this symbol isn't set by Configure. */ 1N/A /* /dev/random isn't used by default because reads from it will block 1N/A * if there isn't enough entropy available. You can compile with 1N/A * PERL_RANDOM_DEVICE to it if you'd prefer Perl to block until there 1N/A * is enough real entropy to fill the seed. */ 1N/A#
ifndef PLAN9 /* XXX Plan9 assembler chokes on this; fix needed */ 1N/A /* Compute a random seed */ 1N/A /* Since there are not enough randbits to to reach all 1N/A * the bits of a UV, the low bits might need extra 1N/A * help. Sum in another random number that will 1N/A * fill in the low bits. */ 1N/A#
endif /* RANDBITS < (UVSIZE * 8) */