- Make TSRM work on Windows.

This commit is contained in:
Andi Gutmans 2000-09-03 18:47:35 +00:00
parent 6c6471b160
commit 03432bf61f
4 changed files with 77 additions and 16 deletions

44
TSRM/readdir.h Normal file
View File

@ -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 */

View File

@ -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) {

View File

@ -28,10 +28,15 @@
#include <stdlib.h>
#include <fcntl.h>
#include "tsrm_config.h"
#include "tsrm_strtok_r.h"
#include "tsrm_virtual_cwd.h"
#ifndef TSRM_WIN32
#include "tsrm_config.h"
#endif
#include "tsrm_strtok_r.h"
/* Are we doing enough to detect this? */
#ifndef MAXPATHLEN
#define MAXPATHLEN 256
@ -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

View File

@ -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