Back to index

php5  5.3.10
Defines | Enumerations | Functions | Variables
reentrancy.c File Reference
#include <sys/types.h>
#include <string.h>
#include <errno.h>
#include "php_reentrancy.h"
#include "ext/standard/php_rand.h"
#include <TSRM.h>
#include <stdlib.h>
#include <stddef.h>

Go to the source code of this file.

Defines

#define local_lock(x)   tsrm_mutex_lock(reentrant_locks[x])
#define local_unlock(x)   tsrm_mutex_unlock(reentrant_locks[x])

Enumerations

enum  {
  LOCALTIME_R, CTIME_R, ASCTIME_R, GMTIME_R,
  READDIR_R, NUMBER_OF_LOCKS
}

Functions

PHPAPI int php_readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result)
PHPAPI struct tm * php_localtime_r (const time_t *const timep, struct tm *p_tm)
PHPAPI char * php_ctime_r (const time_t *clock, char *buf)
PHPAPI char * php_asctime_r (const struct tm *tm, char *buf)
PHPAPI struct tm * php_gmtime_r (const time_t *const timep, struct tm *p_tm)
void reentrancy_startup (void)
void reentrancy_shutdown (void)
static int do_rand (unsigned long *ctx)
PHPAPI int php_rand_r (unsigned int *ctx)
PHPAPI char * php_strtok_r (char *s, const char *delim, char **last)

Variables

static MUTEX_T reentrant_locks [NUMBER_OF_LOCKS]

Define Documentation

#define local_lock (   x)    tsrm_mutex_lock(reentrant_locks[x])

Definition at line 46 of file reentrancy.c.

#define local_unlock (   x)    tsrm_mutex_unlock(reentrant_locks[x])

Definition at line 47 of file reentrancy.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
LOCALTIME_R 
CTIME_R 
ASCTIME_R 
GMTIME_R 
READDIR_R 
NUMBER_OF_LOCKS 

Definition at line 31 of file reentrancy.c.


Function Documentation

static int do_rand ( unsigned long *  ctx) [static]

Definition at line 315 of file reentrancy.c.

{
       return ((*ctx = *ctx * 1103515245 + 12345) % ((u_long)PHP_RAND_MAX + 1));
}

Here is the caller graph for this function:

PHPAPI char* php_asctime_r ( const struct tm *  tm,
char *  buf 
)

Definition at line 215 of file reentrancy.c.

{
       char *tmp;
       
       local_lock(ASCTIME_R);

       tmp = asctime(tm);
       strcpy(buf, tmp);

       local_unlock(ASCTIME_R);

       return buf;
}

Here is the caller graph for this function:

PHPAPI char* php_ctime_r ( const time_t *  clock,
char *  buf 
)

Definition at line 197 of file reentrancy.c.

{
       char *tmp;
       
       local_lock(CTIME_R);

       tmp = ctime(clock);
       strcpy(buf, tmp);

       local_unlock(CTIME_R);
       
       return buf;
}
PHPAPI struct tm* php_gmtime_r ( const time_t *const  timep,
struct tm *  p_tm 
) [read]

Definition at line 233 of file reentrancy.c.

{
       struct tm *tmp;
       
       local_lock(GMTIME_R);

       tmp = gmtime(timep);
       if (tmp) {
              memcpy(p_tm, tmp, sizeof(struct tm));
              tmp = p_tm;
       }
       
       local_unlock(GMTIME_R);

       return tmp;
}

Here is the caller graph for this function:

PHPAPI struct tm* php_localtime_r ( const time_t *const  timep,
struct tm *  p_tm 
) [read]

Definition at line 176 of file reentrancy.c.

{
       struct tm *tmp;
       
       local_lock(LOCALTIME_R);

       tmp = localtime(timep);
       if (tmp) {
              memcpy(p_tm, tmp, sizeof(struct tm));
              tmp = p_tm;
       }
       
       local_unlock(LOCALTIME_R);

       return tmp;
}

Here is the caller graph for this function:

PHPAPI int php_rand_r ( unsigned int ctx)

Definition at line 322 of file reentrancy.c.

{
       u_long val = (u_long) *ctx;
       *ctx = do_rand(&val);
       return (int) *ctx;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI int php_readdir_r ( DIR dirp,
struct dirent entry,
struct dirent **  result 
)

Definition at line 128 of file reentrancy.c.

{
#if defined(HAVE_OLD_READDIR_R)
       int ret = 0;
       
       /* We cannot rely on the return value of readdir_r
          as it differs between various platforms
          (HPUX returns 0 on success whereas Solaris returns non-zero)
        */
       entry->d_name[0] = '\0';
       readdir_r(dirp, entry);
       
       if (entry->d_name[0] == '\0') {
              *result = NULL;
              ret = errno;
       } else {
              *result = entry;
       }
       return ret;
#else
       struct dirent *ptr;
       int ret = 0;

       local_lock(READDIR_R);
       
       errno = 0;
       
       ptr = readdir(dirp);
       
       if (!ptr && errno != 0)
              ret = errno;

       if (ptr)
              memcpy(entry, ptr, sizeof(*ptr));

       *result = ptr;

       local_unlock(READDIR_R);

       return ret;
#endif
}

Here is the call graph for this function:

PHPAPI char* php_strtok_r ( char *  s,
const char *  delim,
char **  last 
)

Definition at line 380 of file reentrancy.c.

{
    char *spanp;
    int c, sc;
    char *tok;

    if (s == NULL && (s = *last) == NULL)
    {
       return NULL;
    }

    /*
     * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
     */
cont:
    c = *s++;
    for (spanp = (char *)delim; (sc = *spanp++) != 0; )
    {
       if (c == sc)
       {
           goto cont;
       }
    }

    if (c == 0)             /* no non-delimiter characters */
    {
       *last = NULL;
       return NULL;
    }
    tok = s - 1;

    /*
     * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
     * Note that delim must have one NUL; we stop if we see that, too.
     */
    for (;;)
    {
       c = *s++;
       spanp = (char *)delim;
       do
       {
           if ((sc = *spanp++) == c)
           {
              if (c == 0)
              {
                  s = NULL;
              }
              else
              {
                  char *w = s - 1;
                  *w = '\0';
              }
              *last = s;
              return tok;
           }
       }
       while (sc != 0);
    }
    /* NOTREACHED */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void reentrancy_shutdown ( void  )

Definition at line 263 of file reentrancy.c.

{
       int i;

       for (i = 0; i < NUMBER_OF_LOCKS; i++) {
              tsrm_mutex_free(reentrant_locks[i]);
       }
}

Here is the caller graph for this function:

void reentrancy_startup ( void  )

Definition at line 254 of file reentrancy.c.

{
       int i;

       for (i = 0; i < NUMBER_OF_LOCKS; i++) {
              reentrant_locks[i] = tsrm_mutex_alloc();
       }
}

Here is the caller graph for this function:


Variable Documentation

MUTEX_T reentrant_locks[NUMBER_OF_LOCKS] [static]

Definition at line 44 of file reentrancy.c.