Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

This commit was manufactured by cvs2svn to create tag 'POST_SUBST_Z_M…

…ACROS'.
  • Loading branch information...
commit a414936716e0435827fa0ab181b2f7e8b727087e 1 parent 6cfba2a
SVN Migration authored
Showing with 450 additions and 31,172 deletions.
  1. +0 −26 TSRM/LICENSE
  2. +0 −6 TSRM/Makefile.am
  3. +0 −2  TSRM/TODO
  4. +0 −588 TSRM/TSRM.c
  5. +0 −186 TSRM/TSRM.dsp
  6. +0 −143 TSRM/TSRM.h
  7. +0 −1  TSRM/acconfig.h
  8. +0 −5 TSRM/acinclude.m4
  9. +0 −43 TSRM/build.mk
  10. +0 −33 TSRM/buildconf
  11. +0 −31 TSRM/configure.in
  12. +0 −44 TSRM/readdir.h
  13. +0 −160 TSRM/threads.m4
  14. +0 −124 TSRM/tsrm.m4
  15. +0 −15 TSRM/tsrm_config.w32.h
  16. +0 −47 TSRM/tsrm_config_common.h
  17. +0 −63 TSRM/tsrm_strtok_r.c
  18. +0 −6 TSRM/tsrm_strtok_r.h
  19. +0 −773 TSRM/tsrm_virtual_cwd.c
  20. +0 −215 TSRM/tsrm_virtual_cwd.h
  21. +0 −359 TSRM/tsrm_win32.c
  22. +0 −107 TSRM/tsrm_win32.h
  23. +0 −186 Zend/FlexLexer.h
  24. +0 −116 Zend/LICENSE
  25. +0 −49 Zend/Makefile.am
  26. +0 −136 Zend/RFCs/001.txt
  27. +0 −169 Zend/RFCs/002.txt
  28. +0 −72 Zend/RFCs/003.txt
  29. +0 −233 Zend/ZEND_CHANGES
  30. +0 −502 Zend/Zend.dsp
  31. +0 −197 Zend/Zend.m4
  32. +0 −258 Zend/ZendCore.dep
  33. +0 −659 Zend/ZendTS.dsp
  34. +0 −76 Zend/acconfig.h
  35. +0 −47 Zend/acinclude.m4
  36. +0 −43 Zend/build.mk
  37. +0 −33 Zend/buildconf
  38. +0 −45 Zend/configure.in
  39. +0 −1,628 Zend/flex.skl
  40. +0 −861 Zend/zend.c
  41. +0 −536 Zend/zend.h
  42. BIN  Zend/zend.ico
  43. +0 −1,386 Zend/zend_API.c
  44. +0 −425 Zend/zend_API.h
  45. +0 −769 Zend/zend_alloc.c
  46. +0 −141 Zend/zend_alloc.h
  47. +0 −1,107 Zend/zend_builtin_functions.c
  48. +0 −26 Zend/zend_builtin_functions.h
  49. +0 −2,539 Zend/zend_compile.c
  50. +0 −631 Zend/zend_compile.h
  51. +0 −86 Zend/zend_config.w32.h
  52. +0 −270 Zend/zend_constants.c
  53. +0 −68 Zend/zend_constants.h
  54. +0 −62 Zend/zend_dynamic_array.c
  55. +0 −38 Zend/zend_dynamic_array.h
  56. +0 −40 Zend/zend_errors.h
  57. +0 −2,545 Zend/zend_execute.c
  58. +0 −161 Zend/zend_execute.h
  59. +0 −811 Zend/zend_execute_API.c
  60. +0 −32 Zend/zend_execute_locks.h
  61. +0 −218 Zend/zend_extensions.c
  62. +0 −116 Zend/zend_extensions.h
  63. +0 −140 Zend/zend_fast_cache.h
  64. +0 −243 Zend/zend_globals.h
  65. +0 −109 Zend/zend_globals_macros.h
  66. +0 −1,307 Zend/zend_hash.c
  67. +0 −219 Zend/zend_hash.h
  68. +0 −181 Zend/zend_highlight.c
  69. +0 −51 Zend/zend_highlight.h
  70. +0 −147 Zend/zend_indent.c
  71. +0 −26 Zend/zend_indent.h
  72. +0 −487 Zend/zend_ini.c
  73. +0 −199 Zend/zend_ini.h
  74. +0 −236 Zend/zend_ini_parser.y
  75. +0 −12 Zend/zend_ini_scanner.h
  76. +0 −227 Zend/zend_ini_scanner.l
  77. +0 −15 Zend/zend_istdiostream.h
  78. +0 −735 Zend/zend_language_parser.y
  79. +0 −38 Zend/zend_language_scanner.h
  80. +0 −1,468 Zend/zend_language_scanner.l
  81. +0 −391 Zend/zend_list.c
  82. +0 −109 Zend/zend_list.h
  83. +0 −305 Zend/zend_llist.c
  84. +0 −79 Zend/zend_llist.h
  85. +0 −84 Zend/zend_modules.h
  86. +0 −149 Zend/zend_objects.c
  87. +0 −35 Zend/zend_objects.h
  88. +0 −395 Zend/zend_opcode.c
  89. +0 −1,738 Zend/zend_operators.c
  90. +0 −266 Zend/zend_operators.h
  91. +0 −110 Zend/zend_ptr_stack.c
  92. +0 −58 Zend/zend_ptr_stack.h
  93. +0 −106 Zend/zend_qsort.c
  94. +0 −26 Zend/zend_qsort.h
  95. +0 −40 Zend/zend_sprintf.c
  96. +0 −164 Zend/zend_stack.c
  97. +0 −47 Zend/zend_stack.h
  98. +0 −76 Zend/zend_static_allocator.c
  99. +0 −45 Zend/zend_static_allocator.h
  100. +0 −196 Zend/zend_variables.c
  101. +0 −59 Zend/zend_variables.h
  102. +0 −103 ext/imap/imap.h
  103. +138 −0 ext/mnogosearch/test.php
  104. +0 −61 ext/pcre/config0.m4
  105. +234 −0 ext/standard/rand_mt.c
  106. +78 −0 ext/standard/rand_sys.c
  107. +0 −283 main/php_realpath.c
  108. +0 −113 strtok_r.c
