1999-04-17 08:37:12 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| PHP version 4.0 |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-01-01 09:32:05 +08:00
|
|
|
| Copyright (c) 1997, 1998, 1999, 2000 The PHP Group |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 21:13:16 +08:00
|
|
|
| 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. |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Rasmus Lerdorf <rasmus@lerdorf.on.ca> |
|
2000-09-09 19:41:14 +08:00
|
|
|
| Stig Bakken <ssb@fast.no> |
|
|
|
|
| Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
2000-10-29 17:14:55 +08:00
|
|
|
| PHP 4.0 patches by Thies C. Arntzen (thies@thieso.net) |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* $Id$ */
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
|
1999-12-18 12:01:20 +08:00
|
|
|
/* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* {{{ includes */
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
#include "php.h"
|
1999-04-21 12:02:11 +08:00
|
|
|
#include "php_globals.h"
|
1999-06-16 05:51:00 +08:00
|
|
|
#include "ext/standard/flock_compat.h"
|
2000-01-06 23:27:03 +08:00
|
|
|
#include "ext/standard/exec.h"
|
2000-07-02 23:12:34 +08:00
|
|
|
#include "ext/standard/php_filestat.h"
|
2000-09-12 02:56:47 +08:00
|
|
|
#include "php_open_temporary_file.h"
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-17 08:37:12 +08:00
|
|
|
#include <windows.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
#define O_RDONLY _O_RDONLY
|
|
|
|
#include "win32/param.h"
|
|
|
|
#include "win32/winutil.h"
|
|
|
|
#else
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/socket.h>
|
2000-08-20 05:15:43 +08:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <arpa/inet.h>
|
1999-04-17 08:37:12 +08:00
|
|
|
#endif
|
1999-06-16 05:51:00 +08:00
|
|
|
#include "ext/standard/head.h"
|
1999-04-17 08:37:12 +08:00
|
|
|
#include "safe_mode.h"
|
1999-12-05 03:19:57 +08:00
|
|
|
#include "php_string.h"
|
1999-06-16 05:51:00 +08:00
|
|
|
#include "file.h"
|
1999-04-17 08:37:12 +08:00
|
|
|
#if HAVE_PWD_H
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef PHP_WIN32
|
1999-04-17 08:37:12 +08:00
|
|
|
#include "win32/pwd.h"
|
|
|
|
#else
|
|
|
|
#include <pwd.h>
|
|
|
|
#endif
|
|
|
|
#endif
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
#ifdef HAVE_SYS_TIME_H
|
1999-10-15 23:22:25 +08:00
|
|
|
#include <sys/time.h>
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
#endif
|
1999-04-17 08:37:12 +08:00
|
|
|
#include "fsock.h"
|
|
|
|
#include "fopen-wrappers.h"
|
1999-06-16 05:51:00 +08:00
|
|
|
#include "php_globals.h"
|
1999-04-17 08:37:12 +08:00
|
|
|
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
#ifdef HAVE_SYS_FILE_H
|
1999-09-12 02:15:39 +08:00
|
|
|
#include <sys/file.h>
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
#endif
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
#if MISSING_FCLOSE_DECL
|
2000-08-04 00:37:35 +08:00
|
|
|
extern int fclose(FILE *);
|
1999-04-17 08:37:12 +08:00
|
|
|
#endif
|
|
|
|
|
1999-09-12 02:15:39 +08:00
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
1999-09-13 04:36:48 +08:00
|
|
|
#ifndef MAP_FAILED
|
|
|
|
#define MAP_FAILED ((void *) -1)
|
|
|
|
#endif
|
|
|
|
|
2000-06-07 02:58:15 +08:00
|
|
|
#include "scanf.h"
|
|
|
|
#include "zend_API.h"
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
#ifdef ZTS
|
|
|
|
int file_globals_id;
|
|
|
|
#else
|
|
|
|
php_file_globals file_globals;
|
|
|
|
#endif
|
|
|
|
|
2001-01-13 21:59:22 +08:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ ZTS-stuff / Globals / Prototypes */
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* sharing globals is *evil* */
|
2000-09-09 19:41:14 +08:00
|
|
|
static int le_fopen, le_popen, le_socket;
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-11-24 11:05:10 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ Module-Stuff */
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2000-10-21 02:25:16 +08:00
|
|
|
static void _file_popen_dtor(zend_rsrc_list_entry *rsrc)
|
1999-10-15 23:22:25 +08:00
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
FILE *pipe = (FILE *)rsrc->ptr;
|
2001-01-13 21:59:22 +08:00
|
|
|
FLS_FETCH();
|
|
|
|
|
|
|
|
FG(pclose_ret) = pclose(pipe);
|
1999-10-15 23:22:25 +08:00
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-13 02:50:05 +08:00
|
|
|
|
2000-10-21 02:25:16 +08:00
|
|
|
static void _file_socket_dtor(zend_rsrc_list_entry *rsrc)
|
1999-10-15 23:22:25 +08:00
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
int *sock = (int *)rsrc->ptr;
|
1999-10-15 23:22:25 +08:00
|
|
|
SOCK_FCLOSE(*sock);
|
|
|
|
#if HAVE_SHUTDOWN
|
|
|
|
shutdown(*sock, 0);
|
|
|
|
#endif
|
|
|
|
efree(sock);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-21 02:25:16 +08:00
|
|
|
static void _file_fopen_dtor(zend_rsrc_list_entry *rsrc)
|
1999-10-15 23:22:25 +08:00
|
|
|
{
|
2000-10-21 02:25:16 +08:00
|
|
|
FILE *fp = (FILE *)rsrc->ptr;
|
1999-10-15 23:22:25 +08:00
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PHPAPI int php_file_le_fopen(void) /* XXX doe we really want this???? */
|
|
|
|
{
|
|
|
|
return le_fopen;
|
|
|
|
}
|
|
|
|
|
2000-03-13 03:42:29 +08:00
|
|
|
PHPAPI int php_file_le_popen(void) /* XXX you may not like this, but I need it. -- KK */
|
|
|
|
{
|
|
|
|
return le_popen;
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
PHPAPI int php_file_le_socket(void) /* XXX doe we really want this???? */
|
|
|
|
{
|
|
|
|
return le_socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ZTS
|
2001-01-13 21:59:22 +08:00
|
|
|
static void file_globals_ctor(FLS_D)
|
|
|
|
{
|
|
|
|
zend_hash_init(&FG(ht_fsock_keys), 0, NULL, NULL, 1);
|
|
|
|
zend_hash_init(&FG(ht_fsock_socks), 0, NULL, (void (*)(void *))php_msock_destroy, 1);
|
|
|
|
FG(def_chunk_size) = PHP_FSOCK_CHUNK_SIZE;
|
|
|
|
FG(phpsockbuf) = NULL;
|
|
|
|
FG(fgetss_state) = 0;
|
|
|
|
FG(pclose_ret) = 0;
|
|
|
|
}
|
|
|
|
static void file_globals_dtor(FLS_D)
|
1999-10-15 23:22:25 +08:00
|
|
|
{
|
2001-01-13 21:59:22 +08:00
|
|
|
zend_hash_destroy(&FG(ht_fsock_socks));
|
|
|
|
zend_hash_destroy(&FG(ht_fsock_keys));
|
|
|
|
php_cleanup_sockbuf(1 FLS_CC);
|
1999-10-15 23:22:25 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
PHP_MINIT_FUNCTION(file)
|
|
|
|
{
|
2000-10-26 01:44:02 +08:00
|
|
|
le_fopen = zend_register_list_destructors_ex(_file_fopen_dtor, NULL, "file", module_number);
|
|
|
|
le_popen = zend_register_list_destructors_ex(_file_popen_dtor, NULL, "pipe", module_number);
|
|
|
|
le_socket = zend_register_list_destructors_ex(_file_socket_dtor, NULL, "socket", module_number);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
#ifdef ZTS
|
2001-01-13 21:59:22 +08:00
|
|
|
file_globals_id = ts_allocate_id(sizeof(php_file_globals), (ts_allocate_ctor) file_globals_ctor, (ts_allocate_dtor) file_globals_dtor);
|
1999-10-15 23:22:25 +08:00
|
|
|
#else
|
2001-01-13 21:59:22 +08:00
|
|
|
file_globals_ctor(FLS_C);
|
1999-10-15 23:22:25 +08:00
|
|
|
#endif
|
|
|
|
|
2000-04-24 22:18:11 +08:00
|
|
|
REGISTER_LONG_CONSTANT("SEEK_SET", SEEK_SET, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("SEEK_CUR", SEEK_CUR, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("SEEK_END", SEEK_END, CONST_CS | CONST_PERSISTENT);
|
2000-06-06 03:35:15 +08:00
|
|
|
REGISTER_LONG_CONSTANT("LOCK_SH", 1, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("LOCK_EX", 2, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("LOCK_UN", 3, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("LOCK_NB", 4, CONST_CS | CONST_PERSISTENT);
|
2000-04-24 22:18:11 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
2000-06-06 01:56:01 +08:00
|
|
|
/* {{{ proto bool flock(int fp, int operation [, int wouldblock])
|
2000-02-24 16:07:29 +08:00
|
|
|
Portable file locking */
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
static int flock_values[] = { LOCK_SH, LOCK_EX, LOCK_UN };
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(flock)
|
|
|
|
{
|
2000-06-06 01:56:01 +08:00
|
|
|
pval **arg1, **arg2, **arg3;
|
|
|
|
int type, fd, act, ret, arg_count = ARG_COUNT(ht);
|
1999-10-14 03:55:25 +08:00
|
|
|
void *what;
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2000-06-06 01:56:01 +08:00
|
|
|
if (arg_count > 3 || zend_get_parameters_ex(arg_count, &arg1, &arg2, &arg3) == FAILURE) {
|
1999-06-16 05:51:00 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
1999-10-14 03:55:25 +08:00
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if (type == le_socket) {
|
|
|
|
fd = *(int *) what;
|
|
|
|
} else {
|
|
|
|
fd = fileno((FILE*) what);
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_long_ex(arg2);
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2000-06-06 03:35:15 +08:00
|
|
|
act = (*arg2)->value.lval & 3;
|
|
|
|
if (act < 1 || act > 3) {
|
2000-06-06 01:56:01 +08:00
|
|
|
php_error(E_WARNING, "Illegal operation argument");
|
1999-10-14 03:55:25 +08:00
|
|
|
RETURN_FALSE;
|
1999-06-16 05:51:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* flock_values contains all possible actions
|
|
|
|
if (arg2 & 4) we won't block on the lock */
|
2000-06-06 03:35:15 +08:00
|
|
|
act = flock_values[act - 1] | ((*arg2)->value.lval & 4 ? LOCK_NB : 0);
|
2000-06-06 01:56:01 +08:00
|
|
|
if ((ret=flock(fd, act)) == -1) {
|
1999-06-16 05:51:00 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-06-06 01:56:01 +08:00
|
|
|
if(ret==-1 && errno==EWOULDBLOCK && arg_count==3) {
|
|
|
|
(*arg3)->type = IS_LONG;
|
|
|
|
(*arg3)->value.lval=1;
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-10-13 02:50:05 +08:00
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto array get_meta_tags(string filename [, int use_include_path])
|
2000-02-24 16:07:29 +08:00
|
|
|
Extracts all meta tag content attributes from a file and returns an array */
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(get_meta_tags)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **filename, **arg2;
|
1999-04-17 08:37:12 +08:00
|
|
|
FILE *fp;
|
|
|
|
char buf[8192];
|
1999-12-12 03:51:04 +08:00
|
|
|
char buf_lcase[8192];
|
1999-04-17 08:37:12 +08:00
|
|
|
int use_include_path = 0;
|
|
|
|
int issock=0, socketd=0;
|
|
|
|
int len, var_namelen;
|
|
|
|
char var_name[50],*val=NULL,*tmp,*end,*slashed;
|
|
|
|
PLS_FETCH();
|
|
|
|
|
|
|
|
/* check args */
|
|
|
|
switch (ARG_COUNT(ht)) {
|
1999-10-15 23:22:25 +08:00
|
|
|
case 1:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(1,&filename) == FAILURE) {
|
1999-06-16 01:06:22 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
1999-10-15 23:22:25 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(2,&filename,&arg2) == FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
use_include_path = (*arg2)->value.lval;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(filename);
|
|
|
|
|
2000-12-13 01:42:53 +08:00
|
|
|
fp = php_fopen_wrapper((*filename)->value.str.val,"rb", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL);
|
1999-04-17 08:37:12 +08:00
|
|
|
if (!fp && !socketd) {
|
|
|
|
if (issock != BAD_URL) {
|
2000-11-01 22:48:00 +08:00
|
|
|
char *tmp = estrndup(Z_STRVAL_PP(filename), Z_STRLEN_PP(filename));
|
1999-12-18 03:16:50 +08:00
|
|
|
php_strip_url_passwd(tmp);
|
1999-10-15 23:22:25 +08:00
|
|
|
php_error(E_WARNING,"get_meta_tags(\"%s\") - %s", tmp, strerror(errno));
|
|
|
|
efree(tmp);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
if (array_init(return_value)==FAILURE) {
|
|
|
|
if (issock) {
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
SOCK_FCLOSE(socketd);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* Now loop through the file and do the magic quotes thing if needed */
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
memset(buf, 0, 8191);
|
1999-12-12 03:51:04 +08:00
|
|
|
while((FP_FGETS(buf,8191,socketd,fp,issock) != NULL)) {
|
|
|
|
memcpy(buf_lcase, buf, 8191);
|
|
|
|
php_strtolower(buf_lcase, 8191);
|
|
|
|
if (php_memnstr(buf_lcase, "</head>", sizeof("</head>")-1, buf_lcase + 8191))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if(php_memnstr(buf_lcase, "<meta", sizeof("<meta")-1, buf_lcase + 8191)) {
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
memset(var_name,0,50);
|
|
|
|
/* get the variable name from the name attribute of the meta tag */
|
1999-12-12 03:51:04 +08:00
|
|
|
tmp = php_memnstr(buf_lcase, "name=\"", sizeof("name=\"")-1, buf_lcase + 8191);
|
1999-04-17 08:37:12 +08:00
|
|
|
if(tmp) {
|
1999-12-12 03:51:04 +08:00
|
|
|
tmp = &buf[tmp - buf_lcase];
|
1999-04-17 08:37:12 +08:00
|
|
|
tmp+=6;
|
|
|
|
end=strstr(tmp,"\"");
|
|
|
|
if(end) {
|
|
|
|
unsigned char *c;
|
|
|
|
*end='\0';
|
|
|
|
snprintf(var_name,50,"%s",tmp);
|
|
|
|
*end='"';
|
|
|
|
|
|
|
|
c = (unsigned char*)var_name;
|
|
|
|
while (*c) {
|
|
|
|
switch(*c) {
|
|
|
|
case '.':
|
|
|
|
case '\\':
|
|
|
|
case '+':
|
|
|
|
case '*':
|
|
|
|
case '?':
|
|
|
|
case '[':
|
|
|
|
case '^':
|
|
|
|
case ']':
|
|
|
|
case '$':
|
|
|
|
case '(':
|
|
|
|
case ')':
|
|
|
|
case ' ':
|
|
|
|
*c++ ='_';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
*c++ = tolower((unsigned char)*c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var_namelen=strlen(var_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the variable value from the content attribute of the meta tag */
|
1999-12-12 03:51:04 +08:00
|
|
|
tmp = php_memnstr(buf_lcase, "content=\"", sizeof("content=\"")-1, buf_lcase + 8191);
|
2000-11-15 17:36:21 +08:00
|
|
|
val = NULL;
|
1999-04-17 08:37:12 +08:00
|
|
|
if(tmp) {
|
1999-12-12 03:51:04 +08:00
|
|
|
tmp = &buf[tmp - buf_lcase];
|
1999-04-17 08:37:12 +08:00
|
|
|
tmp+=9;
|
|
|
|
end=strstr(tmp,"\"");
|
|
|
|
if(end) {
|
|
|
|
*end='\0';
|
|
|
|
val=estrdup(tmp);
|
|
|
|
*end='"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(*var_name && val) {
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
1999-09-04 21:18:59 +08:00
|
|
|
slashed = php_addslashes(val,0,&len,0);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
|
|
|
slashed = estrndup(val,strlen(val));
|
|
|
|
}
|
|
|
|
add_assoc_string(return_value, var_name, slashed, 0);
|
|
|
|
efree(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (issock) {
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
SOCK_FCLOSE(socketd);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2000-06-27 01:57:46 +08:00
|
|
|
/* {{{ proto array file(string filename [, int use_include_path])
|
1999-10-15 23:22:25 +08:00
|
|
|
Read entire file into an array */
|
|
|
|
|
2000-06-27 04:52:04 +08:00
|
|
|
#define PHP_FILE_BUF_SIZE 80
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(file)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **filename, **arg2;
|
1999-04-17 08:37:12 +08:00
|
|
|
FILE *fp;
|
2000-06-27 04:52:04 +08:00
|
|
|
char *slashed, *target_buf;
|
1999-04-17 08:37:12 +08:00
|
|
|
register int i=0;
|
|
|
|
int use_include_path = 0;
|
|
|
|
int issock=0, socketd=0;
|
2000-06-27 04:52:04 +08:00
|
|
|
int target_len, len;
|
|
|
|
zend_bool reached_eof=0;
|
1999-04-17 08:37:12 +08:00
|
|
|
PLS_FETCH();
|
|
|
|
|
|
|
|
/* check args */
|
|
|
|
switch (ARG_COUNT(ht)) {
|
1999-10-15 23:22:25 +08:00
|
|
|
case 1:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(1,&filename) == FAILURE) {
|
1999-06-16 01:06:22 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
1999-10-15 23:22:25 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(2,&filename,&arg2) == FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
use_include_path = (*arg2)->value.lval;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(filename);
|
|
|
|
|
2000-12-13 01:42:53 +08:00
|
|
|
fp = php_fopen_wrapper((*filename)->value.str.val,"rb", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL);
|
1999-04-17 08:37:12 +08:00
|
|
|
if (!fp && !socketd) {
|
|
|
|
if (issock != BAD_URL) {
|
2000-11-01 22:48:00 +08:00
|
|
|
char *tmp = estrndup(Z_STRVAL_PP(filename), Z_STRLEN_PP(filename));
|
1999-12-18 03:16:50 +08:00
|
|
|
php_strip_url_passwd(tmp);
|
1999-10-15 23:22:25 +08:00
|
|
|
php_error(E_WARNING,"file(\"%s\") - %s", tmp, strerror(errno));
|
|
|
|
efree(tmp);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize return array */
|
|
|
|
if (array_init(return_value) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* Now loop through the file and do the magic quotes thing if needed */
|
2000-06-27 04:52:04 +08:00
|
|
|
target_len = 0;
|
|
|
|
target_buf = NULL;
|
|
|
|
while (1) {
|
|
|
|
if (!target_buf) {
|
|
|
|
target_buf = (char *) emalloc(PHP_FILE_BUF_SIZE+1);
|
|
|
|
target_buf[PHP_FILE_BUF_SIZE] = 0; /* avoid overflows */
|
|
|
|
} else {
|
|
|
|
target_buf = (char *) erealloc(target_buf, target_len+PHP_FILE_BUF_SIZE+1);
|
|
|
|
target_buf[target_len+PHP_FILE_BUF_SIZE] = 0; /* avoid overflows */
|
|
|
|
}
|
|
|
|
if (FP_FGETS(target_buf+target_len, PHP_FILE_BUF_SIZE, socketd, fp, issock)==NULL) {
|
|
|
|
if (target_len==0) {
|
|
|
|
efree(target_buf);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
reached_eof = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!reached_eof) {
|
|
|
|
target_len += strlen(target_buf+target_len);
|
|
|
|
if (target_buf[target_len-1]!='\n') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
if (PG(magic_quotes_runtime)) {
|
2000-06-27 04:52:04 +08:00
|
|
|
slashed = php_addslashes(target_buf, target_len, &len, 1); /* 1 = free source string */
|
1999-04-17 08:37:12 +08:00
|
|
|
add_index_stringl(return_value, i++, slashed, len, 0);
|
|
|
|
} else {
|
2000-06-27 04:52:04 +08:00
|
|
|
target_buf = erealloc(target_buf, target_len+1); /* do we really want to do that? */
|
|
|
|
add_index_stringl(return_value, i++, target_buf, target_len, 0);
|
|
|
|
}
|
|
|
|
if (reached_eof) {
|
|
|
|
break;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-06-27 04:52:04 +08:00
|
|
|
target_buf = NULL;
|
|
|
|
target_len = 0;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
if (issock) {
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
SOCK_FCLOSE(socketd);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2000-03-05 01:23:03 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto string tempnam(string dir, string prefix)
|
1999-10-15 23:22:25 +08:00
|
|
|
Create a unique filename in a directory */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(tempnam)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2;
|
1999-04-17 08:37:12 +08:00
|
|
|
char *d;
|
2000-09-09 19:41:14 +08:00
|
|
|
char *opened_path;
|
1999-04-17 08:37:12 +08:00
|
|
|
char p[64];
|
2000-09-09 19:41:14 +08:00
|
|
|
FILE *fp;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(arg1);
|
|
|
|
convert_to_string_ex(arg2);
|
2000-11-01 22:48:00 +08:00
|
|
|
d = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1));
|
|
|
|
strlcpy(p, Z_STRVAL_PP(arg2), sizeof(p));
|
2000-09-09 19:41:14 +08:00
|
|
|
|
|
|
|
if ((fp = php_open_temporary_file(d, p, &opened_path))) {
|
|
|
|
fclose(fp);
|
|
|
|
RETVAL_STRING(opened_path, 0);
|
|
|
|
} else {
|
|
|
|
RETVAL_FALSE;
|
1999-06-28 05:45:06 +08:00
|
|
|
}
|
2000-09-09 19:41:14 +08:00
|
|
|
efree(d);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2000-02-24 16:07:29 +08:00
|
|
|
/* {{{ proto int tmpfile(void)
|
|
|
|
Create a temporary file that will be deleted automatically after use */
|
2000-12-07 20:09:38 +08:00
|
|
|
PHP_NAMED_FUNCTION(php_if_tmpfile)
|
1999-11-14 19:05:37 +08:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
if (ARG_COUNT(ht) != 0) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
fp = tmpfile();
|
|
|
|
if (fp == NULL) {
|
|
|
|
php_error(E_WARNING, "tmpfile: %s", strerror(errno));
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
ZEND_REGISTER_RESOURCE(return_value, fp, le_fopen);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int fopen(string filename, string mode [, int use_include_path])
|
1999-10-15 23:22:25 +08:00
|
|
|
Open a file or a URL and return a file pointer */
|
|
|
|
|
2000-12-07 20:09:38 +08:00
|
|
|
PHP_NAMED_FUNCTION(php_if_fopen)
|
1999-06-16 05:51:00 +08:00
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2, **arg3;
|
1999-04-17 08:37:12 +08:00
|
|
|
FILE *fp;
|
|
|
|
char *p;
|
|
|
|
int *sock;
|
|
|
|
int use_include_path = 0;
|
|
|
|
int issock=0, socketd=0;
|
2001-01-13 21:59:22 +08:00
|
|
|
FLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
switch(ARG_COUNT(ht)) {
|
1999-10-15 23:22:25 +08:00
|
|
|
case 2:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(2,&arg1,&arg2) == FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(3,&arg1,&arg2,&arg3) == FAILURE) {
|
1999-06-16 01:06:22 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
1999-10-15 23:22:25 +08:00
|
|
|
}
|
|
|
|
convert_to_long_ex(arg3);
|
|
|
|
use_include_path = (*arg3)->value.lval;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(arg1);
|
|
|
|
convert_to_string_ex(arg2);
|
|
|
|
p = estrndup((*arg2)->value.str.val,(*arg2)->value.str.len);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We need a better way of returning error messages from
|
1999-12-18 12:01:20 +08:00
|
|
|
* php_fopen_wrapper().
|
1999-04-17 08:37:12 +08:00
|
|
|
*/
|
1999-12-18 03:16:50 +08:00
|
|
|
fp = php_fopen_wrapper((*arg1)->value.str.val, p, use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL);
|
1999-04-17 08:37:12 +08:00
|
|
|
if (!fp && !socketd) {
|
|
|
|
if (issock != BAD_URL) {
|
2000-11-01 22:48:00 +08:00
|
|
|
char *tmp = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1));
|
1999-12-18 03:16:50 +08:00
|
|
|
php_strip_url_passwd(tmp);
|
1999-10-15 23:22:25 +08:00
|
|
|
php_error(E_WARNING,"fopen(\"%s\",\"%s\") - %s", tmp, p, strerror(errno));
|
|
|
|
efree(tmp);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
efree(p);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-14 03:55:25 +08:00
|
|
|
|
|
|
|
efree(p);
|
2001-01-13 21:59:22 +08:00
|
|
|
FG(fgetss_state)=0;
|
1999-10-14 03:55:25 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
if (issock) {
|
|
|
|
sock=emalloc(sizeof(int));
|
|
|
|
*sock=socketd;
|
1999-10-14 03:55:25 +08:00
|
|
|
ZEND_REGISTER_RESOURCE(return_value,sock,le_socket);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
1999-10-14 03:55:25 +08:00
|
|
|
ZEND_REGISTER_RESOURCE(return_value,fp,le_fopen);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int fclose(int fp)
|
2000-02-24 16:07:29 +08:00
|
|
|
Close an open file pointer */
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(fclose)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1;
|
|
|
|
int type;
|
|
|
|
void *what;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,2,le_fopen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
zend_list_delete((*arg1)->value.lval);
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int popen(string command, string mode)
|
1999-10-15 23:22:25 +08:00
|
|
|
Execute a command and open either a read or a write pipe to it */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(popen)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2;
|
1999-04-17 08:37:12 +08:00
|
|
|
FILE *fp;
|
2000-01-06 23:27:03 +08:00
|
|
|
char *p,*tmp = NULL;
|
1999-04-17 08:37:12 +08:00
|
|
|
char *b, buf[1024];
|
1999-04-21 12:02:11 +08:00
|
|
|
PLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(arg1);
|
|
|
|
convert_to_string_ex(arg2);
|
|
|
|
p = estrndup((*arg2)->value.str.val,(*arg2)->value.str.len);
|
1999-04-17 08:37:12 +08:00
|
|
|
if (PG(safe_mode)){
|
1999-10-15 23:22:25 +08:00
|
|
|
b = strchr((*arg1)->value.str.val,' ');
|
1999-06-16 05:51:00 +08:00
|
|
|
if (!b) {
|
1999-10-15 23:22:25 +08:00
|
|
|
b = strrchr((*arg1)->value.str.val,'/');
|
1999-06-16 05:51:00 +08:00
|
|
|
} else {
|
|
|
|
char *c;
|
1999-10-15 23:22:25 +08:00
|
|
|
c = (*arg1)->value.str.val;
|
1999-06-16 05:51:00 +08:00
|
|
|
while((*b!='/')&&(b!=c)) {
|
|
|
|
b--;
|
|
|
|
}
|
|
|
|
if (b==c) {
|
|
|
|
b=NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (b) {
|
|
|
|
snprintf(buf,sizeof(buf),"%s%s",PG(safe_mode_exec_dir),b);
|
|
|
|
} else {
|
1999-10-15 23:22:25 +08:00
|
|
|
snprintf(buf,sizeof(buf),"%s/%s",PG(safe_mode_exec_dir),(*arg1)->value.str.val);
|
1999-06-16 05:51:00 +08:00
|
|
|
}
|
2000-01-06 23:27:03 +08:00
|
|
|
|
|
|
|
tmp = php_escape_shell_cmd(buf);
|
2000-06-13 03:39:04 +08:00
|
|
|
fp = V_POPEN(tmp,p);
|
2000-01-06 23:27:03 +08:00
|
|
|
efree(tmp);
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
if (!fp) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"popen(\"%s\",\"%s\") - %s",buf,p,strerror(errno));
|
1999-06-16 05:51:00 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-06-16 01:06:22 +08:00
|
|
|
} else {
|
2000-11-01 22:48:00 +08:00
|
|
|
fp = V_POPEN((*arg1)->value.str.val, p);
|
1999-06-16 05:51:00 +08:00
|
|
|
if (!fp) {
|
1999-10-15 23:22:25 +08:00
|
|
|
php_error(E_WARNING,"popen(\"%s\",\"%s\") - %s",(*arg1)->value.str.val,p,strerror(errno));
|
1999-06-16 05:51:00 +08:00
|
|
|
efree(p);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-06-16 01:06:22 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
efree(p);
|
1999-10-14 03:55:25 +08:00
|
|
|
|
|
|
|
ZEND_REGISTER_RESOURCE(return_value,fp,le_popen);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int pclose(int fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Close a file pointer opened by popen() */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(pclose)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1;
|
|
|
|
void *what;
|
2001-01-13 21:59:22 +08:00
|
|
|
FLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,1,le_popen);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
zend_list_delete((*arg1)->value.lval);
|
2001-01-13 21:59:22 +08:00
|
|
|
RETURN_LONG(FG(pclose_ret));
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int feof(int fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Test for end-of-file on a file pointer */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(feof)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1;
|
|
|
|
int type;
|
1999-04-17 08:37:12 +08:00
|
|
|
int issock=0;
|
1999-10-15 23:22:25 +08:00
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if (type == le_socket) {
|
1999-04-17 08:37:12 +08:00
|
|
|
issock=1;
|
1999-10-15 23:22:25 +08:00
|
|
|
socketd=*(int *) what;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FP_FEOF(socketd, (FILE*)what, issock)) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2000-02-02 04:02:44 +08:00
|
|
|
|
2000-06-27 01:57:46 +08:00
|
|
|
/* {{{ proto int set_socket_blocking(int socket_descriptor, int mode)
|
2000-02-02 04:02:44 +08:00
|
|
|
Set blocking/non-blocking mode on a socket */
|
1999-12-18 12:01:20 +08:00
|
|
|
PHPAPI int php_set_sock_blocking(int socketd, int block)
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
{
|
|
|
|
int ret = SUCCESS;
|
|
|
|
int flags;
|
|
|
|
int myflag = 0;
|
|
|
|
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef PHP_WIN32
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
/* with ioctlsocket, a non-zero sets nonblocking, a zero sets blocking */
|
2000-07-22 12:23:41 +08:00
|
|
|
flags = !block;
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
if (ioctlsocket(socketd,FIONBIO,&flags)==SOCKET_ERROR){
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"%s",WSAGetLastError());
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
ret = FALSE;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
flags = fcntl(socketd, F_GETFL);
|
|
|
|
#ifdef O_NONBLOCK
|
|
|
|
myflag = O_NONBLOCK; /* POSIX version */
|
|
|
|
#elif defined(O_NDELAY)
|
|
|
|
myflag = O_NDELAY; /* old non-POSIX version */
|
|
|
|
#endif
|
1999-08-28 21:53:46 +08:00
|
|
|
if (!block) {
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
flags |= myflag;
|
|
|
|
} else {
|
|
|
|
flags &= ~myflag;
|
|
|
|
}
|
|
|
|
fcntl(socketd, F_SETFL, flags);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-02-02 04:02:44 +08:00
|
|
|
PHP_FUNCTION(socket_set_blocking)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2;
|
|
|
|
int block;
|
|
|
|
int socketd = 0;
|
|
|
|
void *what;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,1,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
block = (*arg2)->value.lval;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
socketd = *(int*)what;
|
|
|
|
|
1999-12-18 12:01:20 +08:00
|
|
|
if (php_set_sock_blocking(socketd, block) == FAILURE)
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-12-18 04:55:31 +08:00
|
|
|
php_sockset_blocking(socketd, block == 0 ? 0 : 1);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
RETURN_TRUE;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-02-02 04:02:44 +08:00
|
|
|
PHP_FUNCTION(set_socket_blocking)
|
|
|
|
{
|
|
|
|
php_error(E_NOTICE, "set_socket_blocking() is deprecated, use socket_set_blocking() instead");
|
|
|
|
PHP_FN(socket_set_blocking)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
|
|
|
}
|
2000-01-16 03:42:40 +08:00
|
|
|
|
2000-06-27 01:57:46 +08:00
|
|
|
/* {{{ proto bool socket_set_timeout(int socket_descriptor, int seconds, int microseconds)
|
2000-01-16 03:42:40 +08:00
|
|
|
Set timeout on socket read to seconds + microseonds */
|
2000-02-02 04:02:44 +08:00
|
|
|
PHP_FUNCTION(socket_set_timeout)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2000-05-27 01:04:02 +08:00
|
|
|
#if HAVE_SYS_TIME_H
|
2000-01-16 03:41:17 +08:00
|
|
|
zval **socket, **seconds, **microseconds;
|
|
|
|
int type;
|
|
|
|
void *what;
|
|
|
|
int socketd = 0;
|
1999-04-17 08:37:12 +08:00
|
|
|
struct timeval t;
|
|
|
|
|
2000-01-16 03:41:17 +08:00
|
|
|
if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 ||
|
|
|
|
zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket, &seconds, µseconds)==FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2000-01-16 03:41:17 +08:00
|
|
|
|
|
|
|
what = zend_fetch_resource(socket, -1, "File-Handle", &type, 1, le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
socketd = *(int *)what;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-01-16 03:41:17 +08:00
|
|
|
convert_to_long_ex(seconds);
|
|
|
|
t.tv_sec = (*seconds)->value.lval;
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() == 3) {
|
|
|
|
convert_to_long_ex(microseconds);
|
|
|
|
t.tv_usec = (*microseconds)->value.lval % 1000000;
|
|
|
|
t.tv_sec += (*microseconds)->value.lval / 1000000;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-01-16 03:41:17 +08:00
|
|
|
else
|
|
|
|
t.tv_usec = 0;
|
|
|
|
|
|
|
|
php_sockset_timeout(socketd, &t);
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_TRUE;
|
2000-01-16 03:41:17 +08:00
|
|
|
#endif /* HAVE_SYS_TIME_H */
|
2000-05-27 01:04:02 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2000-02-02 04:02:44 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* {{{ proto array socket_get_status(resource socket_descriptor)
|
|
|
|
Return an array describing socket status */
|
|
|
|
PHP_FUNCTION(socket_get_status)
|
|
|
|
{
|
|
|
|
zval **socket;
|
|
|
|
int type;
|
|
|
|
void *what;
|
|
|
|
int socketd = 0;
|
|
|
|
struct php_sockbuf *sock;
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
what = zend_fetch_resource(socket, -1, "File-Handle", &type, 1, le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
socketd = *(int *)what;
|
|
|
|
sock = php_get_socket(socketd);
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
|
|
|
add_assoc_bool(return_value, "timed_out", sock->timeout_event);
|
|
|
|
add_assoc_bool(return_value, "blocked", sock->is_blocked);
|
|
|
|
add_assoc_bool(return_value, "eof", sock->eof);
|
|
|
|
add_assoc_long(return_value, "unread_bytes", sock->writepos - sock->readpos);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto string fgets(int fp, int length)
|
1999-10-15 23:22:25 +08:00
|
|
|
Get a line from file pointer */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(fgets)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2;
|
|
|
|
int len, type;
|
1999-04-17 08:37:12 +08:00
|
|
|
char *buf;
|
|
|
|
int issock=0;
|
1999-10-15 23:22:25 +08:00
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
1999-04-17 08:37:12 +08:00
|
|
|
PLS_FETCH();
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
len = (*arg2)->value.lval;
|
2000-08-22 03:24:44 +08:00
|
|
|
if (len < 0) {
|
|
|
|
php_error(E_WARNING, "length parameter to fgets() may not be negative");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
if (type == le_socket) {
|
1999-04-17 08:37:12 +08:00
|
|
|
issock=1;
|
1999-10-15 23:22:25 +08:00
|
|
|
socketd=*(int*)what;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
buf = emalloc(sizeof(char) * (len + 1));
|
|
|
|
/* needed because recv doesnt put a null at the end*/
|
|
|
|
memset(buf,0,len+1);
|
1999-10-15 23:22:25 +08:00
|
|
|
if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) {
|
1999-04-17 08:37:12 +08:00
|
|
|
efree(buf);
|
|
|
|
RETVAL_FALSE;
|
|
|
|
} else {
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
1999-09-04 21:18:59 +08:00
|
|
|
return_value->value.str.val = php_addslashes(buf,0,&return_value->value.str.len,1);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
|
|
|
return_value->value.str.val = buf;
|
|
|
|
return_value->value.str.len = strlen(return_value->value.str.val);
|
2000-06-29 21:34:55 +08:00
|
|
|
/* resize buffer if it's much larger than the result */
|
|
|
|
if(return_value->value.str.len < len/2) {
|
2000-07-07 17:06:47 +08:00
|
|
|
return_value->value.str.val = erealloc(buf,return_value->value.str.len+1);
|
2000-06-29 21:34:55 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
return_value->type = IS_STRING;
|
|
|
|
}
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto string fgetc(int fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Get a character from file pointer */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(fgetc) {
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1;
|
|
|
|
int type;
|
1999-04-17 08:37:12 +08:00
|
|
|
char *buf;
|
|
|
|
int issock=0;
|
1999-10-15 23:22:25 +08:00
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
2000-09-28 00:08:26 +08:00
|
|
|
int result;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if (type == le_socket) {
|
1999-04-17 08:37:12 +08:00
|
|
|
issock=1;
|
1999-10-15 23:22:25 +08:00
|
|
|
socketd=*(int*)what;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2000-08-20 21:24:14 +08:00
|
|
|
buf = emalloc(sizeof(int));
|
2000-09-28 00:08:26 +08:00
|
|
|
if ((result = FP_FGETC(socketd, (FILE*)what, issock)) == EOF) {
|
1999-04-17 08:37:12 +08:00
|
|
|
efree(buf);
|
|
|
|
RETVAL_FALSE;
|
|
|
|
} else {
|
2000-09-28 00:08:26 +08:00
|
|
|
buf[0]=result;
|
1999-04-17 08:37:12 +08:00
|
|
|
buf[1]='\0';
|
|
|
|
return_value->value.str.val = buf;
|
|
|
|
return_value->value.str.len = 1;
|
|
|
|
return_value->type = IS_STRING;
|
|
|
|
}
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2000-06-07 02:58:15 +08:00
|
|
|
|
1999-09-21 04:05:26 +08:00
|
|
|
/* {{{ proto string fgetss(int fp, int length [, string allowable_tags])
|
1999-10-15 23:22:25 +08:00
|
|
|
Get a line from file pointer and strip HTML tags */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(fgetss)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **fd, **bytes, **allow=NULL;
|
|
|
|
int len, type;
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
char *buf;
|
1999-04-17 08:37:12 +08:00
|
|
|
int issock=0;
|
1999-10-15 23:22:25 +08:00
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
2000-02-09 05:29:18 +08:00
|
|
|
char *allowed_tags=NULL;
|
|
|
|
int allowed_tags_len=0;
|
2001-01-13 21:59:22 +08:00
|
|
|
FLS_FETCH();
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-09-20 23:50:56 +08:00
|
|
|
switch(ARG_COUNT(ht)) {
|
1999-10-15 23:22:25 +08:00
|
|
|
case 2:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(3, &fd, &bytes, &allow) == FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
convert_to_string_ex(allow);
|
2000-02-09 05:29:18 +08:00
|
|
|
allowed_tags = (*allow)->value.str.val;
|
|
|
|
allowed_tags_len = (*allow)->value.str.len;
|
1999-10-15 23:22:25 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
what = zend_fetch_resource(fd,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
if (type == le_socket) {
|
|
|
|
issock=1;
|
|
|
|
socketd=*(int*)what;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_long_ex(bytes);
|
|
|
|
len = (*bytes)->value.lval;
|
2000-08-22 03:24:44 +08:00
|
|
|
if (len < 0) {
|
|
|
|
php_error(E_WARNING, "length parameter to fgetss() may not be negative");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
buf = emalloc(sizeof(char) * (len + 1));
|
|
|
|
/*needed because recv doesnt set null char at end*/
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
memset(buf, 0, len + 1);
|
1999-10-15 23:22:25 +08:00
|
|
|
if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) {
|
1999-04-17 08:37:12 +08:00
|
|
|
efree(buf);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
1999-09-22 01:50:51 +08:00
|
|
|
/* strlen() can be used here since we are doing it on the return of an fgets() anyway */
|
2001-01-13 21:59:22 +08:00
|
|
|
php_strip_tags(buf, strlen(buf), FG(fgetss_state), allowed_tags, allowed_tags_len);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
RETURN_STRING(buf, 0);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
/* }}} */
|
2000-06-27 01:57:46 +08:00
|
|
|
/* {{{ proto mixed fscanf(string str, string format [, string ...])
|
|
|
|
Implements a mostly ANSI compatible fscanf() */
|
2000-06-07 02:58:15 +08:00
|
|
|
PHP_FUNCTION(fscanf)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
pval **file_handle, **format_string;
|
|
|
|
int len, type;
|
|
|
|
char *buf;
|
|
|
|
int issock=0;
|
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
|
|
|
|
|
|
|
zval ***args;
|
|
|
|
int argCount;
|
|
|
|
|
|
|
|
argCount = ZEND_NUM_ARGS();
|
|
|
|
if (argCount < 2) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
args = (zval ***)emalloc(argCount * sizeof(zval **));
|
|
|
|
if (!args || (zend_get_parameters_array_ex(argCount,args) == FAILURE)) {
|
|
|
|
efree( args );
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_handle = args[0];
|
|
|
|
format_string = args[1];
|
|
|
|
|
|
|
|
what = zend_fetch_resource(file_handle,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* we can't do a ZEND_VERIFY_RESOURCE(what), otherwise we end up
|
|
|
|
* with a leak if we have an invalid filehandle. This needs changing
|
|
|
|
* if the code behind ZEND_VERIFY_RESOURCE changed. - cc
|
|
|
|
*/
|
|
|
|
if (!what) {
|
|
|
|
efree(args);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = SCAN_MAX_FSCANF_BUFSIZE;
|
|
|
|
|
|
|
|
if (type == le_socket) {
|
|
|
|
issock=1;
|
|
|
|
socketd=*(int*)what;
|
|
|
|
}
|
|
|
|
buf = emalloc(sizeof(char) * (len + 1));
|
|
|
|
/* needed because recv doesnt put a null at the end*/
|
|
|
|
memset(buf,0,len+1);
|
|
|
|
if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) {
|
|
|
|
efree(buf);
|
|
|
|
RETVAL_FALSE;
|
|
|
|
} else {
|
|
|
|
convert_to_string_ex( format_string );
|
|
|
|
result = php_sscanf_internal( buf,(*format_string)->value.str.val,
|
|
|
|
argCount,args, 2,&return_value);
|
|
|
|
efree(args);
|
|
|
|
efree(buf);
|
|
|
|
if (SCAN_ERROR_WRONG_PARAM_COUNT == result) {
|
|
|
|
WRONG_PARAM_COUNT
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int fwrite(int fp, string str [, int length])
|
1999-10-15 23:22:25 +08:00
|
|
|
Binary-safe file write */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(fwrite)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2, **arg3=NULL;
|
|
|
|
int ret,type;
|
1999-04-17 08:37:12 +08:00
|
|
|
int num_bytes;
|
|
|
|
int issock=0;
|
1999-10-15 23:22:25 +08:00
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
1999-04-17 08:37:12 +08:00
|
|
|
PLS_FETCH();
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
switch (ARG_COUNT(ht)) {
|
1999-10-15 23:22:25 +08:00
|
|
|
case 2:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
convert_to_string_ex(arg2);
|
|
|
|
num_bytes = (*arg2)->value.str.len;
|
|
|
|
break;
|
|
|
|
case 3:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(3, &arg1, &arg2, &arg3)==FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
convert_to_string_ex(arg2);
|
|
|
|
convert_to_long_ex(arg3);
|
|
|
|
num_bytes = MIN((*arg3)->value.lval, (*arg2)->value.str.len);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if (type == le_socket) {
|
1999-04-17 08:37:12 +08:00
|
|
|
issock=1;
|
1999-10-15 23:22:25 +08:00
|
|
|
socketd=*(int*)what;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!arg3 && PG(magic_quotes_runtime)) {
|
1999-10-15 23:22:25 +08:00
|
|
|
zval_copy_ctor(*arg2);
|
|
|
|
php_stripslashes((*arg2)->value.str.val,&num_bytes);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (issock){
|
1999-10-15 23:22:25 +08:00
|
|
|
ret = SOCK_WRITEL((*arg2)->value.str.val,num_bytes,socketd);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
1999-10-15 23:22:25 +08:00
|
|
|
ret = fwrite((*arg2)->value.str.val,1,num_bytes,(FILE*)what);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
1999-04-21 12:02:11 +08:00
|
|
|
|
2000-06-06 20:16:44 +08:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ proto int fflush(int fp)
|
2000-06-27 01:57:46 +08:00
|
|
|
Flushes output */
|
2000-06-06 20:16:44 +08:00
|
|
|
|
|
|
|
PHP_FUNCTION(fflush)
|
|
|
|
{
|
|
|
|
pval **arg1;
|
|
|
|
int ret,type;
|
|
|
|
int issock=0;
|
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
|
|
|
|
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if (type == le_socket) {
|
|
|
|
issock=1;
|
|
|
|
socketd=*(int*)what;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (issock){
|
|
|
|
ret = fsync(socketd);
|
|
|
|
} else {
|
|
|
|
ret = fflush((FILE*)what);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
} else {
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
/* {{{ proto int set_file_buffer(int fp, int buffer)
|
|
|
|
Set file write buffer */
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-07-25 06:16:54 +08:00
|
|
|
PHP_FUNCTION(set_file_buffer)
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2;
|
|
|
|
int ret,type,buff;
|
|
|
|
void *what;
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
|
|
|
|
switch (ARG_COUNT(ht)) {
|
1999-10-15 23:22:25 +08:00
|
|
|
case 2:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(2, &arg1, &arg2)==FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,2,le_fopen,le_popen);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
buff = (*arg2)->value.lval;
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
|
|
|
|
/* if buff is 0 then set to non-buffered */
|
|
|
|
if (buff == 0){
|
1999-10-15 23:22:25 +08:00
|
|
|
ret = setvbuf((FILE*)what, NULL, _IONBF, 0);
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
} else {
|
1999-10-15 23:22:25 +08:00
|
|
|
ret = setvbuf((FILE*)what, NULL, _IOFBF, buff);
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int rewind(int fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Rewind the position of a file pointer */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(rewind)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1;
|
|
|
|
void *what;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,2,le_fopen,le_popen);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
rewind((FILE*) what);
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int ftell(int fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Get file pointer's read/write position */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(ftell)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1;
|
|
|
|
void *what;
|
2000-08-20 21:24:14 +08:00
|
|
|
long ret;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,2,le_fopen,le_popen);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
2000-08-20 21:24:14 +08:00
|
|
|
|
|
|
|
ret = ftell((FILE*) what);
|
|
|
|
if(ret == -1) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2000-08-20 21:24:14 +08:00
|
|
|
RETURN_LONG(ret);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2000-04-24 22:18:11 +08:00
|
|
|
/* {{{ proto int fseek(int fp, int offset [, int whence])
|
1999-10-15 23:22:25 +08:00
|
|
|
Seek on a file pointer */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(fseek)
|
|
|
|
{
|
2000-04-24 22:18:11 +08:00
|
|
|
zval **arg1, **arg2, **arg3;
|
|
|
|
int argcount = ARG_COUNT(ht), whence = SEEK_SET;
|
1999-10-15 23:22:25 +08:00
|
|
|
void *what;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-04-24 03:16:24 +08:00
|
|
|
if (argcount < 2 || argcount > 3 ||
|
|
|
|
zend_get_parameters_ex(argcount, &arg1, &arg2, &arg3) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",NULL,2,le_fopen,le_popen);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_long_ex(arg2);
|
2000-04-24 03:16:24 +08:00
|
|
|
if (argcount > 2) {
|
|
|
|
convert_to_long_ex(arg3);
|
2000-04-24 22:18:11 +08:00
|
|
|
whence = (*arg3)->value.lval;
|
2000-04-24 03:16:24 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2000-04-24 22:18:11 +08:00
|
|
|
RETURN_LONG(fseek((FILE*)what, (*arg2)->value.lval, whence));
|
1999-10-15 23:22:25 +08:00
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int mkdir(string pathname, int mode)
|
1999-10-15 23:22:25 +08:00
|
|
|
Create a directory */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(mkdir)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2;
|
2000-11-01 02:05:19 +08:00
|
|
|
int ret;
|
|
|
|
mode_t mode;
|
1999-04-21 12:02:11 +08:00
|
|
|
PLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(arg1);
|
|
|
|
convert_to_long_ex(arg2);
|
2000-11-01 02:05:19 +08:00
|
|
|
mode = (mode_t) (*arg2)->value.lval;
|
2000-11-03 07:08:07 +08:00
|
|
|
if (PG(safe_mode) &&(!php_checkuid((*arg1)->value.str.val, NULL, CHECKUID_ALLOW_ONLY_DIR))) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-11-01 02:05:19 +08:00
|
|
|
ret = V_MKDIR((*arg1)->value.str.val, mode);
|
1999-04-17 08:37:12 +08:00
|
|
|
if (ret < 0) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"MkDir failed (%s)", strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int rmdir(string dirname)
|
1999-10-15 23:22:25 +08:00
|
|
|
Remove a directory */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(rmdir)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1;
|
1999-04-17 08:37:12 +08:00
|
|
|
int ret;
|
1999-04-21 12:02:11 +08:00
|
|
|
PLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(arg1);
|
2000-11-03 07:08:07 +08:00
|
|
|
if (PG(safe_mode) &&(!php_checkuid((*arg1)->value.str.val, NULL, CHECKUID_ALLOW_FILE_NOT_EXISTS))) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-09-12 12:13:21 +08:00
|
|
|
ret = V_RMDIR((*arg1)->value.str.val);
|
1999-04-17 08:37:12 +08:00
|
|
|
if (ret < 0) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING,"RmDir failed (%s)", strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* }}} */
|
1999-10-15 23:22:25 +08:00
|
|
|
/* {{{ php_passthru_fd */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-09-12 02:15:39 +08:00
|
|
|
static size_t php_passthru_fd(int socketd, FILE *fp, int issock)
|
|
|
|
{
|
|
|
|
size_t bcount = 0;
|
|
|
|
int ready = 0;
|
1999-09-12 02:38:34 +08:00
|
|
|
char buf[8192];
|
1999-09-12 02:15:39 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_MMAP
|
|
|
|
if(!issock) {
|
|
|
|
int fd;
|
|
|
|
struct stat sbuf;
|
|
|
|
off_t off;
|
|
|
|
void *p;
|
|
|
|
size_t len;
|
|
|
|
|
|
|
|
fd = fileno(fp);
|
|
|
|
fstat(fd, &sbuf);
|
|
|
|
|
2000-09-12 00:25:36 +08:00
|
|
|
if (sbuf.st_size > sizeof(buf)) {
|
1999-09-12 02:38:34 +08:00
|
|
|
off = ftell(fp);
|
|
|
|
len = sbuf.st_size - off;
|
|
|
|
p = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, off);
|
2000-09-12 00:25:36 +08:00
|
|
|
if (p != (void *) MAP_FAILED) {
|
1999-09-12 02:38:34 +08:00
|
|
|
PHPWRITE(p, len);
|
|
|
|
munmap(p, len);
|
|
|
|
bcount += len;
|
|
|
|
ready = 1;
|
|
|
|
}
|
1999-09-12 02:15:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!ready) {
|
|
|
|
int b;
|
|
|
|
|
|
|
|
while ((b = FP_FREAD(buf, sizeof(buf), socketd, fp, issock)) > 0) {
|
|
|
|
PHPWRITE(buf, b);
|
|
|
|
bcount += b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bcount;
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int readfile(string filename [, int use_include_path])
|
1999-10-15 23:22:25 +08:00
|
|
|
Output a file or a URL */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(readfile)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2;
|
1999-04-17 08:37:12 +08:00
|
|
|
FILE *fp;
|
1999-09-12 02:15:39 +08:00
|
|
|
int size=0;
|
|
|
|
int use_include_path=0;
|
1999-04-17 08:37:12 +08:00
|
|
|
int issock=0, socketd=0;
|
|
|
|
|
|
|
|
/* check args */
|
|
|
|
switch (ARG_COUNT(ht)) {
|
|
|
|
case 1:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(1,&arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(2,&arg1,&arg2) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
use_include_path = (*arg2)->value.lval;
|
1999-04-17 08:37:12 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(arg1);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We need a better way of returning error messages from
|
1999-12-18 03:16:50 +08:00
|
|
|
* php_fopen_wrapper().
|
1999-04-17 08:37:12 +08:00
|
|
|
*/
|
2000-12-13 01:42:53 +08:00
|
|
|
fp = php_fopen_wrapper((*arg1)->value.str.val,"rb", use_include_path|ENFORCE_SAFE_MODE, &issock, &socketd, NULL);
|
1999-04-17 08:37:12 +08:00
|
|
|
if (!fp && !socketd){
|
|
|
|
if (issock != BAD_URL) {
|
2000-11-01 22:48:00 +08:00
|
|
|
char *tmp = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1));
|
1999-12-18 03:16:50 +08:00
|
|
|
php_strip_url_passwd(tmp);
|
1999-10-15 23:22:25 +08:00
|
|
|
php_error(E_WARNING,"readfile(\"%s\") - %s", tmp, strerror(errno));
|
|
|
|
efree(tmp);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-12-18 03:51:39 +08:00
|
|
|
if (php_header()) {
|
1999-09-12 02:15:39 +08:00
|
|
|
size = php_passthru_fd(socketd, fp, issock);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
if (issock) {
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
SOCK_FCLOSE(socketd);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
RETURN_LONG(size);
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int umask([int mask])
|
1999-10-15 23:22:25 +08:00
|
|
|
Return or change the umask */
|
|
|
|
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
PHP_FUNCTION(umask)
|
1999-06-16 05:51:00 +08:00
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1;
|
1999-04-17 08:37:12 +08:00
|
|
|
int oldumask;
|
|
|
|
int arg_count = ARG_COUNT(ht);
|
|
|
|
|
|
|
|
oldumask = umask(077);
|
|
|
|
|
|
|
|
if (arg_count == 0) {
|
|
|
|
umask(oldumask);
|
1999-10-15 23:22:25 +08:00
|
|
|
} else {
|
1999-12-19 06:40:35 +08:00
|
|
|
if (arg_count > 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_long_ex(arg1);
|
|
|
|
umask((*arg1)->value.lval);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
/* XXX we should maybe reset the umask after each request! */
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_LONG(oldumask);
|
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int fpassthru(int fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Output all remaining data from a file pointer */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(fpassthru)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1;
|
|
|
|
int size, type;
|
1999-04-17 08:37:12 +08:00
|
|
|
int issock=0;
|
1999-10-15 23:22:25 +08:00
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if (type == le_socket) {
|
1999-04-17 08:37:12 +08:00
|
|
|
issock=1;
|
1999-10-15 23:22:25 +08:00
|
|
|
socketd=*(int*)what;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
size = 0;
|
1999-12-18 03:51:39 +08:00
|
|
|
if (php_header()) { /* force headers if not already sent */
|
1999-10-15 23:22:25 +08:00
|
|
|
size = php_passthru_fd(socketd, (FILE*) what, issock);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-12-18 03:51:39 +08:00
|
|
|
zend_list_delete((*arg1)->value.lval);
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_LONG(size);
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2000-07-02 23:12:34 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int rename(string old_name, string new_name)
|
1999-10-15 23:22:25 +08:00
|
|
|
Rename a file */
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(rename)
|
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **old_arg, **new_arg;
|
1999-06-16 05:51:00 +08:00
|
|
|
char *old_name, *new_name;
|
1999-04-17 08:37:12 +08:00
|
|
|
int ret;
|
1999-04-21 12:02:11 +08:00
|
|
|
PLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &old_arg, &new_arg) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(old_arg);
|
|
|
|
convert_to_string_ex(new_arg);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
old_name = (*old_arg)->value.str.val;
|
|
|
|
new_name = (*new_arg)->value.str.val;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-11-03 07:08:07 +08:00
|
|
|
if (PG(safe_mode) &&(!php_checkuid(old_name, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2000-10-27 02:17:45 +08:00
|
|
|
ret = V_RENAME(old_name, new_name);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
if (ret == -1) {
|
1999-10-15 23:22:25 +08:00
|
|
|
php_error(E_WARNING,"Rename failed (%s)", strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RETVAL_TRUE;
|
|
|
|
}
|
2000-07-02 23:12:34 +08:00
|
|
|
/* }}} */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2000-07-02 23:12:34 +08:00
|
|
|
/* {{{ proto int unlink(string filename)
|
|
|
|
Delete a file */
|
|
|
|
PHP_FUNCTION(unlink)
|
|
|
|
{
|
|
|
|
pval **filename;
|
|
|
|
int ret;
|
|
|
|
PLS_FETCH();
|
|
|
|
|
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_string_ex(filename);
|
|
|
|
|
2000-11-03 07:08:07 +08:00
|
|
|
if (PG(safe_mode) && !php_checkuid((*filename)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR)) {
|
2000-07-02 23:12:34 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = V_UNLINK((*filename)->value.str.val);
|
|
|
|
if (ret == -1) {
|
|
|
|
php_error(E_WARNING, "Unlink failed (%s)", strerror(errno));
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
/* Clear stat cache */
|
|
|
|
PHP_FN(clearstatcache)(INTERNAL_FUNCTION_PARAM_PASSTHRU);
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2000-07-02 23:12:34 +08:00
|
|
|
|
|
|
|
|
2000-03-05 01:23:03 +08:00
|
|
|
/* {{{ proto int ftruncate (int fp, int size)
|
|
|
|
Truncate file to 'size' length */
|
2000-12-07 20:09:38 +08:00
|
|
|
PHP_NAMED_FUNCTION(php_if_ftruncate)
|
2000-03-05 01:23:03 +08:00
|
|
|
{
|
|
|
|
zval **fp , **size;
|
|
|
|
short int ret;
|
|
|
|
int type;
|
|
|
|
void *what;
|
|
|
|
|
|
|
|
if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &fp, &size) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
what = zend_fetch_resource(fp,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if (type == le_socket)
|
|
|
|
{
|
|
|
|
php_error(E_WARNING, "can't truncate sockets!");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_long_ex(size);
|
|
|
|
|
|
|
|
ret = ftruncate(fileno((FILE *)what), (*size)->value.lval);
|
2000-03-17 08:44:55 +08:00
|
|
|
RETURN_LONG(ret + 1);
|
2000-03-05 01:23:03 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2000-06-27 01:57:46 +08:00
|
|
|
/* {{{ proto int fstat(int fp)
|
2000-03-05 01:23:03 +08:00
|
|
|
Stat() on a filehandle */
|
2000-12-07 20:09:38 +08:00
|
|
|
PHP_NAMED_FUNCTION(php_if_fstat)
|
2000-03-05 01:23:03 +08:00
|
|
|
{
|
|
|
|
zval **fp;
|
|
|
|
int type;
|
|
|
|
void *what;
|
|
|
|
struct stat stat_sb;
|
|
|
|
|
|
|
|
if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &fp) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
what = zend_fetch_resource(fp,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if (fstat(fileno((FILE *) what ), &stat_sb)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
|
|
|
add_assoc_long ( return_value , "dev" , stat_sb.st_dev );
|
|
|
|
add_assoc_long ( return_value , "ino" , stat_sb.st_ino );
|
|
|
|
add_assoc_long ( return_value , "mode" , stat_sb.st_mode );
|
|
|
|
add_assoc_long ( return_value , "nlink" , stat_sb.st_nlink );
|
|
|
|
add_assoc_long ( return_value , "uid" , stat_sb.st_uid );
|
|
|
|
add_assoc_long ( return_value , "gid" , stat_sb.st_gid );
|
|
|
|
|
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
|
|
|
add_assoc_long ( return_value, "rdev" , stat_sb.st_rdev );
|
|
|
|
add_assoc_long ( return_value , "blksize" , stat_sb.st_blksize );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
add_assoc_long ( return_value , "size" , stat_sb.st_size );
|
|
|
|
add_assoc_long ( return_value , "atime" , stat_sb.st_atime );
|
|
|
|
add_assoc_long ( return_value , "mtime" , stat_sb.st_mtime );
|
|
|
|
add_assoc_long ( return_value , "ctime" , stat_sb.st_ctime );
|
|
|
|
|
|
|
|
#ifdef HAVE_ST_BLOCKS
|
|
|
|
add_assoc_long ( return_value , "blocks" , stat_sb.st_blocks );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int copy(string source_file, string destination_file)
|
1999-10-15 23:22:25 +08:00
|
|
|
Copy a file */
|
|
|
|
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
PHP_FUNCTION(copy)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **source, **target;
|
1999-04-21 12:02:11 +08:00
|
|
|
PLS_FETCH();
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &source, &target) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(source);
|
|
|
|
convert_to_string_ex(target);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-11-03 07:08:07 +08:00
|
|
|
if (PG(safe_mode) &&(!php_checkuid((*source)->value.str.val, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2000-09-09 06:31:21 +08:00
|
|
|
if (php_copy_file(Z_STRVAL_PP(source), Z_STRVAL_PP(target))==SUCCESS) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
|
|
|
|
PHPAPI int php_copy_file(char *src, char *dest)
|
|
|
|
{
|
|
|
|
char buffer[8192];
|
|
|
|
int fd_s,fd_t,read_bytes;
|
2000-12-23 00:34:11 +08:00
|
|
|
int ret = FAILURE;
|
2000-09-09 06:31:21 +08:00
|
|
|
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef PHP_WIN32
|
2000-09-09 06:31:21 +08:00
|
|
|
if ((fd_s=V_OPEN((src,O_RDONLY|_O_BINARY)))==-1) {
|
1999-04-17 08:37:12 +08:00
|
|
|
#else
|
2000-09-09 06:31:21 +08:00
|
|
|
if ((fd_s=V_OPEN((src,O_RDONLY)))==-1) {
|
1999-04-17 08:37:12 +08:00
|
|
|
#endif
|
2000-09-09 06:31:21 +08:00
|
|
|
php_error(E_WARNING,"Unable to open '%s' for reading: %s", src, strerror(errno));
|
|
|
|
return FAILURE;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-02-11 23:59:30 +08:00
|
|
|
#ifdef PHP_WIN32
|
2000-09-09 06:31:21 +08:00
|
|
|
if ((fd_t=V_OPEN((dest,_O_WRONLY|_O_CREAT|_O_TRUNC|_O_BINARY,_S_IREAD|_S_IWRITE)))==-1) {
|
1999-04-17 08:37:12 +08:00
|
|
|
#else
|
2000-09-09 09:15:50 +08:00
|
|
|
if ((fd_t=V_CREAT(dest,0777))==-1) {
|
1999-04-17 08:37:12 +08:00
|
|
|
#endif
|
2000-09-09 06:31:21 +08:00
|
|
|
php_error(E_WARNING,"Unable to create '%s': %s", dest, strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
close(fd_s);
|
2000-09-09 06:31:21 +08:00
|
|
|
return FAILURE;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
2000-12-23 00:34:11 +08:00
|
|
|
#ifdef HAVE_MMAP
|
|
|
|
{
|
|
|
|
void *srcfile;
|
|
|
|
struct stat sbuf;
|
|
|
|
|
|
|
|
if (fstat(fd_s, &sbuf)) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
srcfile = mmap(NULL, sbuf.st_size, PROT_READ, MAP_SHARED, fd_s, 0);
|
2000-12-23 00:39:01 +08:00
|
|
|
if (srcfile != (void *) MAP_FAILED) {
|
2000-12-23 03:26:02 +08:00
|
|
|
if (write(fd_t, srcfile, sbuf.st_size) == sbuf.st_size)
|
|
|
|
ret = SUCCESS;
|
2000-12-23 00:34:11 +08:00
|
|
|
munmap(srcfile, sbuf.st_size);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
while ((read_bytes=read(fd_s,buffer,8192))!=-1 && read_bytes!=0) {
|
|
|
|
if (write(fd_t,buffer,read_bytes)==-1) {
|
2000-09-09 06:31:21 +08:00
|
|
|
php_error(E_WARNING,"Unable to write to '%s': %s", dest, strerror(errno));
|
2000-12-23 00:34:11 +08:00
|
|
|
goto cleanup;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
2000-12-23 00:34:11 +08:00
|
|
|
ret = SUCCESS;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-12-23 00:34:11 +08:00
|
|
|
cleanup:
|
1999-04-17 08:37:12 +08:00
|
|
|
close(fd_s);
|
|
|
|
close(fd_t);
|
2000-12-23 00:34:11 +08:00
|
|
|
return ret;
|
2000-09-09 06:31:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* {{{ proto int fread(int fp, int length)
|
1999-10-15 23:22:25 +08:00
|
|
|
Binary-safe file read */
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(fread)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **arg1, **arg2;
|
|
|
|
int len, type;
|
1999-04-17 08:37:12 +08:00
|
|
|
int issock=0;
|
1999-10-15 23:22:25 +08:00
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
1999-04-17 08:37:12 +08:00
|
|
|
PLS_FETCH();
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if (ARG_COUNT(ht) != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
what = zend_fetch_resource(arg1,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if (type == le_socket) {
|
1999-04-17 08:37:12 +08:00
|
|
|
issock=1;
|
1999-10-15 23:22:25 +08:00
|
|
|
socketd=*(int*)what;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
len = (*arg2)->value.lval;
|
2000-08-22 03:24:44 +08:00
|
|
|
if (len < 0) {
|
|
|
|
php_error(E_WARNING, "length parameter to fread() may not be negative");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
return_value->value.str.val = emalloc(sizeof(char) * (len + 1));
|
|
|
|
/* needed because recv doesnt put a null at the end*/
|
|
|
|
|
|
|
|
if (!issock) {
|
1999-10-15 23:22:25 +08:00
|
|
|
return_value->value.str.len = fread(return_value->value.str.val, 1, len, (FILE*)what);
|
1999-04-17 08:37:12 +08:00
|
|
|
return_value->value.str.val[return_value->value.str.len] = 0;
|
|
|
|
} else {
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
return_value->value.str.len = SOCK_FREAD(return_value->value.str.val, len, socketd);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
1999-09-04 21:18:59 +08:00
|
|
|
return_value->value.str.val = php_addslashes(return_value->value.str.val,return_value->value.str.len,&return_value->value.str.len,1);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
return_value->type = IS_STRING;
|
|
|
|
}
|
1999-06-16 01:06:22 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2000-12-14 22:18:36 +08:00
|
|
|
/* {{{ proto array fgetcsv(int fp, int length [, string delimiter])
|
2000-02-24 16:07:29 +08:00
|
|
|
Get line from file pointer and parse for CSV fields */
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(fgetcsv) {
|
2000-04-19 21:03:47 +08:00
|
|
|
char *temp, *tptr, *bptr, *lineEnd;
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
char delimiter = ','; /* allow this to be set as parameter */
|
1999-04-27 21:06:58 +08:00
|
|
|
|
1999-12-18 12:01:20 +08:00
|
|
|
/* first section exactly as php_fgetss */
|
1999-04-27 21:06:58 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
pval **fd, **bytes, **p_delim;
|
|
|
|
int len, type;
|
1999-06-11 17:23:00 +08:00
|
|
|
char *buf;
|
1999-04-27 21:06:58 +08:00
|
|
|
int issock=0;
|
1999-10-15 23:22:25 +08:00
|
|
|
int socketd=0;
|
|
|
|
void *what;
|
|
|
|
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
switch(ARG_COUNT(ht)) {
|
1999-10-15 23:22:25 +08:00
|
|
|
case 2:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
break;
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
case 3:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(3, &fd, &bytes, &p_delim) == FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_string_ex(p_delim);
|
|
|
|
/* Make sure that there is at least one character in string */
|
|
|
|
if ((*p_delim)->value.str.len < 1) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
/* use first character from string */
|
1999-10-15 23:22:25 +08:00
|
|
|
delimiter = (*p_delim)->value.str.val[0];
|
|
|
|
break;
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
1999-04-27 21:06:58 +08:00
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
what = zend_fetch_resource(fd,-1,"File-Handle",&type,3,le_fopen,le_popen,le_socket);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
1999-04-27 21:06:58 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
if (type == le_socket) {
|
|
|
|
issock=1;
|
|
|
|
socketd=*(int*)what;
|
1999-04-27 21:06:58 +08:00
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_long_ex(bytes);
|
|
|
|
len = (*bytes)->value.lval;
|
2000-08-22 03:24:44 +08:00
|
|
|
if (len < 0) {
|
|
|
|
php_error(E_WARNING, "length parameter to fgetcsv() may not be negative");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-04-27 21:06:58 +08:00
|
|
|
buf = emalloc(sizeof(char) * (len + 1));
|
|
|
|
/*needed because recv doesnt set null char at end*/
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
memset(buf, 0, len + 1);
|
1999-10-15 23:22:25 +08:00
|
|
|
if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) {
|
1999-04-27 21:06:58 +08:00
|
|
|
efree(buf);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now into new section that parses buf for comma/quote delimited fields */
|
|
|
|
|
2000-04-19 21:03:47 +08:00
|
|
|
/* Strip trailing space from buf, saving end of line in case required for quoted field */
|
1999-04-27 21:06:58 +08:00
|
|
|
|
2000-04-19 21:03:47 +08:00
|
|
|
lineEnd = emalloc(sizeof(char) * (len + 1));
|
|
|
|
bptr = buf;
|
|
|
|
tptr = buf + strlen(buf) -1;
|
2000-12-14 22:18:36 +08:00
|
|
|
while ( isspace((int)*tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--;
|
2000-04-19 21:03:47 +08:00
|
|
|
tptr++;
|
|
|
|
strcpy(lineEnd, tptr);
|
1999-04-27 21:06:58 +08:00
|
|
|
|
|
|
|
/* add single space - makes it easier to parse trailing null field */
|
2000-04-19 21:03:47 +08:00
|
|
|
*tptr++ = ' ';
|
|
|
|
*tptr = 0;
|
1999-04-27 21:06:58 +08:00
|
|
|
|
|
|
|
/* reserve workspace for building each individual field */
|
|
|
|
|
|
|
|
temp = emalloc(sizeof(char) * len); /* unlikely but possible! */
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
tptr = temp;
|
1999-04-27 21:06:58 +08:00
|
|
|
|
|
|
|
/* Initialize return array */
|
|
|
|
if (array_init(return_value) == FAILURE) {
|
2000-04-19 21:03:47 +08:00
|
|
|
efree(lineEnd);
|
1999-04-27 21:06:58 +08:00
|
|
|
efree(temp);
|
|
|
|
efree(buf);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Main loop to read CSV fields */
|
|
|
|
/* NB this routine will return a single null entry for a blank line */
|
|
|
|
|
|
|
|
do {
|
|
|
|
/* 1. Strip any leading space */
|
2000-12-14 22:18:36 +08:00
|
|
|
while(isspace((int)*bptr) && (*bptr!=delimiter)) bptr++;
|
1999-04-27 21:06:58 +08:00
|
|
|
/* 2. Read field, leaving bptr pointing at start of next field */
|
|
|
|
if (*bptr == '"') {
|
|
|
|
/* 2A. handle quote delimited field */
|
|
|
|
bptr++; /* move on to first character in field */
|
|
|
|
while (*bptr) {
|
|
|
|
if (*bptr == '"') {
|
|
|
|
/* handle the double-quote */
|
|
|
|
if ( *(bptr+1) == '"') {
|
|
|
|
/* embedded double quotes */
|
|
|
|
*tptr++ = *bptr; bptr +=2;
|
|
|
|
} else {
|
|
|
|
/* must be end of string - skip to start of next field or end */
|
|
|
|
while ( (*bptr != delimiter) && *bptr ) bptr++;
|
|
|
|
if (*bptr == delimiter) bptr++;
|
|
|
|
*tptr=0; /* terminate temporary string */
|
|
|
|
break; /* .. from handling this field - resumes at 3. */
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* normal character */
|
|
|
|
*tptr++ = *bptr++;
|
2000-04-19 21:03:47 +08:00
|
|
|
|
|
|
|
if (*bptr == 0) { /* embedded line end? */
|
|
|
|
*(tptr-1)=0; /* remove space character added on reading line */
|
|
|
|
strcat(temp,lineEnd); /* add the embedded line end to the field */
|
|
|
|
|
|
|
|
/* read a new line from input, as at start of routine */
|
|
|
|
memset(buf,0,len+1);
|
|
|
|
if (FP_FGETS(buf, len, socketd, (FILE*)what, issock) == NULL) {
|
|
|
|
efree(lineEnd); efree(temp); efree(buf);
|
2000-06-27 17:55:52 +08:00
|
|
|
zval_dtor(return_value);
|
2000-04-19 21:03:47 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
bptr = buf;
|
|
|
|
tptr = buf + strlen(buf) -1;
|
2000-12-14 22:18:36 +08:00
|
|
|
while ( isspace((int)*tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--;
|
2000-04-19 21:03:47 +08:00
|
|
|
tptr++; strcpy(lineEnd, tptr);
|
|
|
|
*tptr++ = ' '; *tptr = 0;
|
|
|
|
|
|
|
|
tptr=temp; /* reset temp pointer to end of field as read so far */
|
|
|
|
while (*tptr) tptr++;
|
|
|
|
}
|
1999-04-27 21:06:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* 2B. Handle non-quoted field */
|
|
|
|
while ( (*bptr != delimiter) && *bptr ) *tptr++ = *bptr++;
|
|
|
|
*tptr=0; /* terminate temporary string */
|
|
|
|
if (strlen(temp)) {
|
|
|
|
tptr--;
|
2000-12-14 22:18:36 +08:00
|
|
|
while (isspace((int)*tptr) && (*tptr!=delimiter)) *tptr-- = 0; /* strip any trailing spaces */
|
1999-04-27 21:06:58 +08:00
|
|
|
}
|
|
|
|
if (*bptr == delimiter) bptr++;
|
|
|
|
}
|
|
|
|
/* 3. Now pass our field back to php */
|
|
|
|
add_next_index_string(return_value, temp, 1);
|
|
|
|
tptr=temp;
|
|
|
|
} while (*bptr);
|
2000-04-19 21:03:47 +08:00
|
|
|
|
|
|
|
efree(lineEnd);
|
1999-04-27 21:06:58 +08:00
|
|
|
efree(temp);
|
|
|
|
efree(buf);
|
|
|
|
}
|
* fixed some #if/#ifdef issues
* hand-patched in php3 changes from 3.0.6 to HEAD in these files:
fopen-wrappers.[ch] ext/standard/file.[ch] ext/standard/fsock.[ch]
ext/standard/php3_string.h ext/standard/string.c
* added some new file/socket macros for more readable code:
FP_FGETS(buf,len,sock,fp,issock)
FP_FREAD(buf,len,sock,fp,issock)
FP_FEOF(sock,fp,issock)
FP_FGETC(sock,fp,issock)
1999-06-17 01:06:53 +08:00
|
|
|
|
1999-04-27 21:06:58 +08:00
|
|
|
/* }}} */
|
|
|
|
|
2000-12-27 23:43:05 +08:00
|
|
|
|
|
|
|
#if !defined(PHP_WIN32) || defined(ZTS)
|
2000-02-01 14:06:03 +08:00
|
|
|
/* {{{ proto string realpath(string path)
|
2000-02-02 04:02:44 +08:00
|
|
|
Return the resolved path */
|
2000-02-01 14:06:03 +08:00
|
|
|
PHP_FUNCTION(realpath)
|
|
|
|
{
|
|
|
|
zval **path;
|
2000-08-07 00:22:07 +08:00
|
|
|
char resolved_path_buff[MAXPATHLEN];
|
2000-02-01 14:06:03 +08:00
|
|
|
|
2000-02-02 04:02:44 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(ZEND_NUM_ARGS(), &path) == FAILURE) {
|
2000-02-01 14:06:03 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_string_ex(path);
|
2000-08-07 00:22:07 +08:00
|
|
|
|
|
|
|
if (V_REALPATH((*path)->value.str.val, resolved_path_buff)) {
|
|
|
|
RETURN_STRING(resolved_path_buff, 1);
|
2000-02-01 14:06:03 +08:00
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
2000-12-27 23:43:05 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-07 02:58:15 +08:00
|
|
|
|
1999-12-22 00:51:27 +08:00
|
|
|
#if 0
|
|
|
|
|
|
|
|
static fd_set readfd;
|
|
|
|
static int max_fd;
|
|
|
|
|
1999-11-24 11:05:10 +08:00
|
|
|
PHP_FUNCTION(fd_set)
|
|
|
|
{
|
|
|
|
pval **arg;
|
|
|
|
void *what;
|
|
|
|
int type, fd;
|
|
|
|
|
|
|
|
if(ARG_COUNT(ht) <= 0) {
|
|
|
|
php_error(E_WARNING, "fd_set: Must be passed at least one value" );
|
|
|
|
var_uninit(return_value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if(ARG_COUNT(ht) == 1) {
|
1999-12-19 06:40:35 +08:00
|
|
|
if(zend_get_parameters_ex(1, &arg) == FAILURE) {
|
1999-11-24 11:05:10 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-11-24 11:47:58 +08:00
|
|
|
what = zend_fetch_resource(arg,-1,"select",&type,3,le_fopen,le_socket,le_popen);
|
1999-11-24 11:05:10 +08:00
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
if(type == le_socket) {
|
|
|
|
fd = *(int *)what;
|
|
|
|
} else {
|
|
|
|
fd = fileno((FILE *)what);
|
|
|
|
}
|
|
|
|
max_fd = fd;
|
|
|
|
FD_ZERO(&readfd);
|
|
|
|
FD_SET(max_fd, &readfd);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pval ***args = (pval ***) emalloc(sizeof(pval **) * ARG_COUNT(ht));
|
|
|
|
int i;
|
1999-12-19 06:40:35 +08:00
|
|
|
if(zend_get_parameters_array_ex(ARG_COUNT(ht), args) == FAILURE) {
|
1999-11-24 11:05:10 +08:00
|
|
|
efree(args);
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
FD_ZERO(&readfd);
|
|
|
|
for(i = 0; i < ARG_COUNT(ht); i++) {
|
|
|
|
what = zend_fetch_resource(*args,-1,"select",&type,3,le_fopen,le_socket,le_popen);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
if(type == le_socket) {
|
|
|
|
fd = *(int *)what;
|
|
|
|
} else {
|
|
|
|
fd = fileno((FILE *)what);
|
|
|
|
}
|
|
|
|
FD_SET(fd, &readfd);
|
|
|
|
if(fd > max_fd) max_fd = fd;
|
|
|
|
}
|
1999-11-24 14:16:37 +08:00
|
|
|
efree(args);
|
1999-11-24 11:05:10 +08:00
|
|
|
}
|
|
|
|
RETURN_LONG(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
PHP_FUNCTION(select)
|
|
|
|
{
|
|
|
|
pval **timeout;
|
|
|
|
struct timeval tv;
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if(ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &timeout) == FAILURE) {
|
1999-11-24 11:05:10 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
convert_to_long_ex(timeout);
|
|
|
|
|
|
|
|
tv.tv_sec = (*timeout)->value.lval / 1000000;
|
|
|
|
tv.tv_usec = (*timeout)->value.lval % 1000000;
|
|
|
|
|
|
|
|
RETURN_LONG(select(max_fd + 1,&readfd,NULL,NULL,((*timeout)->value.lval <= 0) ? NULL : &tv));
|
|
|
|
}
|
|
|
|
|
1999-11-24 11:47:58 +08:00
|
|
|
PHP_FUNCTION(fd_isset)
|
|
|
|
{
|
|
|
|
pval **fdarg;
|
|
|
|
void *what;
|
|
|
|
int type, fd;
|
|
|
|
|
1999-12-19 06:40:35 +08:00
|
|
|
if(ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &fdarg) == FAILURE) {
|
1999-11-24 11:47:58 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
what = zend_fetch_resource(fdarg,-1,"select",&type,3,le_fopen,le_socket,le_popen);
|
|
|
|
ZEND_VERIFY_RESOURCE(what);
|
|
|
|
|
|
|
|
if(type == le_socket) {
|
|
|
|
fd = *(int *)what;
|
|
|
|
} else {
|
|
|
|
fd = fileno((FILE *)what);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(FD_ISSET(fd,&readfd)) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-12-22 00:51:27 +08:00
|
|
|
|
|
|
|
#endif
|
2000-03-07 04:37:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
|
|
|
*/
|