home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / PHP / include / php / TSRM / tsrm_virtual_cwd.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-11-22  |  6.8 KB  |  213 lines

  1. /*
  2.    +----------------------------------------------------------------------+
  3.    | PHP version 4.0                                                      |
  4.    +----------------------------------------------------------------------+
  5.    | Copyright (c) 1997, 1998, 1999, 2000 The PHP Group                   |
  6.    +----------------------------------------------------------------------+
  7.    | This source file is subject to version 2.02 of the PHP license,      |
  8.    | that is bundled with this package in the file LICENSE, and is        |
  9.    | available at through the world-wide-web at                           |
  10.    | http://www.php.net/license/2_02.txt.                                 |
  11.    | If you did not receive a copy of the PHP license and are unable to   |
  12.    | obtain it through the world-wide-web, please send a note to          |
  13.    | license@php.net so we can mail you a copy immediately.               |
  14.    +----------------------------------------------------------------------+
  15.    | Authors: Andi Gutmans <andi@zend.com>                                |
  16.    |          Sascha Schumann <sascha@schumann.cx>                        |
  17.    +----------------------------------------------------------------------+
  18. */
  19.  
  20. /* $Id: tsrm_virtual_cwd.h,v 1.10 2000/11/22 04:59:32 andi Exp $ */
  21.  
  22. #ifndef VIRTUAL_CWD_H
  23. #define VIRTUAL_CWD_H
  24.  
  25. #include "tsrm_config_common.h"
  26.  
  27. #include <sys/types.h>
  28. #include <sys/stat.h>
  29. #include <ctype.h>
  30.  
  31. #ifdef HAVE_UTIME_H
  32. #include <utime.h>
  33. #endif
  34.  
  35. #ifdef HAVE_STDARG_H
  36. #include <stdarg.h>
  37. #endif
  38.  
  39. #ifndef TSRM_WIN32
  40. #include <unistd.h>
  41. #endif
  42.  
  43. #ifdef TSRM_WIN32
  44. #include "readdir.h"
  45. #include <sys/utime.h>
  46. /* mode_t isn't defined on Windows */
  47. typedef unsigned short mode_t;
  48.  
  49. #define DEFAULT_SLASH '\\'
  50. #define IS_SLASH(c)    ((c) == '/' || (c) == '\\')
  51. #define COPY_WHEN_ABSOLUTE 2
  52. #define IS_ABSOLUTE_PATH(path, len) \
  53.     (len >= 2 && isalpha(path[0]) && path[1] == ':')
  54.  
  55. #else
  56. #ifdef HAVE_DIRENT_H
  57. #include <dirent.h>
  58. #endif
  59.  
  60. #define DEFAULT_SLASH '/'
  61. #define IS_SLASH(c)    ((c) == '/')
  62.  
  63. #endif
  64.  
  65.  
  66. #ifndef COPY_WHEN_ABSOLUTE
  67. #define COPY_WHEN_ABSOLUTE 0
  68. #endif
  69.  
  70. #ifndef IS_ABSOLUTE_PATH    
  71. #define IS_ABSOLUTE_PATH(path, len) \
  72.     (IS_SLASH(path[0]))
  73. #endif
  74.  
  75. #ifdef TSRM_EXPORTS
  76. #define CWD_EXPORTS
  77. #endif
  78.  
  79. #ifdef TSRM_WIN32
  80. #       ifdef CWD_EXPORTS
  81. #       define CWD_API __declspec(dllexport)
  82. #       else
  83. #       define CWD_API __declspec(dllimport)
  84. #       endif
  85. #else
  86. #define CWD_API
  87. #endif
  88.  
  89. typedef struct _cwd_state {
  90.     char *cwd;
  91.     int cwd_length;
  92. } cwd_state;
  93.  
  94. typedef int (*verify_path_func)(const cwd_state *);
  95.  
  96. CWD_API void virtual_cwd_startup(void);
  97. CWD_API void virtual_cwd_shutdown(void);
  98. CWD_API char *virtual_getcwd_ex(size_t *length);
  99. CWD_API char *virtual_getcwd(char *buf, size_t size);
  100. CWD_API int virtual_chdir(const char *path);
  101. CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path));
  102. CWD_API int virtual_filepath(const char *path, char **filepath);
  103. CWD_API int virtual_filepath_ex(const char *path, char **filepath, verify_path_func verify_path);
  104. CWD_API char *virtual_realpath(const char *path, char *real_path);
  105. CWD_API FILE *virtual_fopen(const char *path, const char *mode);
  106. CWD_API int virtual_open(const char *path, int flags, ...);
  107. CWD_API int virtual_creat(const char *path, mode_t mode);
  108. CWD_API int virtual_rename(char *oldname, char *newname);
  109. CWD_API int virtual_stat(const char *path, struct stat *buf);
  110. #ifndef TSRM_WIN32
  111. CWD_API int virtual_lstat(const char *path, struct stat *buf);
  112. #endif
  113. CWD_API int virtual_unlink(const char *path);
  114. CWD_API int virtual_mkdir(const char *pathname, mode_t mode);
  115. CWD_API int virtual_rmdir(const char *pathname);
  116. CWD_API DIR *virtual_opendir(const char *pathname);
  117. CWD_API FILE *virtual_popen(const char *command, const char *type);
  118. #if HAVE_UTIME
  119. CWD_API int virtual_utime(const char *filename, struct utimbuf *buf);
  120. #endif
  121. CWD_API int virtual_chmod(const char *filename, mode_t mode);
  122. #ifndef TSRM_WIN32
  123. CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group);
  124. #endif
  125.  
  126. CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func verify_path);
  127.  
  128. typedef struct _virtual_cwd_globals {
  129.     cwd_state cwd;
  130. } virtual_cwd_globals;
  131.  
  132. #ifdef ZTS
  133. # define CWDLS_D  virtual_cwd_globals *cwd_globals
  134. # define CWDLS_DC , CWDLS_D
  135. # define CWDLS_C  cwd_globals
  136. # define CWDLS_CC , CWDLS_C
  137. # define CWDG(v) (cwd_globals->v)
  138. # define CWDLS_FETCH()    virtual_cwd_globals *cwd_globals = ts_resource(cwd_globals_id)
  139. #else
  140. # define CWDLS_D  void
  141. # define CWDLS_DC
  142. # define CWDLS_C
  143. # define CWDLS_CC
  144. # define CWDG(v) (cwd_globals.v)
  145. # define CWDLS_FETCH()
  146. #endif
  147.  
  148. /* The actual macros to be used in programs using TSRM
  149.  * If the program defines VIRTUAL_DIR it will use the
  150.  * virtual_* functions 
  151.  */
  152.  
  153. #ifdef VIRTUAL_DIR
  154.  
  155. #define V_GETCWD(buff, size) virtual_getcwd(buff,size)
  156. #define V_FOPEN(path, mode) virtual_fopen(path, mode)
  157. /* The V_OPEN macro will need to be used as V_OPEN((path, flags, ...)) */
  158. #define V_OPEN(open_args) virtual_open open_args
  159. #define V_CREAT(path, mode) virtual_creat(path, mode)
  160. #define V_CHDIR(path) virtual_chdir(path)
  161. #define V_CHDIR_FILE(path) virtual_chdir_file(path, virtual_chdir)
  162. #define V_GETWD(buf)
  163. #define V_REALPATH(path,real_path) virtual_realpath(path,real_path)
  164. #define V_RENAME(oldname,newname) virtual_rename(oldname,newname)
  165. #define V_STAT(path, buff) virtual_stat(path, buff)
  166. #ifdef TSRM_WIN32
  167. #define V_LSTAT(path, buff) virtual_stat(path, buff)
  168. #else
  169. #define V_LSTAT(path, buff) virtual_lstat(path, buff)
  170. #endif
  171. #define V_UNLINK(path) virtual_unlink(path)
  172. #define V_MKDIR(pathname, mode) virtual_mkdir(pathname, mode)
  173. #define V_RMDIR(pathname) virtual_rmdir(pathname)
  174. #define V_OPENDIR(pathname) virtual_opendir(pathname)
  175. #define V_POPEN(command, type) virtual_popen(command, type)
  176. #if HAVE_UTIME
  177. #define V_UTIME(path,time) virtual_utime(path,time)
  178. #endif
  179. #define V_CHMOD(path,mode) virtual_chmod(path,mode)
  180. #ifndef TSRM_WIN32
  181. #define V_CHOWN(path,owner,group) virtual_chown(path,owner,group)
  182. #endif
  183.  
  184. #else
  185.  
  186. #define V_GETCWD(buff, size) getcwd(buff,size)
  187. #define V_FOPEN(path, mode)  fopen(path, mode)
  188. #define V_OPEN(open_args) open open_args
  189. #define V_CREAT(path, mode) creat(path, mode)
  190. #define V_RENAME(oldname,newname) rename(oldname,newname)
  191. #define V_CHDIR(path) chdir(path)
  192. #define V_CHDIR_FILE(path) virtual_chdir_file(path, chdir)
  193. #define V_GETWD(buf) getwd(buf)
  194. #define V_STAT(path, buff) stat(path, buff)
  195. #define V_LSTAT(path, buff) lstat(path, buff)
  196. #define V_UNLINK(path) unlink(path)
  197. #define V_MKDIR(pathname, mode) mkdir(pathname, mode)
  198. #define V_RMDIR(pathname) rmdir(pathname)
  199. #define V_OPENDIR(pathname) opendir(pathname)
  200. #define V_POPEN(command, type) popen(command, type)
  201. #define V_REALPATH(path,real_path) realpath(path,real_path)
  202. #if HAVE_UTIME
  203. #define V_UTIME(path,time) utime(path,time)
  204. #endif
  205. #define V_CHMOD(path,mode) chmod(path,mode)
  206. #ifndef TSRM_WIN32
  207. #define V_CHOWN(path,owner,group) chown(path,owner,group)
  208. #endif
  209.  
  210. #endif
  211.  
  212. #endif /* VIRTUAL_CWD_H */
  213.