View
26 TSRM/LICENSE
@@ -1,26 +0,0 @@
-Copyright (c) 1999, 2000, Andi Gutmans, Sascha Schumann, Zeev Suraski.
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are
-met:
-
-- Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-
-- Neither name of the copyright holders nor the names of their contributors
-may be used to endorse or promote products derived from this software
-without specific prior written permission.
-
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
6 TSRM/Makefile.am
@@ -1,6 +0,0 @@
-## process this file with automake to produce Makefile.am
-AUTOMAKE_OPTIONS=foreign
-noinst_LTLIBRARIES=libtsrm.la
-libtsrm_la_SOURCES = TSRM.c tsrm_strtok_r.c tsrm_virtual_cwd.c
-
-depend:
View
2  TSRM/TODO
@@ -1,2 +0,0 @@
-- Improve the lock in ts_resource_ex() in order to cover less code.
- This can probably be done by more careful hash table access
View
588 TSRM/TSRM.c
@@ -1,588 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | Thread Safe Resource Manager |
- +----------------------------------------------------------------------+
- | Copyright (c) 1999, 2000, Andi Gutmans, Sascha Schumann, Zeev Suraski|
- | This source file is subject to the TSRM license, that is bundled |
- | with this package in the file LICENSE |
- +----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-#include "TSRM.h"
-
-#ifdef ZTS
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#if HAVE_STDARG_H
-#include <stdarg.h>
-#endif
-
-typedef struct _tsrm_tls_entry tsrm_tls_entry;
-
-struct _tsrm_tls_entry {
- void **storage;
- int count;
- THREAD_T thread_id;
- tsrm_tls_entry *next;
-};
-
-
-typedef struct {
- size_t size;
- ts_allocate_ctor ctor;
- ts_allocate_dtor dtor;
-} tsrm_resource_type;
-
-
-/* The memory manager table */
-static tsrm_tls_entry **tsrm_tls_table=NULL;
-static int tsrm_tls_table_size;
-static ts_rsrc_id id_count;
-
-/* The resource sizes table */
-static tsrm_resource_type *resource_types_table=NULL;
-static int resource_types_table_size;
-
-
-static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */
-
-/* New thread handlers */
-static tsrm_thread_begin_func_t tsrm_new_thread_begin_handler;
-static tsrm_thread_end_func_t tsrm_new_thread_end_handler;
-
-/* Debug support */
-int tsrm_error(int level, const char *format, ...);
-
-/* Read a resource from a thread's resource storage */
-static int tsrm_error_level;
-static FILE *tsrm_error_file;
-
-#if TSRM_DEBUG
-#define TSRM_ERROR(args) tsrm_error args
-#define TSRM_SAFE_RETURN_RSRC(array, offset, range) \
- { \
- int unshuffled_offset = TSRM_UNSHUFFLE_RSRC_ID(offset); \
- \
- if (offset==0) { \
- return &array; \
- } else if ((unshuffled_offset)>=0 && (unshuffled_offset)<(range)) { \
- TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Successfully fetched resource id %d for thread id %ld - 0x%0.8X", \
- unshuffled_offset, (long) thread_resources->thread_id, array[unshuffled_offset])); \
- return array[unshuffled_offset]; \
- } else { \
- TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Resource id %d is out of range (%d..%d)", \
- unshuffled_offset, TSRM_SHUFFLE_RSRC_ID(0), TSRM_SHUFFLE_RSRC_ID(thread_resources->count-1))); \
- return NULL; \
- } \
- }
-#else
-#define TSRM_ERROR
-#define TSRM_SAFE_RETURN_RSRC(array, offset, range) \
- if (offset==0) { \
- return &array; \
- } else { \
- return array[TSRM_UNSHUFFLE_RSRC_ID(offset)]; \
- }
-#endif
-
-#if defined(PTHREADS)
-/* Thread local storage */
-static pthread_key_t tls_key;
-#elif defined(TSRM_ST)
-static int tls_key;
-#elif defined(TSRM_WIN32)
-static DWORD tls_key;
-#endif
-
-
-/* Startup TSRM (call once for the entire process) */
-TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename)
-{
-#if defined(GNUPTH)
- pth_init();
-#elif defined(PTHREADS)
- pthread_key_create( &tls_key, 0 );
-#elif defined(TSRM_ST)
- st_init();
- st_key_create(&tls_key, 0);
-#elif defined(TSRM_WIN32)
- tls_key = TlsAlloc();
-#endif
-
- tsrm_error_file = stderr;
- tsrm_error_set(debug_level, debug_filename);
- tsrm_tls_table_size = expected_threads;
-
- tsrm_tls_table = (tsrm_tls_entry **) calloc(tsrm_tls_table_size, sizeof(tsrm_tls_entry *));
- if (!tsrm_tls_table) {
- TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate TLS table"));
- return 0;
- }
- id_count=0;
-
- resource_types_table_size = expected_resources;
- resource_types_table = (tsrm_resource_type *) calloc(resource_types_table_size, sizeof(tsrm_resource_type));
- if (!resource_types_table) {
- TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate resource types table"));
- free(tsrm_tls_table);
- tsrm_tls_table = NULL;
- return 0;
- }
-
- tsmm_mutex = tsrm_mutex_alloc();
-
- tsrm_new_thread_begin_handler = tsrm_new_thread_end_handler = NULL;
-
- TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Started up TSRM, %d expected threads, %d expected resources", expected_threads, expected_resources));
- return 1;
-}
-
-
-/* Shutdown TSRM (call once for the entire process) */
-TSRM_API void tsrm_shutdown(void)
-{
- int i;
-
- if (tsrm_tls_table) {
- for (i=0; i<tsrm_tls_table_size; i++) {
- tsrm_tls_entry *p = tsrm_tls_table[i], *next_p;
-
- while (p) {
- int j;
-
- next_p = p->next;
- for (j=0; j<id_count; j++) {
- free(p->storage[j]);
- }
- free(p->storage);
- free(p);
- p = next_p;
- }
- }
- free(tsrm_tls_table);
- tsrm_tls_table = NULL;
- }
- if (resource_types_table) {
- free(resource_types_table);
- resource_types_table=NULL;
- }
- tsrm_mutex_free(tsmm_mutex);
- tsmm_mutex = NULL;
- TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Shutdown TSRM"));
- if (tsrm_error_file!=stderr) {
- fclose(tsrm_error_file);
- }
-#if defined(GNUPTH)
- pth_kill();
-#elif defined(PTHREADS)
- pthread_key_delete(tls_key);
-#elif defined(TSRM_WIN32)
- TlsFree(tls_key);
-#endif
-}
-
-
-/* allocates a new thread-safe-resource id */
-TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor)
-{
- int i;
-
- TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtaining a new resource id, %d bytes", size));
-
- tsrm_mutex_lock(tsmm_mutex);
-
- /* obtain a resource id */
- *rsrc_id = TSRM_SHUFFLE_RSRC_ID(id_count++);
- TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Obtained resource id %d", *rsrc_id));
-
- /* store the new resource type in the resource sizes table */
- if (resource_types_table_size < id_count) {
- resource_types_table = (tsrm_resource_type *) realloc(resource_types_table, sizeof(tsrm_resource_type)*id_count);
- if (!resource_types_table) {
- tsrm_mutex_unlock(tsmm_mutex);
- TSRM_ERROR((TSRM_ERROR_LEVEL_ERROR, "Unable to allocate storage for resource"));
- *rsrc_id = 0;
- return 0;
- }
- resource_types_table_size = id_count;
- }
- resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].size = size;
- resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].ctor = ctor;
- resource_types_table[TSRM_UNSHUFFLE_RSRC_ID(*rsrc_id)].dtor = dtor;
-
- /* enlarge the arrays for the already active threads */
- for (i=0; i<tsrm_tls_table_size; i++) {
- tsrm_tls_entry *p = tsrm_tls_table[i];
-
- while (p) {
- if (p->count < id_count) {
- int j;
-
- p->storage = (void *) realloc(p->storage, sizeof(void *)*id_count);
- for (j=p->count; j<id_count; j++) {
- p->storage[j] = (void *) malloc(resource_types_table[j].size);
- if (resource_types_table[j].ctor) {
- resource_types_table[j].ctor(p->storage[j], &p->storage);
- }
- }
- p->count = id_count;
- }
- p = p->next;
- }
- }
- tsrm_mutex_unlock(tsmm_mutex);
-
- TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Successfully allocated new resource id %d", *rsrc_id));
- return *rsrc_id;
-}
-
-
-static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_T thread_id)
-{
- int i;
-
- TSRM_ERROR((TSRM_ERROR_LEVEL_CORE, "Creating data structures for thread %x", thread_id));
- (*thread_resources_ptr) = (tsrm_tls_entry *) malloc(sizeof(tsrm_tls_entry));
- (*thread_resources_ptr)->storage = (void **) malloc(sizeof(void *)*id_count);
- (*thread_resources_ptr)->count = id_count;
- (*thread_resources_ptr)->thread_id = thread_id;
- (*thread_resources_ptr)->next = NULL;
-
-#if defined(PTHREADS)
- /* Set thread local storage to this new thread resources structure */
- pthread_setspecific(tls_key, (void *) *thread_resources_ptr);
-#elif defined(TSRM_ST)
- st_thread_setspecific(tls_key, (void *) *thread_resources_ptr);
-#elif defined(TSRM_WIN32)
- TlsSetValue(tls_key, (void *) *thread_resources_ptr);
-#endif
-
- if (tsrm_new_thread_begin_handler) {
- tsrm_new_thread_begin_handler(thread_id, &((*thread_resources_ptr)->storage));
- }
- for (i=0; i<id_count; i++) {
- (*thread_resources_ptr)->storage[i] = (void *) malloc(resource_types_table[i].size);
- if (resource_types_table[i].ctor) {
- resource_types_table[i].ctor((*thread_resources_ptr)->storage[i], &(*thread_resources_ptr)->storage);
- }
- }
-
- tsrm_mutex_unlock(tsmm_mutex);
-
- if (tsrm_new_thread_end_handler) {
- tsrm_new_thread_end_handler(thread_id, &((*thread_resources_ptr)->storage));
- }
-}
-
-
-/* fetches the requested resource for the current thread */
-TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id)
-{
- THREAD_T thread_id;
- int hash_value;
- tsrm_tls_entry *thread_resources;
-
- if (!th_id) {
-#if defined(PTHREADS)
- /* Fast path for looking up the resources for the current
- * thread. Its used by just about every call to
- * ts_resource_ex(). This avoids the need for a mutex lock
- * and our hashtable lookup.
- */
- thread_resources = pthread_getspecific(tls_key);
-#elif defined(TSRM_ST)
- thread_resources = st_thread_getspecific(tls_key);
-#elif defined(TSRM_WIN32)
- thread_resources = TlsGetValue(tls_key);
-#else
- thread_resources = NULL;
-#endif
- if (thread_resources) {
- TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Fetching resource id %d for current thread %d", id, (long) thread_resources->thread_id));
- /* Read a specific resource from the thread's resources.
- * This is called outside of a mutex, so have to be aware about external
- * changes to the structure as we read it.
- */
- TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count);
- }
- thread_id = tsrm_thread_id();
- } else {
- thread_id = *th_id;
- }
-
- TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Fetching resource id %d for thread %ld", id, (long) thread_id));
- tsrm_mutex_lock(tsmm_mutex);
-
- hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size);
- thread_resources = tsrm_tls_table[hash_value];
-
- if (!thread_resources) {
- allocate_new_resource(&tsrm_tls_table[hash_value], thread_id);
- return ts_resource_ex(id, &thread_id);
- } else {
- do {
- if (thread_resources->thread_id == thread_id) {
- break;
- }
- if (thread_resources->next) {
- thread_resources = thread_resources->next;
- } else {
- allocate_new_resource(&thread_resources->next, thread_id);
- return ts_resource_ex(id, &thread_id);
- /*
- * thread_resources = thread_resources->next;
- * break;
- */
- }
- } while (thread_resources);
- }
- tsrm_mutex_unlock(tsmm_mutex);
- /* Read a specific resource from the thread's resources.
- * This is called outside of a mutex, so have to be aware about external
- * changes to the structure as we read it.
- */
- TSRM_SAFE_RETURN_RSRC(thread_resources->storage, id, thread_resources->count);
-}
-
-
-/* frees all resources allocated for the current thread */
-void ts_free_thread(void)
-{
- tsrm_tls_entry *thread_resources;
- int i;
- THREAD_T thread_id = tsrm_thread_id();
- int hash_value;
- tsrm_tls_entry *last=NULL;
-
- tsrm_mutex_lock(tsmm_mutex);
- hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size);
- thread_resources = tsrm_tls_table[hash_value];
-
- while (thread_resources) {
- if (thread_resources->thread_id == thread_id) {
- for (i=0; i<thread_resources->count; i++) {
- if (resource_types_table[i].dtor) {
- resource_types_table[i].dtor(thread_resources->storage[i], &thread_resources->storage);
- }
- }
- for (i=0; i<thread_resources->count; i++) {
- free(thread_resources->storage[i]);
- }
- free(thread_resources->storage);
- if (last) {
- last->next = thread_resources->next;
- } else {
- tsrm_tls_table[hash_value] = thread_resources->next;
- }
-#if defined(PTHREADS)
- pthread_setspecific(tls_key, 0);
-#elif defined(TSRM_WIN32)
- TlsSetValue(tls_key, 0);
-#endif
- free(thread_resources);
- break;
- }
- if (thread_resources->next) {
- last = thread_resources;
- }
- thread_resources = thread_resources->next;
- }
- tsrm_mutex_unlock(tsmm_mutex);
-}
-
-
-/* deallocates all occurrences of a given id */
-void ts_free_id(ts_rsrc_id id)
-{
-}
-
-
-
-
-/*
- * Utility Functions
- */
-
-/* Obtain the current thread id */
-TSRM_API THREAD_T tsrm_thread_id(void)
-{
-#ifdef TSRM_WIN32
- return GetCurrentThreadId();
-#elif defined(GNUPTH)
- return pth_self();
-#elif defined(PTHREADS)
- return pthread_self();
-#elif defined(NSAPI)
- return systhread_current();
-#elif defined(PI3WEB)
- return PIThread_getCurrent();
-#elif defined(TSRM_ST)
- return st_thread_self();
-#endif
-}
-
-
-/* Allocate a mutex */
-TSRM_API MUTEX_T tsrm_mutex_alloc(void)
-{
- MUTEX_T mutexp;
-
-#ifdef TSRM_WIN32
- mutexp = malloc(sizeof(CRITICAL_SECTION));
- InitializeCriticalSection(mutexp);
-#elif defined(GNUPTH)
- mutexp = (MUTEX_T) malloc(sizeof(*mutexp));
- pth_mutex_init(mutexp);
-#elif defined(PTHREADS)
- mutexp = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t));
- pthread_mutex_init(mutexp,NULL);
-#elif defined(NSAPI)
- mutexp = crit_init();
-#elif defined(PI3WEB)
- mutexp = PIPlatform_allocLocalMutex();
-#elif defined(TSRM_ST)
- mutexp = st_mutex_new();
-#endif
-#ifdef THR_DEBUG
- printf("Mutex created thread: %d\n",mythreadid());
-#endif
- return( mutexp );
-}
-
-
-/* Free a mutex */
-TSRM_API void tsrm_mutex_free(MUTEX_T mutexp)
-{
- if (mutexp) {
-#ifdef TSRM_WIN32
- DeleteCriticalSection(mutexp);
-#elif defined(GNUPTH)
- free(mutexp);
-#elif defined(PTHREADS)
- pthread_mutex_destroy(mutexp);
- free(mutexp);
-#elif defined(NSAPI)
- crit_terminate(mutexp);
-#elif defined(PI3WEB)
- PISync_delete(mutexp);
-#elif defined(TSRM_ST)
- st_mutex_destroy(mutexp);
-#endif
- }
-#ifdef THR_DEBUG
- printf("Mutex freed thread: %d\n",mythreadid());
-#endif
-}
-
-
-/* Lock a mutex */
-TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp)
-{
- TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex locked thread: %ld", tsrm_thread_id()));
-#ifdef TSRM_WIN32
- EnterCriticalSection(mutexp);
- return 1;
-#elif defined(GNUPTH)
- return pth_mutex_acquire(mutexp, 0, NULL);
-#elif defined(PTHREADS)
- return pthread_mutex_lock(mutexp);
-#elif defined(NSAPI)
- return crit_enter(mutexp);
-#elif defined(PI3WEB)
- return PISync_lock(mutexp);
-#elif defined(TSRM_ST)
- return st_mutex_lock(mutexp);
-#endif
-}
-
-
-/* Unlock a mutex */
-TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp)
-{
- TSRM_ERROR((TSRM_ERROR_LEVEL_INFO, "Mutex unlocked thread: %ld", tsrm_thread_id()));
-#ifdef TSRM_WIN32
- LeaveCriticalSection(mutexp);
- return 1;
-#elif defined(GNUPTH)
- return pth_mutex_release(mutexp);
-#elif defined(PTHREADS)
- return pthread_mutex_unlock(mutexp);
-#elif defined(NSAPI)
- return crit_exit(mutexp);
-#elif defined(PI3WEB)
- return PISync_unlock(mutexp);
-#elif defined(TSRM_ST)
- return st_mutex_unlock(mutexp);
-#endif
-}
-
-
-TSRM_API void *tsrm_set_new_thread_begin_handler(tsrm_thread_begin_func_t new_thread_begin_handler)
-{
- void *retval = (void *) tsrm_new_thread_begin_handler;
-
- tsrm_new_thread_begin_handler = new_thread_begin_handler;
- return retval;
-}
-
-
-TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread_end_handler)
-{
- void *retval = (void *) tsrm_new_thread_end_handler;
-
- tsrm_new_thread_end_handler = new_thread_end_handler;
- return retval;
-}
-
-
-
-/*
- * Debug support
- */
-
-#if TSRM_DEBUG
-int tsrm_error(int level, const char *format, ...)
-{
- if (level<=tsrm_error_level) {
- va_list args;
- int size;
-
- fprintf(tsrm_error_file, "TSRM: ");
- va_start(args, format);
- size = vfprintf(tsrm_error_file, format, args);
- va_end(args);
- fprintf(tsrm_error_file, "\n");
- fflush(tsrm_error_file);
- return size;
- } else {
- return 0;
- }
-}
-#endif
-
-
-void tsrm_error_set(int level, char *debug_filename)
-{
- tsrm_error_level = level;
-
-#if TSRM_DEBUG
- if (tsrm_error_file!=stderr) { /* close files opened earlier */
- fclose(tsrm_error_file);
- }
-
- if (debug_filename) {
- tsrm_error_file = fopen(debug_filename, "w");
- if (!tsrm_error_file) {
- tsrm_error_file = stderr;
- }
- } else {
- tsrm_error_file = stderr;
- }
-#endif
-}
-
-#endif /* ZTS */
View
186 TSRM/TSRM.dsp
@@ -1,186 +0,0 @@
-# Microsoft Developer Studio Project File - Name="TSRM" - Package Owner=<4>
-# Microsoft Developer Studio Generated Build File, Format Version 6.00
-# ** DO NOT EDIT **
-
-# TARGTYPE "Win32 (x86) Static Library" 0x0104
-
-CFG=TSRM - Win32 Debug_TS
-!MESSAGE This is not a valid makefile. To build this project using NMAKE,
-!MESSAGE use the Export Makefile command and run
-!MESSAGE
-!MESSAGE NMAKE /f "TSRM.mak".
-!MESSAGE
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE NMAKE /f "TSRM.mak" CFG="TSRM - Win32 Debug_TS"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "TSRM - Win32 Debug_TS" (based on "Win32 (x86) Static Library")
-!MESSAGE "TSRM - Win32 Release_TS" (based on "Win32 (x86) Static Library")
-!MESSAGE "TSRM - Win32 Release_TS_inline" (based on "Win32 (x86) Static Library")
-!MESSAGE "TSRM - Win32 Release_TSDbg" (based on "Win32 (x86) Static Library")
-!MESSAGE
-
-# Begin Project
-# PROP AllowPerConfigDependencies 0
-# PROP Scc_ProjName ""
-# PROP Scc_LocalPath ""
-CPP=cl.exe
-RSC=rc.exe
-
-!IF "$(CFG)" == "TSRM - Win32 Debug_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 1
-# PROP BASE Output_Dir "TSRM___Win32_Debug_TS"
-# PROP BASE Intermediate_Dir "TSRM___Win32_Debug_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 1
-# PROP Output_Dir "Debug_TS"
-# PROP Intermediate_Dir "Debug_TS"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I "C:\Projects\TSRM" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
-# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /D "_DEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=1 /YX /FD /GZ /c
-# ADD BASE RSC /l 0x40d /d "_DEBUG"
-# ADD RSC /l 0x40d /d "_DEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TS"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "TSRM___Win32_Release_TS"
-# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TS"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS"
-# PROP Intermediate_Dir "Release_TS"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TS_inline"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "TSRM___Win32_Release_TS_inline"
-# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TS_inline"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TS_inline"
-# PROP Intermediate_Dir "Release_TS_inline"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "TSRM_EXPORTS" /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TSDbg"
-
-# PROP BASE Use_MFC 0
-# PROP BASE Use_Debug_Libraries 0
-# PROP BASE Output_Dir "TSRM___Win32_Release_TSDbg"
-# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TSDbg"
-# PROP BASE Target_Dir ""
-# PROP Use_MFC 0
-# PROP Use_Debug_Libraries 0
-# PROP Output_Dir "Release_TSDbg"
-# PROP Intermediate_Dir "Release_TSDbg"
-# PROP Target_Dir ""
-# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
-# ADD CPP /nologo /MD /W3 /GX /Zi /Od /I "." /D "NDEBUG" /D "ZTS" /D "_LIB" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D TSRM_DEBUG=0 /YX /FD /c
-# ADD BASE RSC /l 0x40d /d "NDEBUG"
-# ADD RSC /l 0x40d /d "NDEBUG"
-BSC32=bscmake.exe
-# ADD BASE BSC32 /nologo
-# ADD BSC32 /nologo
-LIB32=link.exe -lib
-# ADD BASE LIB32 /nologo
-# ADD LIB32 /nologo
-
-!ENDIF
-
-# Begin Target
-
-# Name "TSRM - Win32 Debug_TS"
-# Name "TSRM - Win32 Release_TS"
-# Name "TSRM - Win32 Release_TS_inline"
-# Name "TSRM - Win32 Release_TSDbg"
-# Begin Group "Source Files"
-
-# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
-# Begin Source File
-
-SOURCE=.\TSRM.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_strtok_r.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_virtual_cwd.c
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_win32.c
-# End Source File
-# End Group
-# Begin Group "Header Files"
-
-# PROP Default_Filter "h;hpp;hxx;hm;inl"
-# Begin Source File
-
-SOURCE=.\readdir.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\TSRM.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_config.w32.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_config_common.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_strtok_r.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_virtual_cwd.h
-# End Source File
-# Begin Source File
-
-SOURCE=.\tsrm_win32.h
-# End Source File
-# End Group
-# End Target
-# End Project
View
143 TSRM/TSRM.h
@@ -1,143 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | Thread Safe Resource Manager |
- +----------------------------------------------------------------------+
- | Copyright (c) 1999, 2000, Andi Gutmans, Sascha Schumann, Zeev Suraski|
- | This source file is subject to the TSRM license, that is bundled |
- | with this package in the file LICENSE |
- +----------------------------------------------------------------------+
- | Authors: Zeev Suraski <zeev@zend.com> |
- +----------------------------------------------------------------------+
-*/
-
-#ifndef TSRM_H
-#define TSRM_H
-
-#ifdef HAVE_CONFIG_H
-# include "tsrm_config.h"
-#endif
-
-#ifdef WIN32
-# define TSRM_WIN32
-#endif
-
-#ifdef TSRM_WIN32
-# ifdef TSRM_EXPORTS
-# define TSRM_API __declspec(dllexport)
-# else
-# define TSRM_API __declspec(dllimport)
-# endif
-#else
-# define TSRM_API
-#endif
-
-/* Only compile multi-threading functions if we're in ZTS mode */
-#ifdef ZTS
-
-#ifdef TSRM_WIN32
-# include <windows.h>
-#elif defined(GNUPTH)
-# include <pth.h>
-#elif defined(PTHREADS)
-# include <pthread.h>
-#elif defined(TSRM_ST)
-# include <st.h>
-#endif
-
-typedef int ts_rsrc_id;
-
-/* Define THREAD_T and MUTEX_T */
-#ifdef TSRM_WIN32
-# define THREAD_T DWORD
-# define MUTEX_T CRITICAL_SECTION *
-#elif defined(GNUPTH)
-# define THREAD_T pth_t
-# define MUTEX_T pth_mutex_t *
-#elif defined(PTHREADS)
-# define THREAD_T pthread_t
-# define MUTEX_T pthread_mutex_t *
-#elif defined(NSAPI)
-# define THREAD_T SYS_THREAD
-# define MUTEX_T CRITICAL
-#elif defined(PI3WEB)
-# define THREAD_T PIThread *
-# define MUTEX_T PISync *
-#elif defined(TSRM_ST)
-# define THREAD_T st_thread_t
-# define MUTEX_T st_mutex_t
-#endif
-
-typedef void (*ts_allocate_ctor)(void *, void ***);
-typedef void (*ts_allocate_dtor)(void *, void ***);
-
-#define THREAD_HASH_OF(thr,ts) (unsigned long)thr%(unsigned long)ts
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* startup/shutdown */
-TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_level, char *debug_filename);
-TSRM_API void tsrm_shutdown(void);
-
-/* allocates a new thread-safe-resource id */
-TSRM_API ts_rsrc_id ts_allocate_id(ts_rsrc_id *rsrc_id, size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor);
-
-/* fetches the requested resource for the current thread */
-TSRM_API void *ts_resource_ex(ts_rsrc_id id, THREAD_T *th_id);
-#define ts_resource(id) ts_resource_ex(id, NULL)
-
-/* frees all resources allocated for the current thread */
-TSRM_API void ts_free_thread(void);
-
-/* deallocates all occurrences of a given id */
-TSRM_API void ts_free_id(ts_rsrc_id id);
-
-
-/* Debug support */
-#define TSRM_ERROR_LEVEL_ERROR 1
-#define TSRM_ERROR_LEVEL_CORE 2
-#define TSRM_ERROR_LEVEL_INFO 3
-
-typedef void (*tsrm_thread_begin_func_t)(THREAD_T thread_id, void ***tsrm_ls);
-typedef void (*tsrm_thread_end_func_t)(THREAD_T thread_id, void ***tsrm_ls);
-
-
-TSRM_API int tsrm_error(int level, const char *format, ...);
-TSRM_API void tsrm_error_set(int level, char *debug_filename);
-
-/* utility functions */
-TSRM_API THREAD_T tsrm_thread_id(void);
-TSRM_API MUTEX_T tsrm_mutex_alloc(void);
-TSRM_API void tsrm_mutex_free(MUTEX_T mutexp);
-TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp);
-TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp);
-
-TSRM_API void *tsrm_set_new_thread_begin_handler(tsrm_thread_begin_func_t new_thread_begin_handler);
-TSRM_API void *tsrm_set_new_thread_end_handler(tsrm_thread_end_func_t new_thread_end_handler);
-
-#define TSRM_SHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)+1)
-#define TSRM_UNSHUFFLE_RSRC_ID(rsrc_id) ((rsrc_id)-1)
-
-#define TSRMLS_FETCH() void ***tsrm_ls = (void ***) ts_resource_ex(0, NULL)
-#define TSRMG(id, type, element) (((type) (*((void ***) tsrm_ls))[TSRM_UNSHUFFLE_RSRC_ID(id)])->element)
-#define TSRMLS_D void ***tsrm_ls
-#define TSRMLS_DC , TSRMLS_D
-#define TSRMLS_C tsrm_ls
-#define TSRMLS_CC , TSRMLS_C
-
-#ifdef __cplusplus
-}
-#endif
-
-#else /* non ZTS */
-
-#define TSRMLS_FETCH()
-#define TSRMLS_D void
-#define TSRMLS_DC
-#define TSRMLS_C
-#define TSRMLS_CC
-
-#endif /* ZTS */
-
-#endif /* TSRM_H */
View
1  TSRM/acconfig.h
@@ -1 +0,0 @@
-#undef PTHREADS
View
5 TSRM/acinclude.m4
@@ -1,5 +0,0 @@
-
-AC_DEFUN(AM_SET_LIBTOOL_VARIABLE,[
- LIBTOOL='$(SHELL) $(top_builddir)/libtool $1'
-])
-
View
43 TSRM/build.mk
@@ -1,43 +0,0 @@
-# Makefile to generate build tools
-#
-# Standard usage:
-# make -f build.mk
-#
-# Written by Sascha Schumann
-#
-# $Id$
-
-
-LT_TARGETS = ltmain.sh ltconfig
-
-config_h_in = tsrm_config.h.in
-
-makefile_am_files = Makefile.am
-makefile_in_files = $(makefile_am_files:.am=.in)
-makefile_files = $(makefile_am_files:e.am=e)
-
-targets = $(makefile_in_files) $(LT_TARGETS) configure $(config_h_in)
-
-all: $(targets)
-
-clean:
- rm -f $(targets)
-
-$(LT_TARGETS):
- rm -f $(LT_TARGETS)
- libtoolize --automake $(AMFLAGS) -f
-
-$(makefile_in_files): $(makefile_am_files)
- automake -a -i $(AMFLAGS) $(makefile_files)
-
-aclocal.m4: configure.in acinclude.m4
- aclocal
-
-$(config_h_in): configure.in acconfig.h
-# explicitly remove target since autoheader does not seem to work
-# correctly otherwise (timestamps are not updated)
- @rm -f $@
- autoheader
-
-configure: aclocal.m4 configure.in
- autoconf
View
33 TSRM/buildconf
@@ -1,33 +0,0 @@
-#!/bin/sh
-
-case "$1" in
---copy)
- automake_flags=--copy
- shift
-;;
-esac
-
-libtoolize --force --automake $automake_flags
-
-mv aclocal.m4 aclocal.m4.old 2>/dev/null
-aclocal
-if cmp aclocal.m4.old aclocal.m4 > /dev/null 2>&1; then
- echo "buildconf: keeping ${1}aclocal.m4"
- mv aclocal.m4.old aclocal.m4
-else
- echo "buildconf: created or modified ${1}aclocal.m4"
-fi
-
-autoheader
-
-automake --add-missing --include-deps $automake_flags
-
-mv configure configure.old 2>/dev/null
-autoconf
-if cmp configure.old configure > /dev/null 2>&1; then
- echo "buildconf: keeping ${1}configure"
- mv configure.old configure
-else
- echo "buildconf: created or modified ${1}configure"
-fi
-
View
31 TSRM/configure.in
@@ -1,31 +0,0 @@
-dnl $Id$
-dnl
-dnl Minimalistic configure.in for TSRM.
-dnl
-
-AC_INIT(TSRM.c)
-AM_INIT_AUTOMAKE(TSRM, 1.0, nodefine)
-AM_CONFIG_HEADER(tsrm_config.h)
-
-sinclude(tsrm.m4)
-
-TSRM_BASIC_CHECKS
-TSRM_THREADS_CHECKS
-
-AM_PROG_LIBTOOL
-if test "$enable_debug" != "yes"; then
- AM_SET_LIBTOOL_VARIABLE([--silent])
-fi
-
-dnl TSRM_PTHREAD
-
-AC_CHECK_HEADERS(
-utime.h \
-dirent.h \
-stdarg.h \
-alloca.h \
-unistd.h \
-limits.h
-)
-
-AC_OUTPUT(Makefile)
View
44 TSRM/readdir.h
@@ -1,44 +0,0 @@
-#ifndef READDIR_H
-#define READDIR_H
-
-
-/*
- * Structures and types used to implement opendir/readdir/closedir
- * on Windows 95/NT.
- */
-
-#include <io.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-
-
-/* struct dirent - same as Unix */
-
-struct dirent {
- long d_ino; /* inode (always 1 in WIN32) */
- off_t d_off; /* offset to this dirent */
- unsigned short d_reclen; /* length of d_name */
- char d_name[_MAX_FNAME + 1]; /* filename (null terminated) */
-};
-
-
-/* typedef DIR - not the same as Unix */
-typedef struct {
- long handle; /* _findfirst/_findnext handle */
- short offset; /* offset into directory */
- short finished; /* 1 if there are not more files */
- struct _finddata_t fileinfo; /* from _findfirst/_findnext */
- char *dir; /* the dir we are reading */
- struct dirent dent; /* the dirent to return */
-} DIR;
-
-/* Function prototypes */
-DIR *opendir(const char *);
-struct dirent *readdir(DIR *);
-int readdir_r(DIR *, struct dirent *, struct dirent **);
-int closedir(DIR *);
-void rewinddir(DIR *);
-
-
-#endif /* READDIR_H */
View
160 TSRM/threads.m4
@@ -1,160 +0,0 @@
-dnl Copyright (c) 1999, 2000 Sascha Schumann. All rights reserved.
-dnl
-dnl Redistribution and use in source and binary forms, with or without
-dnl modification, are permitted provided that the following conditions
-dnl are met:
-dnl
-dnl 1. Redistributions of source code must retain the above copyright
-dnl notice, this list of conditions and the following disclaimer.
-dnl
-dnl 2. Redistributions in binary form must reproduce the above copyright
-dnl notice, this list of conditions and the following disclaimer in
-dnl the documentation and/or other materials provided with the
-dnl distribution.
-dnl
-dnl THIS SOFTWARE IS PROVIDED BY SASCHA SCHUMANN ``AS IS'' AND ANY
-dnl EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-dnl PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SASCHA SCHUMANN OR
-dnl HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-dnl NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-dnl LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-dnl STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-dnl ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-dnl OF THE POSSIBILITY OF SUCH DAMAGE.
-
-dnl
-dnl PTHREADS_FLAGS
-dnl
-dnl Set some magic defines to achieve POSIX threads conformance
-dnl
-AC_DEFUN(PTHREADS_FLAGS,[
- if test -z "$host_alias" && test -n "$host"; then
- host_alias=$host
- fi
- if test -z "$host_alias"; then
- AC_MSG_ERROR(host_alias is not set. Make sure to run config.guess)
- fi
- case $host_alias in
- *solaris*)
- PTHREAD_FLAGS="-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT";;
- *freebsd*)
- PTHREAD_FLAGS="-D_REENTRANT -D_THREAD_SAFE";;
- *linux*)
- PTHREAD_FLAGS=-D_REENTRANT;;
- *aix*)
- PTHREAD_FLAGS=-D_THREAD_SAFE;;
- *irix*)
- PTHREAD_FLAGS=-D_POSIX_THREAD_SAFE_FUNCTIONS;;
- *hpux*)
- PTHREAD_FLAGS=-D_REENTRANT;;
- *sco*)
- PTHREAD_FLAGS=-D_REENTRANT;;
-dnl Solves sigwait() problem, creates problems with u_long etc.
-dnl PTHREAD_FLAGS="-D_REENTRANT -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=199506 -D_XOPEN_SOURCE_EXTENDED=1";;
- esac
-
- if test -n "$PTHREAD_FLAGS"; then
- CPPFLAGS="$CPPFLAGS $PTHREAD_FLAGS"
- fi
-])dnl
-dnl
-dnl PTHREADS_CHECK_COMPILE
-dnl
-dnl Check whether the current setup can use POSIX threads calls
-dnl
-AC_DEFUN(PTHREADS_CHECK_COMPILE, [
-AC_TRY_RUN( [
-#include <pthread.h>
-#include <stddef.h>
-
-void *thread_routine(void *data) {
- return data;
-}
-
-int main() {
- pthread_t thd;
- pthread_mutexattr_t mattr;
- int data = 1;
- pthread_mutexattr_init(&mattr);
- return pthread_create(&thd, NULL, thread_routine, &data);
-} ], [
- pthreads_working=yes
- ], [
- pthreads_working=no
- ], pthreads_working=no ) ] )dnl
-dnl
-dnl PTHREADS_CHECK()
-dnl
-dnl Try to find a way to enable POSIX threads
-dnl
-dnl Magic flags
-dnl -kthread gcc (FreeBSD)
-dnl -Kthread UDK cc (UnixWare)
-dnl -mt WorkShop cc (Solaris)
-dnl -mthreads gcc (AIX)
-dnl -pthread gcc (Linux, FreeBSD, NetBSD, OpenBSD)
-dnl -pthreads gcc (Solaris)
-dnl -qthreaded AIX cc V5
-dnl -threads gcc (HP-UX)
-dnl
-AC_DEFUN(PTHREADS_CHECK,[
-
-save_CFLAGS=$CFLAGS
-save_LIBS=$LIBS
-PTHREADS_ASSIGN_VARS
-PTHREADS_CHECK_COMPILE
-LIBS=$save_LIBS
-CFLAGS=$save_CFLAGS
-
-AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
-ac_cv_pthreads_cflags=
-if test "$pthreads_working" != "yes"; then
- for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
- ac_save=$CFLAGS
- CFLAGS="$CFLAGS $flag"
- PTHREADS_CHECK_COMPILE
- CFLAGS=$ac_save
- if test "$pthreads_working" = "yes"; then
- ac_cv_pthreads_cflags=$flag
- break
- fi
- done
-fi
-])
-
-AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
-ac_cv_pthreads_lib=
-if test "$pthreads_working" != "yes"; then
- for lib in pthread pthreads c_r; do
- ac_save=$LIBS
- LIBS="$LIBS -l$lib"
- PTHREADS_CHECK_COMPILE
- LIBS=$ac_save
- if test "$pthreads_working" = "yes"; then
- ac_cv_pthreads_lib=$lib
- break
- fi
- done
-fi
-])
-
-if test "$pthreads_working" = "yes"; then
- threads_result="POSIX-Threads found"
-else
- threads_result="POSIX-Threads not found"
-fi
-])dnl
-dnl
-dnl
-AC_DEFUN(PTHREADS_ASSIGN_VARS,[
-if test -n "$ac_cv_pthreads_lib"; then
- LIBS="$LIBS -l$ac_cv_pthreads_lib"
-fi
-
-if test -n "$ac_cv_pthreads_cflags"; then
- CFLAGS="$CFLAGS $ac_cv_pthreads_cflags"
-fi
-])dnl
View
124 TSRM/tsrm.m4
@@ -1,124 +0,0 @@
-
-dnl TSRM_CHECK_GCC_ARG(ARG, ACTION-IF-FOUND, ACTION-IF-NOT_FOUND)
-AC_DEFUN(TSRM_CHECK_GCC_ARG,[
- gcc_arg_name=[ac_cv_gcc_arg]translit($1,A-Z-,a-z_)
- AC_CACHE_CHECK([whether $CC supports $1], [ac_cv_gcc_arg]translit($1,A-Z-,a-z_), [
- echo 'void somefunc() { };' > conftest.c
- cmd='$CC $1 -c conftest.c'
- if eval $cmd 2>&1 | egrep -e $1 >/dev/null ; then
- ac_result=no
- else
- ac_result=yes
- fi
- eval $gcc_arg_name=$ac_result
- rm -f conftest.*
- ])
- if eval test "\$$gcc_arg_name" = "yes"; then
- $2
- else
- :
- $3
- fi
-])
-
-AC_DEFUN(TSRM_BASIC_CHECKS,[
-
-AC_REQUIRE([AC_PROG_CC])dnl
-dnl AC_REQUIRE([AM_PROG_CC_STDC])dnl
-AC_REQUIRE([AC_PROG_CC_C_O])dnl
-AC_REQUIRE([AC_PROG_RANLIB])dnl
-
-AC_CHECK_HEADERS(stdarg.h)
-
-])
-
-
-AC_DEFUN(TSRM_CHECK_PTH,[
-
-AC_MSG_CHECKING(for GNU Pth)
-PTH_PREFIX="`$1 --prefix`"
-if test -z "$PTH_PREFIX"; then
- AC_MSG_RESULT(Please check your Pth installation)
-fi
-
-CPPFLAGS="$CPPFLAGS `$1 --cflags`"
-LDFLAGS="$LDFLAGS `$1 --ldflags`"
-LIBS="$LIBS `$1 --libs`"
-
-AC_DEFINE(GNUPTH, 1, [Whether you use GNU Pth])
-AC_MSG_RESULT(yes - installed in $PTH_PREFIX)
-
-])
-
-AC_DEFUN(TSRM_CHECK_ST,[
- if test -r "$1/include/st.h"; then
- CPPFLAGS="$CPPFLAGS -I$1/include"
- LDFLAGS="$LDFLAGS -L$1/lib"
- elif test -r "$1/st.h"; then
- CPPFLAGS="$CPPFLAGS -I$1"
- LDFLAGS="$LDFLAGS -L$1"
- fi
- AC_CHECK_HEADERS(st.h,[],[
- AC_MSG_ERROR([Sorry[,] I was unable to locate the State Threads header file. Please specify the prefix using --with-tsrm-st=/prefix])
- ])
- LIBS="$LIBS -lst"
- AC_MSG_CHECKING(for SGI's State Threads)
- AC_MSG_RESULT(yes)
- AC_DEFINE(TSRM_ST, 1, [ ])
-])
-
-sinclude(threads.m4)
-sinclude(TSRM/threads.m4)
-
-AC_DEFUN(TSRM_CHECK_PTHREADS,[
-
-PTHREADS_CHECK
-
-if test "$pthreads_working" != "yes"; then
- AC_MSG_ERROR(Your system seems to lack POSIX threads.)
-fi
-
-AC_DEFINE(PTHREADS, 1, Whether to use Pthreads)
-
-AC_MSG_CHECKING(for POSIX threads)
-AC_MSG_RESULT(yes)
-])
-
-
-AC_DEFUN(TSRM_THREADS_CHECKS,[
-
-dnl For the thread implementations, we always use --with-*
-dnl to maintain consistency
-
-AC_ARG_WITH(tsrm-pth,
-[ --with-tsrm-pth[=pth-config] Use GNU Pth.],[
- TSRM_PTH=$withval
-],[
- TSRM_PTH=no
-])
-
-AC_ARG_WITH(tsrm-st,
-[ --with-tsrm-st],[
- TSRM_ST=$withval
-],[
- TSRM_ST=no
-])
-
-AC_ARG_WITH(tsrm-pthreads,
-[ --with-tsrm-pthreads Use POSIX threads (default)],[
- TSRM_PTHREADS=$withval
-],[
- TSRM_PTHREADS=yes
-])
-
-test "$TSRM_PTH" = "yes" && TSRM_PTH=pth-config
-
-if test "$TSRM_PTH" != "no"; then
- TSRM_CHECK_PTH($TSRM_PTH)
-elif test "$TSRM_ST" != "no"; then
- TSRM_CHECK_ST($TSRM_ST)
-elif test "$TSRM_PTHREADS" != "no"; then
- TSRM_CHECK_PTHREADS
-fi
-
-])
View
15 TSRM/tsrm_config.w32.h
@@ -1,15 +0,0 @@
-#ifndef TSRM_CONFIG_W32_H
-#define TSRM_CONFIG_W32_H
-
-#define HAVE_UTIME 1
-#define HAVE_ALLOCA 1
-
-#undef inline
-#ifdef ZEND_WIN32_FORCE_INLINE
-# define inline __forceinline
-#else
-# define inline
-#endif
-
-
-#endif
View
47 TSRM/tsrm_config_common.h
@@ -1,47 +0,0 @@
-#ifndef TSRM_CONFIG_COMMON_H
-#define TSRM_CONFIG_COMMON_H
-
-#if WINNT|WIN32
-# define TSRM_WIN32
-#endif
-
-#ifndef TSRM_WIN32
-# include "tsrm_config.h"
-# include <sys/param.h>
-#else
-# include "tsrm_config.w32.h"
-#endif
-
-#ifdef TSRM_WIN32
-#include <malloc.h>
-#endif
-
-#if HAVE_ALLOCA_H
-#include <alloca.h>
-#endif
-
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#if HAVE_LIMITS_H
-#include <limits.h>
-#endif
-
-#ifndef MAXPATHLEN
-# ifdef PATH_MAX
-# define MAXPATHLEN PATH_MAX
-# else
-# define MAXPATHLEN 256
-# endif
-#endif
-
-#if (HAVE_ALLOCA || (defined (__GNUC__) && __GNUC__ >= 2))
-# define tsrm_do_alloca(p) alloca(p)
-# define tsrm_free_alloca(p)
-#else
-# define tsrm_do_alloca(p) malloc(p)
-# define tsrm_free_alloca(p) free(p)
-#endif
-
-#endif /* TSRM_CONFIG_COMMON_H */
View
63 TSRM/tsrm_strtok_r.c
@@ -1,63 +0,0 @@
-#include <stdio.h>
-
-#include "tsrm_config_common.h"
-#include "tsrm_strtok_r.h"
-
-static inline int in_character_class(char ch, const char *delim)
-{
- while (*delim) {
- if (*delim == ch) {
- return 1;
- }
- delim++;
- }
- return 0;
-}
-
-char *tsrm_strtok_r(char *s, const char *delim, char **last)
-{
- char *token;
-
- if (s == NULL) {
- s = *last;
- }
-
- while (*s && in_character_class(*s, delim)) {
- s++;
- }
- if (!*s) {
- return NULL;
- }
-
- token = s;
-
- while (*s && !in_character_class(*s, delim)) {
- s++;
- }
- if (!*s) {
- *last = s;
- } else {
- *s = '\0';
- *last = s + 1;
- }
- return token;
-}
-
-#if 0
-
-main()
-{
- char foo[] = "/foo/bar//\\barbara";
- char *last;
- char *token;
-
- token = tsrm_strtok_r(foo, "/\\", &last);
- while (token) {
- printf ("Token = '%s'\n", token);
- token = tsrm_strtok_r(NULL, "/\\", &last);
- }
-
- return 0;
-}
-
-#endif
View
6 TSRM/tsrm_strtok_r.h
@@ -1,6 +0,0 @@
-#ifndef TSRM_STRTOK_R
-#define TSRM_STRTOK_R
-
-char *tsrm_strtok_r(char *s, const char *delim, char **last);
-
-#endif
View
773 TSRM/tsrm_virtual_cwd.c
@@ -1,773 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@zend.com> |
- | Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <string.h>
-#include <stdio.h>
-#include <limits.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <fcntl.h>
-
-#include "tsrm_virtual_cwd.h"
-#include "tsrm_strtok_r.h"
-
-#ifdef TSRM_WIN32
-#include <io.h>
-#include "tsrm_win32.h"
-#endif
-
-#define VIRTUAL_CWD_DEBUG 0
-
-#include "TSRM.h"
-
-/* Only need mutex for popen() in Windows because it doesn't chdir() on UNIX */
-#if defined(TSRM_WIN32) && defined(ZTS)
-MUTEX_T cwd_mutex;
-#endif
-
-#ifdef ZTS
-static ts_rsrc_id cwd_globals_id;
-#else
-static virtual_cwd_globals cwd_globals;
-#endif
-
-cwd_state main_cwd_state; /* True global */
-
-#ifndef TSRM_WIN32
-#include <unistd.h>
-#else
-#include <direct.h>
-#endif
-
-#ifndef S_ISDIR
-#define S_ISDIR(mode) ((mode) & _S_IFDIR)
-#endif
-
-#ifndef S_ISREG
-#define S_ISREG(mode) ((mode) & _S_IFREG)
-#endif
-
-#ifdef TSRM_WIN32
-#define tsrm_strtok_r(a,b,c) strtok((a),(b))
-#define TOKENIZER_STRING "/\\"
-
-static int php_check_dots(const char *element, int n)
-{
- while (n-- > 0) if (element[n] != '.') break;
-
- return (n != -1);
-}
-
-#define IS_DIRECTORY_UP(element, len) \
- (len >= 2 && !php_check_dots(element, len))
-
-#define IS_DIRECTORY_CURRENT(element, len) \
- (len == 1 && ptr[0] == '.')
-
-
-#else
-#define TOKENIZER_STRING "/"
-#endif
-
-
-/* default macros */
-
-#ifndef IS_DIRECTORY_UP
-#define IS_DIRECTORY_UP(element, len) \
- (len == 2 && memcmp(element, "..", 2) == 0)
-#endif
-
-#ifndef IS_DIRECTORY_CURRENT
-#define IS_DIRECTORY_CURRENT(element, len) \
- (len == 1 && ptr[0] == '.')
-#endif
-
-/* define this to check semantics */
-#define IS_DIR_OK(s) (1)
-
-#ifndef IS_DIR_OK
-#define IS_DIR_OK(state) (php_is_dir_ok(state) == 0)
-#endif
-
-
-#define CWD_STATE_COPY(d, s) \
- (d)->cwd_length = (s)->cwd_length; \
- (d)->cwd = (char *) malloc((s)->cwd_length+1); \
- memcpy((d)->cwd, (s)->cwd, (s)->cwd_length+1);
-
-#define CWD_STATE_FREE(s) \
- free((s)->cwd);
-
-static int php_is_dir_ok(const cwd_state *state)
-{
- struct stat buf;
-
- if (stat(state->cwd, &buf) == 0 && S_ISDIR(buf.st_mode))
- return (0);
-
- return (1);
-}
-
-static int php_is_file_ok(const cwd_state *state)
-{
- struct stat buf;
-
- if (stat(state->cwd, &buf) == 0 && S_ISREG(buf.st_mode))
- return (0);
-
- return (1);
-}
-
-static void cwd_globals_ctor(virtual_cwd_globals *cwd_globals TSRMLS_DC)
-{
- CWD_STATE_COPY(&cwd_globals->cwd, &main_cwd_state);
-}
-
-static void cwd_globals_dtor(virtual_cwd_globals *cwd_globals TSRMLS_DC)
-{
- CWD_STATE_FREE(&cwd_globals->cwd);
-}
-
-static char *tsrm_strndup(const char *s, size_t length)
-{
- char *p;
-
- p = (char *) malloc(length+1);
- if (!p) {
- return (char *)NULL;
- }
- if (length) {
- memcpy(p,s,length);
- }
- p[length]=0;
- return p;
-}
-
-CWD_API void virtual_cwd_startup(void)
-{
- char cwd[MAXPATHLEN];
- char *result;
-
- result = getcwd(cwd, sizeof(cwd));
- if (!result) {
- cwd[0] = '\0';
- }
- main_cwd_state.cwd = strdup(cwd);
- main_cwd_state.cwd_length = strlen(cwd);
-
-#ifdef ZTS
- ts_allocate_id(&cwd_globals_id, sizeof(virtual_cwd_globals), (ts_allocate_ctor) cwd_globals_ctor, (ts_allocate_dtor) cwd_globals_dtor);
-#else
- cwd_globals_ctor(&cwd_globals TSRMLS_CC);
-#endif
-
-#if defined(TSRM_WIN32) && defined(ZTS)
- cwd_mutex = tsrm_mutex_alloc();
-#endif
-}
-
-CWD_API void virtual_cwd_shutdown(void)
-{
-#ifndef ZTS
- cwd_globals_dtor(&cwd_globals TSRMLS_CC);
-#endif
-#if defined(TSRM_WIN32) && defined(ZTS)
- tsrm_mutex_free(cwd_mutex);
-#endif
-
- free(main_cwd_state.cwd); /* Don't use CWD_STATE_FREE because the non global states will probably use emalloc()/efree() */
-}
-
-CWD_API char *virtual_getcwd_ex(size_t *length TSRMLS_DC)
-{
- cwd_state *state;
-
- state = &CWDG(cwd);
-
- if (state->cwd_length == 0) {
- char *retval;
-
- *length = 1;
- retval = (char *) malloc(2);
- retval[0] = DEFAULT_SLASH;
- retval[1] = '\0';
- return retval;
- }
-
-#ifdef TSRM_WIN32
- /* If we have something like C: */
- if (state->cwd_length == 2 && state->cwd[state->cwd_length-1] == ':') {
- char *retval;
-
- *length = state->cwd_length+1;
- retval = (char *) malloc(*length+1);
- memcpy(retval, state->cwd, *length);
- retval[*length-1] = DEFAULT_SLASH;
- retval[*length] = '\0';
- return retval;
- }
-#endif
- *length = state->cwd_length;
- return strdup(state->cwd);
-}
-
-
-/* Same semantics as UNIX getcwd() */
-CWD_API char *virtual_getcwd(char *buf, size_t size TSRMLS_DC)
-{
- size_t length;
- char *cwd;
-
- cwd = virtual_getcwd_ex(&length TSRMLS_CC);
-
- if (buf == NULL) {
- return cwd;
- }
- if (length > size-1) {
- free(cwd);
- errno = ERANGE; /* Is this OK? */
- return NULL;
- }
- memcpy(buf, cwd, length+1);
- free(cwd);
- return buf;
-}
-
-/* Resolve path relatively to state and put the real path into state */
-/* returns 0 for ok, 1 for error */
-CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path)
-{
- int path_length = strlen(path);
- char *ptr, *path_copy;
- char *tok = NULL;
- int ptr_length;
- cwd_state *old_state;
- int ret = 0;
- int copy_amount = -1;
- char *free_path;
- unsigned char is_absolute = 0;
-#ifndef TSRM_WIN32
- char resolved_path[MAXPATHLEN];
-#endif
-
- if (path_length == 0)
- return (0);
-
-#if !defined(TSRM_WIN32) && !defined(__BEOS__)
- if (IS_ABSOLUTE_PATH(path, path_length)) {
- if (realpath(path, resolved_path)) {
- path = resolved_path;
- path_length = strlen(path);
- }
- } else { /* Concat current directory with relative path and then run realpath() on it */
- char *tmp;
- char *ptr;
-
- ptr = tmp = (char *) malloc(state->cwd_length+path_length+sizeof("/"));
- if (!tmp) {
- return 1;
- }
- memcpy(ptr, state->cwd, state->cwd_length);
- ptr += state->cwd_length;
- *ptr++ = DEFAULT_SLASH;
- memcpy(ptr, path, path_length);
- ptr += path_length;
- *ptr = '\0';
- if (realpath(tmp, resolved_path)) {
- path = resolved_path;
- path_length = strlen(path);
- }
- free(tmp);
- }
-#endif
- free_path = path_copy = tsrm_strndup(path, path_length);
-
- old_state = (cwd_state *) malloc(sizeof(cwd_state));
- CWD_STATE_COPY(old_state, state);
-#if VIRTUAL_CWD_DEBUG
- fprintf(stderr,"cwd = %s path = %s\n", state->cwd, path);
-#endif
- if (IS_ABSOLUTE_PATH(path_copy, path_length)) {
- copy_amount = COPY_WHEN_ABSOLUTE;
- is_absolute = 1;
-#ifdef TSRM_WIN32
- } else if (IS_UNC_PATH(path_copy, path_length)) {
- copy_amount = 2;
- is_absolute = 1;
- } else if (IS_SLASH(path_copy[0])) {
- copy_amount = 2;
-#endif
- }
-
- if (copy_amount != -1) {
- state->cwd = (char *) realloc(state->cwd, copy_amount + 1);
- if (copy_amount) {
- if (is_absolute) {
- memcpy(state->cwd, path_copy, copy_amount);
- path_copy += copy_amount;
- } else {
- memcpy(state->cwd, old_state->cwd, copy_amount);
- }
- }
- state->cwd[copy_amount] = '\0';
- state->cwd_length = copy_amount;
- }
-
-
- ptr = tsrm_strtok_r(path_copy, TOKENIZER_STRING, &tok);
- while (ptr) {
- ptr_length = strlen(ptr);
-
- if (IS_DIRECTORY_UP(ptr, ptr_length)) {
- char save;
-
- save = DEFAULT_SLASH;
-
-#define PREVIOUS state->cwd[state->cwd_length - 1]
-
- while (IS_ABSOLUTE_PATH(state->cwd, state->cwd_length) &&
- !IS_SLASH(PREVIOUS)) {
- save = PREVIOUS;
- PREVIOUS = '\0';
- state->cwd_length--;
- }
-
- if (!IS_ABSOLUTE_PATH(state->cwd, state->cwd_length)) {
- state->cwd[state->cwd_length++] = save;
- state->cwd[state->cwd_length] = '\0';
- } else {
- PREVIOUS = '\0';
- state->cwd_length--;
- }
- } else if (!IS_DIRECTORY_CURRENT(ptr, ptr_length)) {
- state->cwd = (char *) realloc(state->cwd, state->cwd_length+ptr_length+1+1);
-#ifdef TSRM_WIN32
- /* Windows 9x will consider C:\\Foo as a network path. Avoid it. */
- if (state->cwd[state->cwd_length-1]!='\\' && state->cwd[state->cwd_length-1]!='/') {
- state->cwd[state->cwd_length++] = DEFAULT_SLASH;
- }
-#else
- state->cwd[state->cwd_length++] = DEFAULT_SLASH;
-#endif
- memcpy(&state->cwd[state->cwd_length], ptr, ptr_length+1);
- state->cwd_length += ptr_length;
- }
- ptr = tsrm_strtok_r(NULL, TOKENIZER_STRING, &tok);
- }
-
- if (state->cwd_length == COPY_WHEN_ABSOLUTE) {
- state->cwd = (char *) realloc(state->cwd, state->cwd_length+1+1);
- state->cwd[state->cwd_length] = DEFAULT_SLASH;
- state->cwd[state->cwd_length+1] = '\0';
- state->cwd_length++;
- }
-
- if (verify_path && verify_path(state)) {
- CWD_STATE_FREE(state);
-
- *state = *old_state;
-
- ret = 1;
- } else {
- CWD_STATE_FREE(old_state);
- ret = 0;
- }
-
- free(old_state);
-
- free(free_path);
-#if VIRTUAL_CWD_DEBUG
- fprintf (stderr, "virtual_file_ex() = %s\n",state->cwd);
-#endif
- return (ret);
-}
-
-CWD_API int virtual_chdir(const char *path TSRMLS_DC)
-{
- return virtual_file_ex(&CWDG(cwd), path, php_is_dir_ok)?-1:0;
-}
-
-CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path TSRMLS_DC) TSRMLS_DC)
-{
- int length = strlen(path);
- char *temp;
- int retval;
-
- if (length == 0) {
- return 1; /* Can't cd to empty string */
- }
- while(--length >= 0 && !IS_SLASH(path[length])) {
- }
-
- if (length == -1) {
- /* No directory only file name */
- errno = ENOENT;
- return -1;
- }
-
- if (length == COPY_WHEN_ABSOLUTE && IS_ABSOLUTE_PATH(path, length+1)) { /* Also use trailing slash if this is absolute */
- length++;
- }
- temp = (char *) tsrm_do_alloca(length+1);
- memcpy(temp, path, length);
- temp[length] = 0;
-#if VIRTUAL_CWD_DEBUG
- fprintf (stderr, "Changing directory to %s\n", temp);
-#endif
- retval = p_chdir(temp TSRMLS_CC);
- tsrm_free_alloca(temp);
- return retval;
-}
-
-CWD_API char *virtual_realpath(const char *path, char *real_path TSRMLS_DC)
-{
- cwd_state new_state;
- int retval;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- retval = virtual_file_ex(&new_state, path, NULL);
-
- if (!retval) {
- int len = new_state.cwd_length>MAXPATHLEN-1?MAXPATHLEN-1:new_state.cwd_length;
- memcpy(real_path, new_state.cwd, len);
- real_path[len] = '\0';
- return real_path;
- }
-
- return NULL;
-}
-
-CWD_API int virtual_filepath_ex(const char *path, char **filepath, verify_path_func verify_path TSRMLS_DC)
-{
- cwd_state new_state;
- int retval;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- retval = virtual_file_ex(&new_state, path, verify_path);
-
- *filepath = new_state.cwd;
-
- return retval;
-
-}
-
-CWD_API int virtual_filepath(const char *path, char **filepath TSRMLS_DC)
-{
- return virtual_filepath_ex(path, filepath, php_is_file_ok TSRMLS_CC);
-}
-
-CWD_API FILE *virtual_fopen(const char *path, const char *mode TSRMLS_DC)
-{
- cwd_state new_state;
- FILE *f;
-
- if (path[0] == '\0') { /* Fail to open empty path */
- return NULL;
- }
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, path, NULL);
-
- f = fopen(new_state.cwd, mode);
-
- CWD_STATE_FREE(&new_state);
- return f;
-}
-
-#if HAVE_UTIME
-CWD_API int virtual_utime(const char *filename, struct utimbuf *buf TSRMLS_DC)
-{
- cwd_state new_state;
- int ret;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, filename, NULL);
-
- ret = utime(new_state.cwd, buf);
-
- CWD_STATE_FREE(&new_state);
- return ret;
-}
-#endif
-
-CWD_API int virtual_chmod(const char *filename, mode_t mode TSRMLS_DC)
-{
- cwd_state new_state;
- int ret;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, filename, NULL);
-
- ret = chmod(new_state.cwd, mode);
-
- CWD_STATE_FREE(&new_state);
- return ret;
-}
-
-#ifndef TSRM_WIN32
-CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group TSRMLS_DC)
-{
- cwd_state new_state;
- int ret;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, filename, NULL);
-
- ret = chown(new_state.cwd, owner, group);
-
- CWD_STATE_FREE(&new_state);
- return ret;
-}
-#endif
-
-CWD_API int virtual_open(const char *path TSRMLS_DC, int flags, ...)
-{
- cwd_state new_state;
- int f;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, path, NULL);
-
- if (flags & O_CREAT) {
- mode_t mode;
- va_list arg;
-
- va_start(arg, flags);
- mode = va_arg(arg, mode_t);
- va_end(arg);
-
- f = open(new_state.cwd, flags, mode);
- } else {
- f = open(new_state.cwd, flags);
- }
- CWD_STATE_FREE(&new_state);
- return f;
-}
-
-CWD_API int virtual_creat(const char *path, mode_t mode TSRMLS_DC)
-{
- cwd_state new_state;
- int f;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, path, NULL);
-
- f = creat(new_state.cwd, mode);
-
- CWD_STATE_FREE(&new_state);
- return f;
-}
-
-CWD_API int virtual_rename(char *oldname, char *newname TSRMLS_DC)
-{
- cwd_state old_state;
- cwd_state new_state;
- int retval;
-
- CWD_STATE_COPY(&old_state, &CWDG(cwd));
- virtual_file_ex(&old_state, oldname, NULL);
- oldname = old_state.cwd;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, newname, NULL);
- newname = new_state.cwd;
-
- retval = rename(oldname, newname);
-
- CWD_STATE_FREE(&old_state);
- CWD_STATE_FREE(&new_state);
-
- return retval;
-}
-
-CWD_API int virtual_stat(const char *path, struct stat *buf TSRMLS_DC)
-{
- cwd_state new_state;
- int retval;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, path, NULL);
-
- retval = stat(new_state.cwd, buf);
-
- CWD_STATE_FREE(&new_state);
- return retval;
-}
-
-#ifndef TSRM_WIN32
-
-CWD_API int virtual_lstat(const char *path, struct stat *buf TSRMLS_DC)
-{
- cwd_state new_state;
- int retval;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, path, NULL);
-
- retval = lstat(new_state.cwd, buf);
-
- CWD_STATE_FREE(&new_state);
- return retval;
-}
-
-#endif
-
-CWD_API int virtual_unlink(const char *path TSRMLS_DC)
-{
- cwd_state new_state;
- int retval;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, path, NULL);
-
- retval = unlink(new_state.cwd);
-
- CWD_STATE_FREE(&new_state);
- return retval;
-}
-
-CWD_API int virtual_mkdir(const char *pathname, mode_t mode TSRMLS_DC)
-{
- cwd_state new_state;
- int retval;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, pathname, NULL);
-
-#ifdef TSRM_WIN32
- retval = mkdir(new_state.cwd);
-#else
- retval = mkdir(new_state.cwd, mode);
-#endif
- CWD_STATE_FREE(&new_state);
- return retval;
-}
-
-CWD_API int virtual_rmdir(const char *pathname TSRMLS_DC)
-{
- cwd_state new_state;
- int retval;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, pathname, NULL);
-
- retval = rmdir(new_state.cwd);
-
- CWD_STATE_FREE(&new_state);
- return retval;
-}
-
-#ifdef TSRM_WIN32
-DIR *opendir(const char *name);
-#endif
-
-CWD_API DIR *virtual_opendir(const char *pathname TSRMLS_DC)
-{
- cwd_state new_state;
- DIR *retval;
-
- CWD_STATE_COPY(&new_state, &CWDG(cwd));
- virtual_file_ex(&new_state, pathname, NULL);
-
- retval = opendir(new_state.cwd);
-
- CWD_STATE_FREE(&new_state);
- return retval;
-}
-
-#ifndef TSRM_WIN32
-
-CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC)
-{
- int command_length;
- char *command_line;
- char *ptr;
- FILE *retval;
-
- command_length = strlen(command);
-
- ptr = command_line = (char *) malloc(command_length + sizeof("cd ; ") + CWDG(cwd).cwd_length+1);
- if (!command_line) {
- return NULL;
- }
- memcpy(ptr, "cd ", sizeof("cd ")-1);
- ptr += sizeof("cd ")-1;
-
- if (CWDG(cwd).cwd_length == 0) {
- *ptr++ = DEFAULT_SLASH;
- } else {
- memcpy(ptr, CWDG(cwd).cwd, CWDG(cwd).cwd_length);
- ptr += CWDG(cwd).cwd_length;
- }
-
- *ptr++ = ' ';
- *ptr++ = ';';
- *ptr++ = ' ';
-
- memcpy(ptr, command, command_length+1);
- retval = popen(command_line, type);
-
- free(command_line);
- return retval;
-}
-
-#else
-
-/* On Windows the trick of prepending "cd cwd; " doesn't work so we need to perform
- a real chdir() and mutex it
- */
-CWD_API FILE *virtual_popen(const char *command, const char *type TSRMLS_DC)
-{
- char prev_cwd[MAXPATHLEN];
- char *getcwd_result;
- FILE *retval;
-
- getcwd_result = getcwd(prev_cwd, MAXPATHLEN);
- if (!getcwd_result) {
- return NULL;
- }
-
-#ifdef ZTS
- tsrm_mutex_lock(cwd_mutex);
-#endif
-
- chdir(CWDG(cwd).cwd);
- retval = popen(command, type);
- chdir(prev_cwd);
-
-#ifdef ZTS
- tsrm_mutex_unlock(cwd_mutex);
-#endif
-
- return retval;
-}
-
-#endif
-
-
-/*
- * Local variables:
- * tab-width: 4
- * c-basic-offset: 4
- * End:
- */
View
215 TSRM/tsrm_virtual_cwd.h
@@ -1,215 +0,0 @@
-/*
- +----------------------------------------------------------------------+
- | PHP version 4.0 |
- +----------------------------------------------------------------------+
- | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
- +----------------------------------------------------------------------+
- | This source file is subject to version 2.02 of the PHP license, |
- | that is bundled with this package in the file LICENSE, and is |
- | available at through the world-wide-web at |
- | http://www.php.net/license/2_02.txt. |
- | If you did not receive a copy of the PHP license and are unable to |
- | obtain it through the world-wide-web, please send a note to |
- | license@php.net so we can mail you a copy immediately. |
- +----------------------------------------------------------------------+
- | Authors: Andi Gutmans <andi@zend.com> |
- | Sascha Schumann <sascha@schumann.cx> |
- +----------------------------------------------------------------------+
-*/
-
-/* $Id$ */
-
-#ifndef VIRTUAL_CWD_H
-#define VIRTUAL_CWD_H
-
-#include "TSRM.h"
-#include "tsrm_config_common.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <ctype.h>
-
-#ifdef HAVE_UTIME_H
-#include <utime.h>
-#endif
-
-#ifdef HAVE_STDARG_H
-#include <stdarg.h>
-#endif
-
-#ifndef TSRM_WIN32
-#include <unistd.h>
-#endif
-
-#ifdef TSRM_WIN32
-#include "readdir.h"
-#include <sys/utime.h>
-/* mode_t isn't defined on Windows */
-typedef unsigned short mode_t;
-
-#define DEFAULT_SLASH '\\'
-#define DEFAULT_DIR_SEPARATOR ';'
-#define IS_SLASH(c) ((c) == '/' || (c) == '\\')
-#define COPY_WHEN_ABSOLUTE 2
-#define IS_ABSOLUTE_PATH(path, len) \
- (len >= 2 && isalpha(path[0]) && path[1] == ':')
-#define IS_UNC_PATH(path, len) \
- (len >= 2 && IS_SLASH(path[0]) && IS_SLASH(path[1]))
-
-#else
-#ifdef HAVE_DIRENT_H
-#include <dirent.h>
-#endif
-
-#define DEFAULT_SLASH '/'
-#define DEFAULT_DIR_SEPARATOR ':'
-#define IS_SLASH(c) ((c) == '/')
-
-#endif
-
-
-#ifndef COPY_WHEN_ABSOLUTE
-#define COPY_WHEN_ABSOLUTE 0
-#endif
-
-#ifndef IS_ABSOLUTE_PATH
-#define IS_ABSOLUTE_PATH(path, len) \
- (IS_SLASH(path[0]))
-#endif
-
-#ifdef TSRM_EXPORTS
-#define CWD_EXPORTS
-#endif
-
-#ifdef<