diff options
author | Andi Gutmans <andi@php.net> | 2000-09-03 18:47:35 +0000 |
---|---|---|
committer | Andi Gutmans <andi@php.net> | 2000-09-03 18:47:35 +0000 |
commit | 03432bf61f14bbd415972fe6b4e2ba94f342efaa (patch) | |
tree | 993700b4bfc39567c96e986a5bae7e26c893ea58 | |
parent | 6c6471b16018b8e225043e436fa8c819a57cd459 (diff) | |
download | php-git-03432bf61f14bbd415972fe6b4e2ba94f342efaa.tar.gz |
- Make TSRM work on Windows.
-rw-r--r-- | TSRM/readdir.h | 44 | ||||
-rw-r--r-- | TSRM/tsrm_strtok_r.c | 2 | ||||
-rw-r--r-- | TSRM/tsrm_virtual_cwd.c | 35 | ||||
-rw-r--r-- | TSRM/tsrm_virtual_cwd.h | 10 |
4 files changed, 76 insertions, 15 deletions
diff --git a/TSRM/readdir.h b/TSRM/readdir.h new file mode 100644 index 0000000000..b0f1ad9e6f --- /dev/null +++ b/TSRM/readdir.h @@ -0,0 +1,44 @@ +#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 */ diff --git a/TSRM/tsrm_strtok_r.c b/TSRM/tsrm_strtok_r.c index 509f563ec0..b631825140 100644 --- a/TSRM/tsrm_strtok_r.c +++ b/TSRM/tsrm_strtok_r.c @@ -2,7 +2,7 @@ #include <stdio.h> -static inline int in_character_class(char ch, const char *delim) +static int in_character_class(char ch, const char *delim) { while (*delim) { if (*delim == ch) { diff --git a/TSRM/tsrm_virtual_cwd.c b/TSRM/tsrm_virtual_cwd.c index 48b566af94..f1ed8a0e3a 100644 --- a/TSRM/tsrm_virtual_cwd.c +++ b/TSRM/tsrm_virtual_cwd.c @@ -28,9 +28,14 @@ #include <stdlib.h> #include <fcntl.h> +#include "tsrm_virtual_cwd.h" + +#ifndef TSRM_WIN32 #include "tsrm_config.h" +#endif + #include "tsrm_strtok_r.h" -#include "tsrm_virtual_cwd.h" + /* Are we doing enough to detect this? */ #ifndef MAXPATHLEN @@ -42,15 +47,14 @@ # define do_alloca(p) alloca(p) # define free_alloca(p) # else -# define do_alloca(p) emalloc(p) -# define free_alloca(p) efree(p) +# define do_alloca(p) malloc(p) +# define free_alloca(p) free(p) # endif #endif #ifdef TSRM_WIN32 -/* mode_t isn't defined on Windows */ -typedef int mode_t; #include <sys/utime.h> +#include <io.h> #endif #define VIRTUAL_CWD_DEBUG 0 @@ -175,7 +179,7 @@ static void cwd_globals_dtor(virtual_cwd_globals *cwd_globals) CWD_STATE_FREE(&cwd_globals->cwd); } -static char *tsrm_strndup(const char *s, uint length) +static char *tsrm_strndup(const char *s, size_t length) { char *p; @@ -509,7 +513,7 @@ CWD_API FILE *virtual_fopen(const char *path, const char *mode) return f; } -#if HAVE_UTIME +#if HAVE_UTIME || defined(TSRM_WIN32) CWD_API int virtual_utime(const char *filename, struct utimbuf *buf) { cwd_state new_state; @@ -541,7 +545,7 @@ CWD_API int virtual_chmod(const char *filename, mode_t mode) return ret; } -#ifndef PHP_WIN32 +#ifndef TSRM_WIN32 CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group) { cwd_state new_state; @@ -657,8 +661,11 @@ CWD_API int virtual_mkdir(const char *pathname, mode_t mode) 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; } @@ -678,6 +685,10 @@ CWD_API int virtual_rmdir(const char *pathname) return retval; } +#ifdef TSRM_WIN32 +DIR *opendir(const char *name); +#endif + CWD_API DIR *virtual_opendir(const char *pathname) { cwd_state new_state; @@ -724,7 +735,11 @@ CWD_API FILE *virtual_popen(const char *command, const char *type) *ptr++ = ' '; memcpy(ptr, command, command_length+1); +#ifdef TSRM_WIN32 + retval = _popen(command_line, type); +#else retval = popen(command_line, type); +#endif free(command_line); return retval; } @@ -751,7 +766,7 @@ CWD_API FILE *virtual_popen(const char *command, const char *type) #endif chdir(CWDG(cwd).cwd); - retval = popen(command, type); + retval = _popen(command, type); chdir(prev_cwd); #ifdef ZTS diff --git a/TSRM/tsrm_virtual_cwd.h b/TSRM/tsrm_virtual_cwd.h index 93c5c67a57..b6875dfe4b 100644 --- a/TSRM/tsrm_virtual_cwd.h +++ b/TSRM/tsrm_virtual_cwd.h @@ -43,7 +43,10 @@ #endif #ifdef TSRM_WIN32 -#include "win32/readdir.h" +#include "readdir.h" + +/* mode_t isn't defined on Windows */ +typedef int mode_t; #define IS_SLASH(c) ((c) == '/' || (c) == '\\') @@ -70,7 +73,7 @@ # endif #endif -#ifdef PHP_EXPORTS +#ifdef TSRM_EXPORTS #define CWD_EXPORTS #endif @@ -97,7 +100,6 @@ CWD_API char *virtual_getcwd_ex(int *length); CWD_API char *virtual_getcwd(char *buf, size_t size); CWD_API int virtual_chdir(const char *path); CWD_API int virtual_chdir_file(const char *path, int (*p_chdir)(const char *path)); -/* CWD_API void virtual_real_chdir_file(const char *path); */ CWD_API int virtual_filepath(const char *path, char **filepath); CWD_API char *virtual_realpath(const char *path, char *real_path); CWD_API FILE *virtual_fopen(const char *path, const char *mode); @@ -116,7 +118,7 @@ CWD_API FILE *virtual_popen(const char *command, const char *type); CWD_API int virtual_utime(const char *filename, struct utimbuf *buf); #endif CWD_API int virtual_chmod(const char *filename, mode_t mode); -#ifndef PHP_WIN32 +#ifndef TSRM_WIN32 CWD_API int virtual_chown(const char *filename, uid_t owner, gid_t group); #endif |