1999-04-17 08:37:12 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2001-12-11 23:32:16 +08:00
|
|
|
| PHP Version 4 |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2003-01-01 00:08:15 +08:00
|
|
|
| Copyright (c) 1997-2003 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
|
|
|
+----------------------------------------------------------------------+
|
2002-02-28 16:29:35 +08:00
|
|
|
| Authors: Rasmus Lerdorf <rasmus@php.net> |
|
2000-09-09 19:41:14 +08:00
|
|
|
| Stig Bakken <ssb@fast.no> |
|
|
|
|
| Andi Gutmans <andi@zend.com> |
|
|
|
|
| Zeev Suraski <zeev@zend.com> |
|
2002-03-16 05:03:08 +08:00
|
|
|
| PHP 4.0 patches by Thies C. Arntzen (thies@thieso.net) |
|
|
|
|
| PHP streams by Wez Furlong (wez@thebrainroom.com) |
|
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"
|
2001-05-19 07:38:46 +08:00
|
|
|
#include "ext/standard/basic_functions.h"
|
2002-09-07 23:45:29 +08:00
|
|
|
#include "php_ini.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
|
|
|
#define O_RDONLY _O_RDONLY
|
|
|
|
#include "win32/param.h"
|
|
|
|
#include "win32/winutil.h"
|
2002-09-05 22:25:07 +08:00
|
|
|
#elif defined(NETWARE) && !defined(NEW_LIBC)
|
|
|
|
/*#include <ws2nlm.h>*/
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include "netware/param.h"
|
1999-04-17 08:37:12 +08:00
|
|
|
#else
|
|
|
|
#include <sys/param.h>
|
2003-01-03 22:37:42 +08:00
|
|
|
#include <sys/select.h>
|
2002-09-05 22:25:07 +08:00
|
|
|
#if defined(NETWARE) && defined(USE_WINSOCK)
|
|
|
|
#include <novsock2.h>
|
|
|
|
#else
|
1999-04-17 08:37:12 +08:00
|
|
|
#include <sys/socket.h>
|
2000-08-20 05:15:43 +08:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netdb.h>
|
2002-09-05 22:25:07 +08:00
|
|
|
#endif
|
2001-01-22 01:29:15 +08:00
|
|
|
#if HAVE_ARPA_INET_H
|
2000-08-20 05:15:43 +08:00
|
|
|
#include <arpa/inet.h>
|
1999-04-17 08:37:12 +08:00
|
|
|
#endif
|
2001-01-22 01:29:15 +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"
|
2002-09-05 22:25:07 +08:00
|
|
|
#elif defined(NETWARE)
|
|
|
|
#include "netware/pwd.h"
|
1999-04-17 08:37:12 +08:00
|
|
|
#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"
|
2001-02-24 06:07:16 +08:00
|
|
|
#include "fopen_wrappers.h"
|
2002-03-16 05:03:08 +08:00
|
|
|
#include "php_streams.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
|
|
|
|
|
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
|
|
|
|
|
2002-03-22 03:18:13 +08:00
|
|
|
#ifdef HAVE_FNMATCH
|
2003-02-28 15:52:23 +08:00
|
|
|
#ifndef _GNU_SOURCE
|
|
|
|
#define _GNU_SOURCE
|
2002-03-22 03:18:13 +08:00
|
|
|
#include <fnmatch.h>
|
|
|
|
#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* */
|
2002-04-11 06:42:32 +08:00
|
|
|
static int le_stream_context = FAILURE;
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2003-02-28 06:23:39 +08:00
|
|
|
PHPAPI int php_le_stream_context(void)
|
|
|
|
{
|
|
|
|
return le_stream_context;
|
|
|
|
}
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
|
|
|
/* {{{ Module-Stuff */
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2002-04-11 06:42:32 +08:00
|
|
|
static ZEND_RSRC_DTOR_FUNC(file_context_dtor)
|
|
|
|
{
|
|
|
|
php_stream_context_free((php_stream_context*)rsrc->ptr);
|
|
|
|
}
|
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
static void file_globals_ctor(php_file_globals *file_globals_p TSRMLS_DC)
|
2001-01-13 21:59:22 +08:00
|
|
|
{
|
|
|
|
FG(pclose_ret) = 0;
|
2002-09-26 20:12:27 +08:00
|
|
|
FG(user_stream_current_filename) = NULL;
|
2002-03-20 01:49:02 +08:00
|
|
|
FG(def_chunk_size) = PHP_SOCK_CHUNK_SIZE;
|
2001-01-13 21:59:22 +08:00
|
|
|
}
|
2001-01-14 07:49:44 +08:00
|
|
|
|
2001-07-28 19:36:37 +08:00
|
|
|
static void file_globals_dtor(php_file_globals *file_globals_p TSRMLS_DC)
|
1999-10-15 23:22:25 +08:00
|
|
|
{
|
|
|
|
}
|
2001-01-14 07:49:44 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2002-09-07 23:45:29 +08:00
|
|
|
PHP_INI_BEGIN()
|
2002-09-24 02:12:39 +08:00
|
|
|
STD_PHP_INI_ENTRY("user_agent", NULL, PHP_INI_ALL, OnUpdateString, user_agent, php_file_globals, file_globals)
|
|
|
|
STD_PHP_INI_ENTRY("default_socket_timeout", "60", PHP_INI_ALL, OnUpdateInt, default_socket_timeout, php_file_globals, file_globals)
|
|
|
|
STD_PHP_INI_ENTRY("auto_detect_line_endings", "0", PHP_INI_ALL, OnUpdateInt, auto_detect_line_endings, php_file_globals, file_globals)
|
2002-09-07 23:45:29 +08:00
|
|
|
PHP_INI_END()
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
PHP_MINIT_FUNCTION(file)
|
|
|
|
{
|
2002-04-11 06:42:32 +08:00
|
|
|
le_stream_context = zend_register_list_destructors_ex(file_context_dtor, NULL, "stream-context", module_number);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
#ifdef ZTS
|
2001-07-27 18:16:41 +08:00
|
|
|
ts_allocate_id(&file_globals_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-07-28 19:36:37 +08:00
|
|
|
file_globals_ctor(&file_globals TSRMLS_CC);
|
1999-10-15 23:22:25 +08:00
|
|
|
#endif
|
|
|
|
|
2002-09-07 23:45:29 +08:00
|
|
|
REGISTER_INI_ENTRIES();
|
|
|
|
|
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
|
|
|
|
2002-04-11 06:42:32 +08:00
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_CONNECT", PHP_STREAM_NOTIFY_CONNECT, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_AUTH_REQUIRED", PHP_STREAM_NOTIFY_AUTH_REQUIRED, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_AUTH_RESULT", PHP_STREAM_NOTIFY_AUTH_RESULT, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_MIME_TYPE_IS", PHP_STREAM_NOTIFY_MIME_TYPE_IS, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_FILE_SIZE_IS", PHP_STREAM_NOTIFY_FILE_SIZE_IS, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_REDIRECTED", PHP_STREAM_NOTIFY_REDIRECTED, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_PROGRESS", PHP_STREAM_NOTIFY_PROGRESS, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_FAILURE", PHP_STREAM_NOTIFY_FAILURE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_INFO", PHP_STREAM_NOTIFY_SEVERITY_INFO, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_WARN", PHP_STREAM_NOTIFY_SEVERITY_WARN, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_NOTIFY_SEVERITY_ERR", PHP_STREAM_NOTIFY_SEVERITY_ERR, CONST_CS | CONST_PERSISTENT);
|
2003-02-11 06:26:53 +08:00
|
|
|
|
2003-02-18 10:53:24 +08:00
|
|
|
REGISTER_LONG_CONSTANT("STREAM_FILTER_READ", PHP_STREAM_FILTER_READ, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_FILTER_WRITE", PHP_STREAM_FILTER_WRITE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("STREAM_FILTER_ALL", PHP_STREAM_FILTER_ALL, CONST_CS | CONST_PERSISTENT);
|
|
|
|
|
2003-02-11 06:26:53 +08:00
|
|
|
REGISTER_LONG_CONSTANT("FILE_USE_INCLUDE_PATH", PHP_FILE_USE_INCLUDE_PATH, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("FILE_IGNORE_NEW_LINES", PHP_FILE_IGNORE_NEW_LINES, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("FILE_SKIP_EMPTY_LINES", PHP_FILE_SKIP_EMPTY_LINES, CONST_CS | CONST_PERSISTENT);
|
2002-04-11 06:42:32 +08:00
|
|
|
|
2002-09-26 08:27:13 +08:00
|
|
|
#ifdef HAVE_FNMATCH
|
|
|
|
REGISTER_LONG_CONSTANT("FNM_NOESCAPE", FNM_NOESCAPE, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("FNM_PATHNAME", FNM_PATHNAME, CONST_CS | CONST_PERSISTENT);
|
|
|
|
REGISTER_LONG_CONSTANT("FNM_PERIOD", FNM_PERIOD, CONST_CS | CONST_PERSISTENT);
|
|
|
|
#ifdef FNM_CASEFOLD /* a GNU extension */ /* TODO emulate if not available */
|
|
|
|
REGISTER_LONG_CONSTANT("FNM_CASEFOLD", FNM_CASEFOLD, CONST_CS | CONST_PERSISTENT);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* }}} */
|
2001-01-14 07:49:44 +08:00
|
|
|
|
|
|
|
PHP_MSHUTDOWN_FUNCTION(file)
|
|
|
|
{
|
|
|
|
#ifndef ZTS
|
2001-07-28 19:36:37 +08:00
|
|
|
file_globals_dtor(&file_globals TSRMLS_CC);
|
2001-01-14 07:49:44 +08:00
|
|
|
#endif
|
|
|
|
return SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-06-10 18:28:33 +08:00
|
|
|
/* {{{ proto bool flock(resource 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)
|
|
|
|
{
|
2003-02-25 09:39:06 +08:00
|
|
|
zval *arg1, *arg3 = NULL;
|
|
|
|
int fd, act;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2003-01-04 02:33:28 +08:00
|
|
|
long operation = 0;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2003-01-04 02:33:28 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|z", &arg1, &operation, &arg3) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2003-01-04 02:33:28 +08:00
|
|
|
php_stream_from_zval(stream, &arg1);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2003-01-04 02:33:28 +08:00
|
|
|
if (php_stream_cast(stream, PHP_STREAM_AS_FD, (void*)&fd, 1) == FAILURE) {
|
2002-03-16 05:03:08 +08:00
|
|
|
RETURN_FALSE;
|
1999-10-14 03:55:25 +08:00
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2003-01-04 02:33:28 +08:00
|
|
|
act = operation & 3;
|
|
|
|
if (act < 1 || act > 3) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Illegal operation argument");
|
1999-10-14 03:55:25 +08:00
|
|
|
RETURN_FALSE;
|
2000-06-06 01:56:01 +08:00
|
|
|
}
|
2003-01-04 02:33:28 +08:00
|
|
|
|
|
|
|
/* flock_values contains all possible actions if (operation & 4) we won't block on the lock */
|
|
|
|
act = flock_values[act - 1] | (operation & 4 ? LOCK_NB : 0);
|
2003-02-25 09:39:06 +08:00
|
|
|
if (!php_stream_lock(stream, act)) {
|
|
|
|
if (operation && errno == EWOULDBLOCK && arg3 && PZVAL_IS_REF(arg3)) {
|
|
|
|
convert_to_long_ex(&arg3);
|
|
|
|
ZVAL_LONG(arg3, 1);
|
2003-01-04 02:33:28 +08:00
|
|
|
}
|
2003-02-25 09:39:06 +08:00
|
|
|
RETURN_TRUE;
|
2003-01-04 02:33:28 +08:00
|
|
|
}
|
2003-02-25 09:39:06 +08:00
|
|
|
RETURN_FALSE;
|
1999-06-16 05:51:00 +08:00
|
|
|
}
|
1999-10-13 02:50:05 +08:00
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
/* }}} */
|
2001-03-06 12:34:05 +08:00
|
|
|
|
|
|
|
#define PHP_META_UNSAFE ".\\+*?[^]$() "
|
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto array get_meta_tags(string filename [, bool 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)
|
|
|
|
{
|
2001-12-21 09:53:25 +08:00
|
|
|
char *filename;
|
|
|
|
int filename_len;
|
|
|
|
zend_bool use_include_path = 0;
|
|
|
|
int in_tag = 0, done = 0;
|
|
|
|
int looking_for_val = 0, have_name = 0, have_content = 0;
|
|
|
|
int saw_name = 0, saw_content = 0;
|
|
|
|
char *name = NULL, *value = NULL, *temp = NULL;
|
2001-02-11 10:38:40 +08:00
|
|
|
php_meta_tags_token tok, tok_last;
|
2001-12-21 11:50:07 +08:00
|
|
|
php_meta_tags_data md;
|
|
|
|
|
|
|
|
/* Initiailize our structure */
|
|
|
|
memset(&md, 0, sizeof(md));
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-12-21 09:53:25 +08:00
|
|
|
/* Parse arguments */
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b",
|
|
|
|
&filename, &filename_len, &use_include_path) == FAILURE) {
|
|
|
|
return;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
md.stream = php_stream_open_wrapper(filename, "rb",
|
2002-08-25 20:09:57 +08:00
|
|
|
(use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS,
|
2002-03-18 16:05:28 +08:00
|
|
|
NULL);
|
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
if (!md.stream) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
array_init(return_value);
|
1999-12-12 03:51:04 +08:00
|
|
|
|
2001-02-11 10:38:40 +08:00
|
|
|
tok_last = TOK_EOF;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2002-03-19 02:54:32 +08:00
|
|
|
while (!done && (tok = php_next_meta_token(&md TSRMLS_CC)) != TOK_EOF) {
|
2001-02-11 10:38:40 +08:00
|
|
|
if (tok == TOK_ID) {
|
|
|
|
if (tok_last == TOK_OPENTAG) {
|
2001-12-21 09:53:25 +08:00
|
|
|
md.in_meta = !strcasecmp("meta", md.token_data);
|
2001-02-11 10:38:40 +08:00
|
|
|
} else if (tok_last == TOK_SLASH && in_tag) {
|
2001-07-01 04:07:12 +08:00
|
|
|
if (strcasecmp("head", md.token_data) == 0) {
|
2001-02-11 10:38:40 +08:00
|
|
|
/* We are done here! */
|
|
|
|
done = 1;
|
|
|
|
}
|
2001-03-06 12:34:05 +08:00
|
|
|
} else if (tok_last == TOK_EQUAL && looking_for_val) {
|
2001-07-01 04:07:12 +08:00
|
|
|
if (saw_name) {
|
|
|
|
/* Get the NAME attr (Single word attr, non-quoted) */
|
2001-08-12 01:03:37 +08:00
|
|
|
temp = name = estrndup(md.token_data, md.token_len);
|
2001-03-06 12:34:05 +08:00
|
|
|
|
|
|
|
while (temp && *temp) {
|
|
|
|
if (strchr(PHP_META_UNSAFE, *temp)) {
|
|
|
|
*temp = '_';
|
|
|
|
}
|
|
|
|
temp++;
|
|
|
|
}
|
2001-07-01 04:07:12 +08:00
|
|
|
|
|
|
|
have_name = 1;
|
|
|
|
} else if (saw_content) {
|
|
|
|
/* Get the CONTENT attr (Single word attr, non-quoted) */
|
2001-03-06 12:34:05 +08:00
|
|
|
if (PG(magic_quotes_runtime)) {
|
2001-08-12 01:03:37 +08:00
|
|
|
value = php_addslashes(md.token_data, 0, &md.token_len, 0 TSRMLS_CC);
|
2001-03-06 12:34:05 +08:00
|
|
|
} else {
|
2001-08-12 01:03:37 +08:00
|
|
|
value = estrndup(md.token_data, md.token_len);
|
2001-03-06 12:34:05 +08:00
|
|
|
}
|
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
have_content = 1;
|
2001-03-06 12:34:05 +08:00
|
|
|
}
|
2001-07-01 04:07:12 +08:00
|
|
|
|
2001-03-06 12:34:05 +08:00
|
|
|
looking_for_val = 0;
|
2001-02-11 10:38:40 +08:00
|
|
|
} else {
|
2001-12-21 09:53:25 +08:00
|
|
|
if (md.in_meta) {
|
2001-07-01 04:07:12 +08:00
|
|
|
if (strcasecmp("name", md.token_data) == 0) {
|
|
|
|
saw_name = 1;
|
|
|
|
saw_content = 0;
|
|
|
|
looking_for_val = 1;
|
|
|
|
} else if (strcasecmp("content", md.token_data) == 0) {
|
|
|
|
saw_name = 0;
|
|
|
|
saw_content = 1;
|
2001-02-11 10:38:40 +08:00
|
|
|
looking_for_val = 1;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-11 10:38:40 +08:00
|
|
|
} else if (tok == TOK_STRING && tok_last == TOK_EQUAL && looking_for_val) {
|
2001-07-01 04:07:12 +08:00
|
|
|
if (saw_name) {
|
|
|
|
/* Get the NAME attr (Quoted single/double) */
|
2001-08-12 01:03:37 +08:00
|
|
|
temp = name = estrndup(md.token_data, md.token_len);
|
2001-07-01 04:07:12 +08:00
|
|
|
|
2001-02-11 10:38:40 +08:00
|
|
|
while (temp && *temp) {
|
2001-03-06 12:34:05 +08:00
|
|
|
if (strchr(PHP_META_UNSAFE, *temp)) {
|
2001-02-11 10:38:40 +08:00
|
|
|
*temp = '_';
|
|
|
|
}
|
|
|
|
temp++;
|
|
|
|
}
|
2001-07-01 04:07:12 +08:00
|
|
|
|
|
|
|
have_name = 1;
|
|
|
|
} else if (saw_content) {
|
|
|
|
/* Get the CONTENT attr (Single word attr, non-quoted) */
|
1999-04-17 08:37:12 +08:00
|
|
|
if (PG(magic_quotes_runtime)) {
|
2001-08-12 01:03:37 +08:00
|
|
|
value = php_addslashes(md.token_data, 0, &md.token_len, 0 TSRMLS_CC);
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
2001-08-12 01:03:37 +08:00
|
|
|
value = estrndup(md.token_data, md.token_len);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-02-11 10:38:40 +08:00
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
have_content = 1;
|
2001-02-11 10:38:40 +08:00
|
|
|
}
|
2001-07-01 04:07:12 +08:00
|
|
|
|
2001-02-11 10:38:40 +08:00
|
|
|
looking_for_val = 0;
|
|
|
|
} else if (tok == TOK_OPENTAG) {
|
|
|
|
if (looking_for_val) {
|
|
|
|
looking_for_val = 0;
|
2001-07-01 04:07:12 +08:00
|
|
|
have_name = saw_name = 0;
|
|
|
|
have_content = saw_content = 0;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-02-11 10:38:40 +08:00
|
|
|
in_tag = 1;
|
|
|
|
} else if (tok == TOK_CLOSETAG) {
|
2001-07-01 04:07:12 +08:00
|
|
|
if (have_name) {
|
2001-07-06 07:29:11 +08:00
|
|
|
/* For BC */
|
|
|
|
php_strtolower(name, strlen(name));
|
2001-07-01 04:07:12 +08:00
|
|
|
if (have_content) {
|
|
|
|
add_assoc_string(return_value, name, value, 0);
|
|
|
|
} else {
|
|
|
|
add_assoc_string(return_value, name, empty_string, 0);
|
|
|
|
}
|
|
|
|
|
2001-02-11 10:38:40 +08:00
|
|
|
efree(name);
|
2001-07-01 04:07:12 +08:00
|
|
|
} else if (have_content) {
|
|
|
|
efree(value);
|
2001-02-11 10:38:40 +08:00
|
|
|
}
|
2001-07-01 04:07:12 +08:00
|
|
|
|
|
|
|
name = value = NULL;
|
|
|
|
|
2001-02-11 10:38:40 +08:00
|
|
|
/* Reset all of our flags */
|
2001-12-21 09:53:25 +08:00
|
|
|
in_tag = looking_for_val = 0;
|
2001-07-01 04:07:12 +08:00
|
|
|
have_name = saw_name = 0;
|
|
|
|
have_content = saw_content = 0;
|
2001-08-04 20:36:51 +08:00
|
|
|
md.in_meta = 0;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-02-11 10:38:40 +08:00
|
|
|
|
|
|
|
tok_last = tok;
|
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
if (md.token_data)
|
|
|
|
efree(md.token_data);
|
2001-02-11 10:38:40 +08:00
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
md.token_data = NULL;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-02-11 10:38:40 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_close(md.stream);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-06-16 05:51:00 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2002-03-17 00:06:18 +08:00
|
|
|
|
2002-03-17 00:52:24 +08:00
|
|
|
/* {{{ proto string file_get_contents(string filename [, bool use_include_path])
|
2002-03-17 00:06:18 +08:00
|
|
|
Read the entire file into a string */
|
2002-03-17 00:52:24 +08:00
|
|
|
PHP_FUNCTION(file_get_contents)
|
2002-03-17 00:06:18 +08:00
|
|
|
{
|
|
|
|
char *filename;
|
|
|
|
int filename_len;
|
2002-03-17 00:14:56 +08:00
|
|
|
char *contents;
|
2002-03-17 00:06:18 +08:00
|
|
|
zend_bool use_include_path = 0;
|
|
|
|
php_stream *stream;
|
|
|
|
int len, newlen;
|
|
|
|
|
|
|
|
/* Parse arguments */
|
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b",
|
|
|
|
&filename, &filename_len, &use_include_path) == FAILURE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
stream = php_stream_open_wrapper(filename, "rb",
|
2002-08-25 20:09:57 +08:00
|
|
|
(use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS,
|
2002-03-18 16:05:28 +08:00
|
|
|
NULL);
|
2002-03-17 00:06:18 +08:00
|
|
|
if (!stream) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* uses mmap if possible */
|
2002-10-16 00:45:26 +08:00
|
|
|
if ((len = php_stream_copy_to_mem(stream, &contents, PHP_STREAM_COPY_ALL, 0)) >= 0) {
|
2002-03-17 00:06:18 +08:00
|
|
|
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
|
|
|
contents = php_addslashes(contents, len, &newlen, 1 TSRMLS_CC); /* 1 = free source string */
|
|
|
|
len = newlen;
|
|
|
|
}
|
|
|
|
|
2002-03-17 00:14:56 +08:00
|
|
|
RETVAL_STRINGL(contents, len, 0);
|
2002-03-17 00:06:18 +08:00
|
|
|
} else {
|
|
|
|
RETVAL_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
php_stream_close(stream);
|
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2003-02-11 06:26:53 +08:00
|
|
|
/* {{{ proto array file(string filename [, int flags])
|
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)
|
|
|
|
{
|
2001-12-21 09:53:25 +08:00
|
|
|
char *filename;
|
|
|
|
int filename_len;
|
2002-10-23 02:07:11 +08:00
|
|
|
char *slashed, *target_buf=NULL, *p, *s, *e;
|
2001-12-21 09:53:25 +08:00
|
|
|
register int i = 0;
|
2002-10-19 04:39:49 +08:00
|
|
|
int target_len, len;
|
2002-09-24 10:46:38 +08:00
|
|
|
char eol_marker = '\n';
|
2003-02-11 06:26:53 +08:00
|
|
|
long flags = 0;
|
|
|
|
zend_bool use_include_path;
|
|
|
|
zend_bool include_new_line;
|
|
|
|
zend_bool skip_blank_lines;
|
2002-03-16 09:34:52 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-10-19 04:39:49 +08:00
|
|
|
/* Parse arguments */
|
2003-02-11 06:26:53 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &filename, &filename_len, &flags) == FAILURE) {
|
2001-12-21 09:53:25 +08:00
|
|
|
return;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2003-02-11 06:26:53 +08:00
|
|
|
if (flags < 0 || flags > (PHP_FILE_USE_INCLUDE_PATH | PHP_FILE_IGNORE_NEW_LINES | PHP_FILE_SKIP_EMPTY_LINES)) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "'%l' flag is not supported.", flags);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
use_include_path = flags & PHP_FILE_USE_INCLUDE_PATH;
|
|
|
|
include_new_line = !(flags & PHP_FILE_IGNORE_NEW_LINES);
|
|
|
|
skip_blank_lines = flags & PHP_FILE_SKIP_EMPTY_LINES;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2003-02-11 06:26:53 +08:00
|
|
|
stream = php_stream_open_wrapper(filename, "rb", (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL);
|
2002-03-17 00:06:18 +08:00
|
|
|
if (!stream) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize return array */
|
2001-08-17 17:08:03 +08:00
|
|
|
array_init(return_value);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-10-19 04:39:49 +08:00
|
|
|
if ((target_len = php_stream_copy_to_mem(stream, &target_buf, PHP_STREAM_COPY_ALL, 0))) {
|
|
|
|
s = target_buf;
|
|
|
|
e = target_buf + target_len;
|
|
|
|
|
|
|
|
if (!(p = php_stream_locate_eol(stream, target_buf, target_len TSRMLS_CC))) {
|
|
|
|
p = e;
|
|
|
|
goto parse_eol;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (stream->flags & PHP_STREAM_FLAG_EOL_MAC) {
|
|
|
|
eol_marker = '\r';
|
|
|
|
}
|
2003-02-10 04:05:13 +08:00
|
|
|
|
|
|
|
/* for performance reasons the code is duplicated, so that the if (include_new_line)
|
|
|
|
* will not need to be done for every single line in the file.
|
|
|
|
*/
|
|
|
|
if (include_new_line) {
|
|
|
|
do {
|
|
|
|
p++;
|
|
|
|
parse_eol:
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
|
|
|
/* s is in target_buf which is freed at the end of the function */
|
|
|
|
slashed = php_addslashes(s, (p-s), &len, 0 TSRMLS_CC);
|
|
|
|
add_index_stringl(return_value, i++, slashed, len, 0);
|
|
|
|
} else {
|
|
|
|
add_index_stringl(return_value, i++, estrndup(s, p-s), p-s, 0);
|
|
|
|
}
|
|
|
|
s = p;
|
|
|
|
} while ((p = memchr(p, eol_marker, (e-p))));
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
if (skip_blank_lines && !(p-s)) {
|
|
|
|
s = ++p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (PG(magic_quotes_runtime)) {
|
|
|
|
/* s is in target_buf which is freed at the end of the function */
|
|
|
|
slashed = php_addslashes(s, (p-s), &len, 0 TSRMLS_CC);
|
|
|
|
add_index_stringl(return_value, i++, slashed, len, 0);
|
|
|
|
} else {
|
|
|
|
add_index_stringl(return_value, i++, estrndup(s, p-s), p-s, 0);
|
|
|
|
}
|
|
|
|
s = ++p;
|
|
|
|
} while ((p = memchr(p, eol_marker, (e-p))));
|
|
|
|
}
|
2002-10-19 04:39:49 +08:00
|
|
|
|
|
|
|
/* handle any left overs of files without new lines */
|
|
|
|
if (s != e) {
|
|
|
|
p = e;
|
|
|
|
goto parse_eol;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-10-23 02:07:11 +08:00
|
|
|
if (target_buf) {
|
|
|
|
efree(target_buf);
|
|
|
|
}
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_close(stream);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +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;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 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);
|
2002-07-02 14:16:35 +08:00
|
|
|
|
|
|
|
if (php_check_open_basedir(Z_STRVAL_PP(arg1) TSRMLS_CC)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2001-08-05 09:43:02 +08:00
|
|
|
if ((fp = php_open_temporary_file(d, p, &opened_path TSRMLS_CC))) {
|
2000-09-09 19:41:14 +08:00
|
|
|
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-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto resource tmpfile(void)
|
2000-02-24 16:07:29 +08:00
|
|
|
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
|
|
|
{
|
2002-03-16 09:34:52 +08:00
|
|
|
php_stream *stream;
|
2002-03-16 05:03:08 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 0) {
|
1999-11-14 19:05:37 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
stream = php_stream_fopen_tmpfile();
|
|
|
|
|
|
|
|
if (stream) {
|
2002-03-20 22:21:30 +08:00
|
|
|
php_stream_to_zval(stream, return_value);
|
2002-03-16 05:03:08 +08:00
|
|
|
}
|
|
|
|
else {
|
1999-11-14 19:05:37 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-04-11 06:42:32 +08:00
|
|
|
/* {{{ proto resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
|
|
|
|
Open a file or a URL and return a file pointer */
|
|
|
|
PHP_NAMED_FUNCTION(php_if_fopen)
|
|
|
|
{
|
|
|
|
char *filename, *mode;
|
|
|
|
int filename_len, mode_len;
|
|
|
|
zend_bool use_include_path = 0;
|
|
|
|
zval *zcontext = NULL;
|
|
|
|
php_stream *stream;
|
|
|
|
php_stream_context *context = NULL;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2002-04-11 06:42:32 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ss|br", &filename, &filename_len,
|
|
|
|
&mode, &mode_len, &use_include_path, &zcontext) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
if (zcontext) {
|
2002-09-08 04:58:30 +08:00
|
|
|
ZEND_FETCH_RESOURCE(context, php_stream_context*, &zcontext, -1, "stream-context", le_stream_context);
|
2002-04-11 06:42:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stream = php_stream_open_wrapper_ex(filename, mode,
|
2002-08-25 20:09:57 +08:00
|
|
|
(use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS,
|
2002-04-11 06:42:32 +08:00
|
|
|
NULL, context);
|
|
|
|
|
2003-01-10 07:23:32 +08:00
|
|
|
if (stream == NULL) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-03-20 22:21:30 +08:00
|
|
|
|
|
|
|
php_stream_to_zval(stream, return_value);
|
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
return;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto bool fclose(resource fp)
|
2000-02-24 16:07:29 +08:00
|
|
|
Close an open file pointer */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(fclose)
|
1999-06-16 05:51:00 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 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
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
|
|
|
php_stream_close(stream);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
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
|
|
|
/* }}} */
|
2002-04-11 06:42:32 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto resource 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)
|
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1, **arg2;
|
1999-04-17 08:37:12 +08:00
|
|
|
FILE *fp;
|
2001-08-12 01:03:37 +08:00
|
|
|
char *p, *tmp = NULL;
|
1999-04-17 08:37:12 +08:00
|
|
|
char *b, buf[1024];
|
2002-03-16 09:34:52 +08:00
|
|
|
php_stream *stream;
|
2002-03-16 05:03:08 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 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);
|
2001-08-17 17:08:03 +08:00
|
|
|
p = estrndup(Z_STRVAL_PP(arg2), Z_STRLEN_PP(arg2));
|
1999-04-17 08:37:12 +08:00
|
|
|
if (PG(safe_mode)){
|
2001-08-17 17:08:03 +08:00
|
|
|
b = strchr(Z_STRVAL_PP(arg1), ' ');
|
1999-06-16 05:51:00 +08:00
|
|
|
if (!b) {
|
2001-08-17 17:08:03 +08:00
|
|
|
b = strrchr(Z_STRVAL_PP(arg1), '/');
|
1999-06-16 05:51:00 +08:00
|
|
|
} else {
|
|
|
|
char *c;
|
2001-08-17 17:08:03 +08:00
|
|
|
c = Z_STRVAL_PP(arg1);
|
|
|
|
while((*b != '/') && (b != c)) {
|
1999-06-16 05:51:00 +08:00
|
|
|
b--;
|
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
if (b == c) {
|
|
|
|
b = NULL;
|
1999-06-16 05:51:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (b) {
|
2001-08-12 01:03:37 +08:00
|
|
|
snprintf(buf, sizeof(buf), "%s%s", PG(safe_mode_exec_dir), b);
|
1999-06-16 05:51:00 +08:00
|
|
|
} else {
|
2001-08-17 17:08:03 +08:00
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", PG(safe_mode_exec_dir), Z_STRVAL_PP(arg1));
|
1999-06-16 05:51:00 +08:00
|
|
|
}
|
2000-01-06 23:27:03 +08:00
|
|
|
|
|
|
|
tmp = php_escape_shell_cmd(buf);
|
2001-08-12 01:03:37 +08:00
|
|
|
fp = VCWD_POPEN(tmp, p);
|
2000-01-06 23:27:03 +08:00
|
|
|
efree(tmp);
|
|
|
|
|
1999-06-16 05:51:00 +08:00
|
|
|
if (!fp) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref2(NULL TSRMLS_CC, buf, p, E_WARNING, "%s", strerror(errno));
|
1999-06-16 05:51:00 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-06-16 01:06:22 +08:00
|
|
|
} else {
|
2001-08-17 17:08:03 +08:00
|
|
|
fp = VCWD_POPEN(Z_STRVAL_PP(arg1), p);
|
1999-06-16 05:51:00 +08:00
|
|
|
if (!fp) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(arg1), p, E_WARNING, "%s", strerror(errno));
|
1999-06-16 05:51:00 +08:00
|
|
|
efree(p);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-06-16 01:06:22 +08:00
|
|
|
}
|
2002-03-16 05:03:08 +08:00
|
|
|
stream = php_stream_fopen_from_pipe(fp, p);
|
|
|
|
|
|
|
|
if (stream == NULL) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(arg1), p, E_WARNING, "%s", strerror(errno));
|
2002-03-16 05:03:08 +08:00
|
|
|
RETVAL_FALSE;
|
2002-03-20 22:21:30 +08:00
|
|
|
} else {
|
|
|
|
php_stream_to_zval(stream, return_value);
|
2002-03-16 05:03:08 +08:00
|
|
|
}
|
1999-10-14 03:55:25 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
efree(p);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto int pclose(resource 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)
|
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2002-03-16 05:03:08 +08:00
|
|
|
|
2003-01-21 22:56:40 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
RETURN_LONG(php_stream_close(stream));
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto bool feof(resource fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Test for end-of-file on a file pointer */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(feof)
|
1999-06-16 05:51:00 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 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
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
|
|
|
|
|
|
|
if (php_stream_eof(stream)) {
|
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2001-12-05 03:40:48 +08:00
|
|
|
/* {{{ proto string fgets(resource fp[, int length])
|
1999-10-15 23:22:25 +08:00
|
|
|
Get a line from file pointer */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(fgets)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1, **arg2;
|
2002-10-25 03:17:08 +08:00
|
|
|
int len = 1024;
|
2002-10-14 10:28:35 +08:00
|
|
|
char *buf = NULL;
|
2001-12-05 03:40:48 +08:00
|
|
|
int argc = ZEND_NUM_ARGS();
|
2002-10-19 21:11:48 +08:00
|
|
|
size_t line_len = 0;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-12-05 03:40:48 +08:00
|
|
|
if (argc<1 || argc>2 || zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2002-10-14 10:28:35 +08:00
|
|
|
if (argc == 1) {
|
|
|
|
/* ask streams to give us a buffer of an appropriate size */
|
2002-10-19 21:11:48 +08:00
|
|
|
buf = php_stream_get_line(stream, NULL, 0, &line_len);
|
2002-10-14 10:28:35 +08:00
|
|
|
if (buf == NULL)
|
|
|
|
goto exit_failed;
|
|
|
|
} else if (argc > 1) {
|
2001-12-05 03:40:48 +08:00
|
|
|
convert_to_long_ex(arg2);
|
|
|
|
len = Z_LVAL_PP(arg2);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2002-10-14 10:28:35 +08:00
|
|
|
if (len < 0) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-10-14 10:28:35 +08:00
|
|
|
buf = ecalloc(len + 1, sizeof(char));
|
2002-10-19 21:11:48 +08:00
|
|
|
if (php_stream_get_line(stream, buf, len, &line_len) == NULL)
|
2002-10-14 10:28:35 +08:00
|
|
|
goto exit_failed;
|
|
|
|
}
|
|
|
|
|
2001-04-18 01:06:06 +08:00
|
|
|
if (PG(magic_quotes_runtime)) {
|
2002-10-19 21:11:48 +08:00
|
|
|
Z_STRVAL_P(return_value) = php_addslashes(buf, line_len, &Z_STRLEN_P(return_value), 1 TSRMLS_CC);
|
2001-08-17 17:08:03 +08:00
|
|
|
Z_TYPE_P(return_value) = IS_STRING;
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
2002-10-19 21:11:48 +08:00
|
|
|
ZVAL_STRINGL(return_value, buf, line_len, 0);
|
2002-10-14 10:28:35 +08:00
|
|
|
/* resize buffer if it's much larger than the result.
|
|
|
|
* Only needed if the user requested a buffer size. */
|
2003-01-12 07:05:19 +08:00
|
|
|
if (argc > 1 && Z_STRLEN_P(return_value) < len / 2) {
|
2002-10-19 21:11:48 +08:00
|
|
|
Z_STRVAL_P(return_value) = erealloc(buf, line_len + 1);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
return;
|
|
|
|
|
|
|
|
exit_failed:
|
|
|
|
RETVAL_FALSE;
|
2002-10-14 10:28:35 +08:00
|
|
|
if (buf)
|
|
|
|
efree(buf);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto string fgetc(resource fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Get a character from file pointer */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(fgetc)
|
2001-08-05 09:43:02 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1;
|
1999-04-17 08:37:12 +08:00
|
|
|
char *buf;
|
2000-09-28 00:08:26 +08:00
|
|
|
int result;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
buf = emalloc(2 * sizeof(char));
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
result = php_stream_getc(stream);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
|
|
|
if (result == EOF) {
|
1999-04-17 08:37:12 +08:00
|
|
|
efree(buf);
|
|
|
|
RETVAL_FALSE;
|
|
|
|
} else {
|
2001-08-17 17:08:03 +08:00
|
|
|
buf[0] = result;
|
|
|
|
buf[1] = '\0';
|
|
|
|
|
|
|
|
RETURN_STRINGL(buf, 1, 0);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2000-06-07 02:58:15 +08:00
|
|
|
|
2003-02-26 04:12:18 +08:00
|
|
|
/* {{{ proto string fgetss(resource fp [, int length, string allowable_tags])
|
1999-10-15 23:22:25 +08:00
|
|
|
Get a line from file pointer and strip HTML tags */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(fgetss)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2003-02-26 04:12:18 +08:00
|
|
|
zval **fd, **bytes = NULL, **allow=NULL;
|
|
|
|
size_t len = 0;
|
2003-02-25 06:39:47 +08:00
|
|
|
size_t actual_len, retval_len;
|
2003-02-26 04:12:18 +08:00
|
|
|
char *buf = NULL, *retval;
|
2002-03-20 22:38:13 +08:00
|
|
|
php_stream *stream;
|
2000-02-09 05:29:18 +08:00
|
|
|
char *allowed_tags=NULL;
|
|
|
|
int allowed_tags_len=0;
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
switch(ZEND_NUM_ARGS()) {
|
2003-02-26 04:12:18 +08:00
|
|
|
case 1:
|
|
|
|
if (zend_get_parameters_ex(1, &fd) == FAILURE) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
break;
|
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);
|
2001-08-17 17:08:03 +08:00
|
|
|
allowed_tags = Z_STRVAL_PP(allow);
|
|
|
|
allowed_tags_len = Z_STRLEN_PP(allow);
|
1999-10-15 23:22:25 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, fd);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2003-02-26 04:12:18 +08:00
|
|
|
if (bytes != NULL) {
|
|
|
|
convert_to_long_ex(bytes);
|
|
|
|
if (Z_LVAL_PP(bytes) < 0) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative");
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2003-02-26 04:12:18 +08:00
|
|
|
len = (size_t) Z_LVAL_PP(bytes);
|
|
|
|
buf = emalloc(sizeof(char) * (len + 1));
|
|
|
|
/*needed because recv doesnt set null char at end*/
|
|
|
|
memset(buf, 0, len + 1);
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2003-02-26 04:12:18 +08:00
|
|
|
if ((retval = php_stream_get_line(stream, buf, len, &actual_len)) == NULL) {
|
|
|
|
if (buf != NULL) {
|
|
|
|
efree(buf);
|
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2003-02-26 04:12:18 +08:00
|
|
|
retval_len = php_strip_tags(retval, actual_len, &stream->fgetss_state, allowed_tags, allowed_tags_len);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2003-02-26 04:12:18 +08:00
|
|
|
RETURN_STRINGL(retval, retval_len, 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
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2002-09-25 23:46:47 +08:00
|
|
|
/* {{{ proto mixed fscanf(resource stream, string format [, string ...])
|
2000-06-27 01:57:46 +08:00
|
|
|
Implements a mostly ANSI compatible fscanf() */
|
2000-06-07 02:58:15 +08:00
|
|
|
PHP_FUNCTION(fscanf)
|
|
|
|
{
|
2001-04-18 01:06:06 +08:00
|
|
|
int result;
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **file_handle, **format_string;
|
2003-01-18 22:10:22 +08:00
|
|
|
size_t len;
|
|
|
|
int type;
|
2001-04-18 01:06:06 +08:00
|
|
|
char *buf;
|
|
|
|
void *what;
|
2000-06-07 02:58:15 +08:00
|
|
|
|
2001-04-18 01:06:06 +08:00
|
|
|
zval ***args;
|
|
|
|
int argCount;
|
2000-06-07 02:58:15 +08:00
|
|
|
|
2001-04-18 01:06:06 +08:00
|
|
|
argCount = ZEND_NUM_ARGS();
|
|
|
|
if (argCount < 2) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
args = (zval ***)emalloc(argCount * sizeof(zval **));
|
2003-01-19 04:01:46 +08:00
|
|
|
if (zend_get_parameters_array_ex(argCount, args) == FAILURE) {
|
2001-04-18 01:06:06 +08:00
|
|
|
efree( args );
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
file_handle = args[0];
|
|
|
|
format_string = args[1];
|
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
what = zend_fetch_resource(file_handle TSRMLS_CC, -1, "File-Handle", &type, 2,
|
|
|
|
php_file_le_stream(), php_file_le_pstream());
|
2001-04-18 01:06:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-11-28 04:05:20 +08:00
|
|
|
buf = php_stream_get_line((php_stream *) what, NULL, 0, &len);
|
|
|
|
if (buf == NULL) {
|
2003-01-18 21:55:58 +08:00
|
|
|
efree(args);
|
2001-04-18 01:06:06 +08:00
|
|
|
RETURN_FALSE;
|
2002-03-16 05:03:08 +08:00
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
convert_to_string_ex(format_string);
|
|
|
|
result = php_sscanf_internal(buf, Z_STRVAL_PP(format_string),
|
2001-07-30 16:24:42 +08:00
|
|
|
argCount, args, 2, &return_value TSRMLS_CC);
|
2002-11-28 04:05:20 +08:00
|
|
|
|
2001-04-18 01:06:06 +08:00
|
|
|
efree(args);
|
|
|
|
efree(buf);
|
2002-11-28 04:05:20 +08:00
|
|
|
|
2001-04-18 01:06:06 +08:00
|
|
|
if (SCAN_ERROR_WRONG_PARAM_COUNT == result) {
|
2002-11-28 04:05:20 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
2001-04-18 01:06:06 +08:00
|
|
|
}
|
2000-06-07 02:58:15 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto int fwrite(resource fp, string str [, int length])
|
1999-10-15 23:22:25 +08:00
|
|
|
Binary-safe file write */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(fwrite)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1, **arg2, **arg3=NULL;
|
2002-09-25 23:25:12 +08:00
|
|
|
int ret;
|
1999-04-17 08:37:12 +08:00
|
|
|
int num_bytes;
|
2002-08-27 07:18:59 +08:00
|
|
|
char *buffer = NULL;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
switch (ZEND_NUM_ARGS()) {
|
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);
|
2001-08-17 17:08:03 +08:00
|
|
|
num_bytes = Z_STRLEN_PP(arg2);
|
1999-10-15 23:22:25 +08:00
|
|
|
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);
|
2003-01-12 07:05:19 +08:00
|
|
|
num_bytes = MIN(Z_LVAL_PP(arg3), Z_STRLEN_PP(arg2));
|
1999-10-15 23:22:25 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
2001-04-18 01:06:06 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
if (!arg3 && PG(magic_quotes_runtime)) {
|
2002-08-27 07:18:59 +08:00
|
|
|
buffer = estrndup(Z_STRVAL_PP(arg2), Z_STRLEN_PP(arg2));
|
|
|
|
php_stripslashes(buffer, &num_bytes TSRMLS_CC);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
ret = php_stream_write(stream, buffer ? buffer : Z_STRVAL_PP(arg2), num_bytes);
|
2002-08-27 07:18:59 +08:00
|
|
|
if (buffer) {
|
|
|
|
efree(buffer);
|
|
|
|
}
|
2002-03-16 05:03:08 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_LONG(ret);
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto bool fflush(resource fp)
|
2000-06-27 01:57:46 +08:00
|
|
|
Flushes output */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(fflush)
|
2000-06-06 20:16:44 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1;
|
2002-09-25 23:25:12 +08:00
|
|
|
int ret;
|
|
|
|
php_stream *stream;
|
2000-06-06 20:16:44 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
2000-06-06 20:16:44 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
2000-06-06 20:16:44 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
ret = php_stream_flush(stream);
|
2000-06-06 20:16:44 +08:00
|
|
|
if (ret) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2002-03-16 05:03:08 +08:00
|
|
|
RETURN_TRUE;
|
2000-06-06 20:16:44 +08:00
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto bool rewind(resource fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Rewind the position of a file pointer */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(rewind)
|
1999-06-16 05:51:00 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
if (-1 == php_stream_rewind(stream)) {
|
2002-03-16 05:03:08 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto int ftell(resource fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Get file pointer's read/write position */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(ftell)
|
1999-06-16 05:51:00 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1;
|
2000-08-20 21:24:14 +08:00
|
|
|
long ret;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
2000-08-20 21:24:14 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
ret = php_stream_tell(stream);
|
2002-03-16 05:03:08 +08:00
|
|
|
if (ret == -1) {
|
2000-08-20 21:24:14 +08:00
|
|
|
RETURN_FALSE;
|
2001-04-18 01:06:06 +08:00
|
|
|
}
|
2000-08-20 21:24:14 +08:00
|
|
|
RETURN_LONG(ret);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto int fseek(resource fp, int offset [, int whence])
|
1999-10-15 23:22:25 +08:00
|
|
|
Seek on a file pointer */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(fseek)
|
1999-06-16 05:51:00 +08:00
|
|
|
{
|
2000-04-24 22:18:11 +08:00
|
|
|
zval **arg1, **arg2, **arg3;
|
2001-08-17 17:08:03 +08:00
|
|
|
int argcount = ZEND_NUM_ARGS(), whence = SEEK_SET;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +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;
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
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);
|
2001-08-17 17:08:03 +08:00
|
|
|
whence = Z_LVAL_PP(arg3);
|
2000-04-24 03:16:24 +08:00
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
RETURN_LONG(php_stream_seek(stream, Z_LVAL_PP(arg2), 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
|
|
|
/* }}} */
|
2003-02-10 04:35:54 +08:00
|
|
|
|
|
|
|
/* {{{ proto int mkdir(char *dir int mode)
|
|
|
|
*/
|
|
|
|
|
|
|
|
PHPAPI int php_mkdir(char *dir, long mode TSRMLS_DC)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (PG(safe_mode) && (!php_checkuid(dir, NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (php_check_open_basedir(dir TSRMLS_CC)) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ret = VCWD_MKDIR(dir, (mode_t)mode)) < 0) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, strerror(errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
|
|
|
/* {{{ proto bool mkdir(string pathname [, int mode [, bool recursive])
|
1999-10-15 23:22:25 +08:00
|
|
|
Create a directory */
|
1999-06-16 05:51:00 +08:00
|
|
|
PHP_FUNCTION(mkdir)
|
|
|
|
{
|
2002-01-11 18:44:24 +08:00
|
|
|
int dir_len, ret;
|
2002-05-07 01:31:22 +08:00
|
|
|
long mode = 0777;
|
2002-01-11 18:44:24 +08:00
|
|
|
char *dir;
|
2003-02-10 04:35:54 +08:00
|
|
|
zend_bool recursive = 0;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2003-02-10 04:35:54 +08:00
|
|
|
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|lb", &dir, &dir_len, &mode, &recursive) == FAILURE) {
|
2002-01-11 18:44:24 +08:00
|
|
|
return;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2003-02-10 04:35:54 +08:00
|
|
|
if (!recursive) {
|
2003-02-10 07:11:23 +08:00
|
|
|
ret = php_mkdir(dir, mode TSRMLS_CC);
|
2003-02-10 04:35:54 +08:00
|
|
|
} else {
|
|
|
|
/* we look for directory separator from the end of string, thus hopefuly reducing our work load */
|
|
|
|
char *p, *e, *buf;
|
|
|
|
struct stat sb;
|
|
|
|
|
|
|
|
buf = estrndup(dir, dir_len);
|
|
|
|
e = buf + dir_len;
|
|
|
|
|
|
|
|
/* find a top level directory we need to create */
|
|
|
|
while ((p = strrchr(buf, DEFAULT_SLASH))) {
|
|
|
|
*p = '\0';
|
|
|
|
if (VCWD_STAT(buf, &sb) == 0) {
|
|
|
|
*p = DEFAULT_SLASH;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p == buf) {
|
2003-02-10 07:11:23 +08:00
|
|
|
ret = php_mkdir(dir, mode TSRMLS_CC);
|
|
|
|
} else if (!(ret = php_mkdir(buf, mode TSRMLS_CC))) {
|
2003-02-10 04:35:54 +08:00
|
|
|
if (!p) {
|
|
|
|
p = buf;
|
|
|
|
}
|
|
|
|
/* create any needed directories if the creation of the 1st directory worked */
|
|
|
|
while (++p != e) {
|
|
|
|
if (*p == '\0' && *(p + 1) != '\0') {
|
|
|
|
*p = DEFAULT_SLASH;
|
|
|
|
if ((ret = VCWD_MKDIR(buf, (mode_t)mode)) < 0) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, strerror(errno));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
efree(buf);
|
2001-12-21 16:04:21 +08:00
|
|
|
}
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
RETURN_FALSE;
|
2003-02-10 04:35:54 +08:00
|
|
|
} else {
|
|
|
|
RETURN_TRUE;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto bool 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)
|
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1;
|
1999-04-17 08:37:12 +08:00
|
|
|
int ret;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_string_ex(arg1);
|
2001-12-21 16:04:21 +08:00
|
|
|
|
2002-05-12 23:59:42 +08:00
|
|
|
if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(arg1), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2001-12-21 16:04:21 +08:00
|
|
|
if (php_check_open_basedir(Z_STRVAL_PP(arg1) TSRMLS_CC)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
ret = VCWD_RMDIR(Z_STRVAL_PP(arg1));
|
1999-04-17 08:37:12 +08:00
|
|
|
if (ret < 0) {
|
2002-08-26 02:21:40 +08:00
|
|
|
php_error_docref1(NULL TSRMLS_CC, Z_STRVAL_PP(arg1), E_WARNING, "%s", strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2003-02-27 03:34:16 +08:00
|
|
|
/* {{{ proto int readfile(string filename [, bool 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)
|
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1, **arg2;
|
1999-09-12 02:15:39 +08:00
|
|
|
int size=0;
|
|
|
|
int use_include_path=0;
|
2002-03-16 09:34:52 +08:00
|
|
|
php_stream *stream;
|
2002-03-16 05:03:08 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
/* check args */
|
2001-08-17 17:08:03 +08:00
|
|
|
switch (ZEND_NUM_ARGS()) {
|
1999-04-17 08:37:12 +08:00
|
|
|
case 1:
|
2001-08-12 01:03:37 +08:00
|
|
|
if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
2001-08-12 01:03:37 +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);
|
2001-08-17 17:08:03 +08:00
|
|
|
use_include_path = Z_LVAL_PP(arg2);
|
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
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
stream = php_stream_open_wrapper(Z_STRVAL_PP(arg1), "rb",
|
2002-08-25 20:09:57 +08:00
|
|
|
(use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS,
|
2002-03-18 16:05:28 +08:00
|
|
|
NULL);
|
2002-03-16 05:03:08 +08:00
|
|
|
if (stream) {
|
2002-03-21 09:11:52 +08:00
|
|
|
size = php_stream_passthru(stream);
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_close(stream);
|
|
|
|
RETURN_LONG(size);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2002-03-16 05:03:08 +08:00
|
|
|
RETURN_FALSE;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2001-08-17 17:08:03 +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;
|
2001-08-17 17:08:03 +08:00
|
|
|
int arg_count = ZEND_NUM_ARGS();
|
2001-04-18 01:06:06 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
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);
|
2001-08-17 17:08:03 +08:00
|
|
|
umask(Z_LVAL_PP(arg1));
|
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
|
|
|
/* }}} */
|
2001-10-08 02:34:44 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto int fpassthru(resource fp)
|
1999-10-15 23:22:25 +08:00
|
|
|
Output all remaining data from a file pointer */
|
|
|
|
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(fpassthru)
|
1999-06-16 05:51:00 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1;
|
2002-09-25 23:25:12 +08:00
|
|
|
int size;
|
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 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
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
size = php_stream_passthru(stream);
|
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
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto bool 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)
|
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **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;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 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
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
old_name = Z_STRVAL_PP(old_arg);
|
|
|
|
new_name = Z_STRVAL_PP(new_arg);
|
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;
|
|
|
|
}
|
2001-12-21 16:04:21 +08:00
|
|
|
|
|
|
|
if (php_check_open_basedir(old_name TSRMLS_CC)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-04-30 20:45:02 +08:00
|
|
|
ret = VCWD_RENAME(old_name, new_name);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
if (ret == -1) {
|
2002-08-26 02:21:40 +08:00
|
|
|
php_error_docref2(NULL TSRMLS_CC, old_name, new_name, E_WARNING, "%s", strerror(errno));
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
RETURN_TRUE;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-07-02 23:12:34 +08:00
|
|
|
/* }}} */
|
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto bool unlink(string filename)
|
2000-07-02 23:12:34 +08:00
|
|
|
Delete a file */
|
|
|
|
PHP_FUNCTION(unlink)
|
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **filename;
|
2000-07-02 23:12:34 +08:00
|
|
|
int ret;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2000-07-02 23:12:34 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &filename) == FAILURE) {
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
convert_to_string_ex(filename);
|
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (PG(safe_mode) && !php_checkuid(Z_STRVAL_PP(filename), NULL, CHECKUID_CHECK_FILE_AND_DIR)) {
|
2000-07-02 23:12:34 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-12-21 16:04:21 +08:00
|
|
|
if (php_check_open_basedir(Z_STRVAL_PP(filename) TSRMLS_CC)) {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
ret = VCWD_UNLINK(Z_STRVAL_PP(filename));
|
2000-07-02 23:12:34 +08:00
|
|
|
if (ret == -1) {
|
2002-08-26 02:21:40 +08:00
|
|
|
php_error_docref1(NULL TSRMLS_CC, Z_STRVAL_PP(filename), E_WARNING, "%s", strerror(errno));
|
2000-07-02 23:12:34 +08:00
|
|
|
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
|
|
|
|
2003-02-28 01:43:38 +08:00
|
|
|
/* {{{ proto bool ftruncate(resource fp, int size)
|
2000-03-05 01:23:03 +08:00
|
|
|
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;
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream *stream;
|
2000-03-05 01:23:03 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &fp, &size) == FAILURE) {
|
2000-03-05 01:23:03 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, fp);
|
2000-03-05 01:23:03 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
convert_to_long_ex(size);
|
|
|
|
|
2003-02-28 01:43:38 +08:00
|
|
|
if (!php_stream_truncate_supported(stream)) {
|
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Can't truncate this stream!");
|
2000-03-05 01:23:03 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2003-02-28 01:43:38 +08:00
|
|
|
|
|
|
|
RETURN_BOOL(0 == php_stream_truncate_set_size(stream, Z_LVAL_PP(size)));
|
2000-03-05 01:23:03 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto int fstat(resource 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;
|
2001-08-12 01:03:37 +08:00
|
|
|
zval *stat_dev, *stat_ino, *stat_mode, *stat_nlink, *stat_uid, *stat_gid, *stat_rdev,
|
2001-05-12 03:55:44 +08:00
|
|
|
*stat_size, *stat_atime, *stat_mtime, *stat_ctime, *stat_blksize, *stat_blocks;
|
2002-03-28 08:49:00 +08:00
|
|
|
php_stream *stream;
|
|
|
|
php_stream_statbuf stat_ssb;
|
2001-05-12 03:55:44 +08:00
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
char *stat_sb_names[13]={"dev", "ino", "mode", "nlink", "uid", "gid", "rdev",
|
|
|
|
"size", "atime", "mtime", "ctime", "blksize", "blocks"};
|
2000-03-05 01:23:03 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &fp) == FAILURE) {
|
2000-03-05 01:23:03 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, fp);
|
2000-03-05 01:23:03 +08:00
|
|
|
|
2002-03-28 08:49:00 +08:00
|
|
|
if (php_stream_stat(stream, &stat_ssb)) {
|
2000-03-05 01:23:03 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
array_init(return_value);
|
|
|
|
|
2002-03-28 08:49:00 +08:00
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_dev, stat_ssb.sb.st_dev);
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_ino, stat_ssb.sb.st_ino);
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_mode, stat_ssb.sb.st_mode);
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_nlink, stat_ssb.sb.st_nlink);
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_uid, stat_ssb.sb.st_uid);
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_gid, stat_ssb.sb.st_gid);
|
2001-05-11 09:47:46 +08:00
|
|
|
#ifdef HAVE_ST_RDEV
|
2002-03-28 08:49:00 +08:00
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_rdev, stat_ssb.sb.st_rdev);
|
2001-05-11 09:47:46 +08:00
|
|
|
#else
|
2001-05-12 03:55:44 +08:00
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_rdev, -1);
|
2001-05-11 09:47:46 +08:00
|
|
|
#endif
|
2002-03-28 08:49:00 +08:00
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_size, stat_ssb.sb.st_size);
|
2003-01-03 22:37:42 +08:00
|
|
|
#if defined(NETWARE) && defined(CLIB_STAT_PATCH)
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_atime, stat_ssb.sb.st_atime.tv_sec);
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_ssb.sb.st_mtime.tv_sec);
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_ssb.sb.st_ctime.tv_sec);
|
|
|
|
#else
|
2002-03-28 08:49:00 +08:00
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_atime, stat_ssb.sb.st_atime);
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_mtime, stat_ssb.sb.st_mtime);
|
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_ctime, stat_ssb.sb.st_ctime);
|
2003-01-03 22:37:42 +08:00
|
|
|
#endif
|
|
|
|
|
2001-05-11 09:47:46 +08:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
2002-03-28 08:49:00 +08:00
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_blksize, stat_ssb.sb.st_blksize);
|
2001-05-11 09:47:46 +08:00
|
|
|
#else
|
2001-05-12 03:55:44 +08:00
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_blksize,-1);
|
2001-05-11 09:47:46 +08:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ST_BLOCKS
|
2002-03-28 08:49:00 +08:00
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_blocks, stat_ssb.sb.st_blocks);
|
2001-05-11 09:47:46 +08:00
|
|
|
#else
|
2001-05-12 03:55:44 +08:00
|
|
|
MAKE_LONG_ZVAL_INCREF(stat_blocks,-1);
|
2000-03-05 01:23:03 +08:00
|
|
|
#endif
|
2001-05-12 03:55:44 +08:00
|
|
|
/* Store numeric indexes in propper order */
|
2001-08-12 01:03:37 +08:00
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_dev, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ino, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mode, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_nlink, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_uid, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_gid, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_rdev, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_size, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_atime, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_mtime, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_ctime, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blksize, sizeof(zval *), NULL);
|
|
|
|
zend_hash_next_index_insert(HASH_OF(return_value), (void *)&stat_blocks, sizeof(zval *), NULL);
|
2001-05-12 03:55:44 +08:00
|
|
|
|
|
|
|
/* Store string indexes referencing the same zval*/
|
2001-08-12 01:03:37 +08:00
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[0], strlen(stat_sb_names[0])+1, (void *)&stat_dev, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[1], strlen(stat_sb_names[1])+1, (void *)&stat_ino, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[2], strlen(stat_sb_names[2])+1, (void *)&stat_mode, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[3], strlen(stat_sb_names[3])+1, (void *)&stat_nlink, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[4], strlen(stat_sb_names[4])+1, (void *)&stat_uid, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[5], strlen(stat_sb_names[5])+1, (void *)&stat_gid, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[6], strlen(stat_sb_names[6])+1, (void *)&stat_rdev, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[7], strlen(stat_sb_names[7])+1, (void *)&stat_size, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[8], strlen(stat_sb_names[8])+1, (void *)&stat_atime, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[9], strlen(stat_sb_names[9])+1, (void *)&stat_mtime, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[10], strlen(stat_sb_names[10])+1, (void *)&stat_ctime, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[11], strlen(stat_sb_names[11])+1, (void *)&stat_blksize, sizeof(zval *), NULL);
|
|
|
|
zend_hash_update(HASH_OF(return_value), stat_sb_names[12], strlen(stat_sb_names[12])+1, (void *)&stat_blocks, sizeof(zval *), NULL);
|
2000-03-05 01:23:03 +08:00
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto bool 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
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **source, **target;
|
2001-03-23 17:30:51 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 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
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (PG(safe_mode) &&(!php_checkuid(Z_STRVAL_PP(source), NULL, CHECKUID_CHECK_FILE_AND_DIR))) {
|
1999-04-17 08:37:12 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-03-23 17:30:51 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (php_check_open_basedir(Z_STRVAL_PP(source) TSRMLS_CC)) {
|
2001-05-20 06:50:44 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2001-08-05 09:43:02 +08:00
|
|
|
if (php_copy_file(Z_STRVAL_PP(source), Z_STRVAL_PP(target) TSRMLS_CC)==SUCCESS) {
|
2000-09-09 06:31:21 +08:00
|
|
|
RETURN_TRUE;
|
|
|
|
} else {
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_copy_file
|
|
|
|
*/
|
2001-08-05 09:43:02 +08:00
|
|
|
PHPAPI int php_copy_file(char *src, char *dest TSRMLS_DC)
|
2000-09-09 06:31:21 +08:00
|
|
|
{
|
2002-03-16 09:34:52 +08:00
|
|
|
php_stream *srcstream = NULL, *deststream = NULL;
|
2000-12-23 00:34:11 +08:00
|
|
|
int ret = FAILURE;
|
2000-09-09 06:31:21 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
srcstream = php_stream_open_wrapper(src, "rb",
|
2003-02-25 05:40:23 +08:00
|
|
|
STREAM_DISABLE_OPEN_BASEDIR | REPORT_ERRORS,
|
2002-03-18 16:05:28 +08:00
|
|
|
NULL);
|
2002-09-13 21:34:06 +08:00
|
|
|
|
2003-01-10 07:23:32 +08:00
|
|
|
if (!srcstream) {
|
2002-09-13 21:34:06 +08:00
|
|
|
return ret;
|
2003-01-10 07:23:32 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
deststream = php_stream_open_wrapper(dest, "wb",
|
|
|
|
ENFORCE_SAFE_MODE | REPORT_ERRORS,
|
2002-03-18 16:05:28 +08:00
|
|
|
NULL);
|
2000-12-23 00:34:11 +08:00
|
|
|
|
2003-01-10 07:23:32 +08:00
|
|
|
if (srcstream && deststream) {
|
2002-03-16 10:48:35 +08:00
|
|
|
ret = php_stream_copy_to_stream(srcstream, deststream, PHP_STREAM_COPY_ALL) == 0 ? FAILURE : SUCCESS;
|
2003-01-10 07:23:32 +08:00
|
|
|
}
|
|
|
|
if (srcstream) {
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_close(srcstream);
|
2003-01-10 07:23:32 +08:00
|
|
|
}
|
|
|
|
if (deststream) {
|
2002-03-16 05:03:08 +08:00
|
|
|
php_stream_close(deststream);
|
2003-01-10 07:23:32 +08:00
|
|
|
}
|
2000-12-23 00:34:11 +08:00
|
|
|
return ret;
|
2001-04-18 01:06:06 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-06-16 05:51:00 +08:00
|
|
|
|
2001-11-12 04:33:27 +08:00
|
|
|
/* {{{ proto string fread(resource fp, int length)
|
1999-10-15 23:22:25 +08:00
|
|
|
Binary-safe file read */
|
2002-04-05 19:51:43 +08:00
|
|
|
PHPAPI PHP_FUNCTION(fread)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2001-08-17 17:08:03 +08:00
|
|
|
zval **arg1, **arg2;
|
2002-09-25 23:25:12 +08:00
|
|
|
int len;
|
2002-03-16 09:34:52 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (ZEND_NUM_ARGS() != 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
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, arg1);
|
1999-10-15 23:22:25 +08:00
|
|
|
|
|
|
|
convert_to_long_ex(arg2);
|
2001-08-17 17:08:03 +08:00
|
|
|
len = Z_LVAL_PP(arg2);
|
2003-01-10 07:23:32 +08:00
|
|
|
if (len < 0) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative");
|
2000-08-22 03:24:44 +08:00
|
|
|
RETURN_FALSE;
|
2003-01-10 07:23:32 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
Z_STRVAL_P(return_value) = emalloc(len + 1);
|
2002-03-16 05:03:08 +08:00
|
|
|
Z_STRLEN_P(return_value) = php_stream_read(stream, Z_STRVAL_P(return_value), len);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
/* needed because recv/read/gzread doesnt put a null at the end*/
|
2001-08-17 17:08:03 +08:00
|
|
|
Z_STRVAL_P(return_value)[Z_STRLEN_P(return_value)] = 0;
|
2002-03-16 05:03:08 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
if (PG(magic_quotes_runtime)) {
|
2001-08-17 17:08:03 +08:00
|
|
|
Z_STRVAL_P(return_value) = php_addslashes(Z_STRVAL_P(return_value),
|
|
|
|
Z_STRLEN_P(return_value), &Z_STRLEN_P(return_value), 1 TSRMLS_CC);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
Z_TYPE_P(return_value) = IS_STRING;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
/* }}} */
|
2001-06-06 21:06:12 +08:00
|
|
|
|
2002-05-23 15:08:25 +08:00
|
|
|
/* {{{ proto array fgetcsv(resource fp, int length [, string delimiter [, string enclosure]])
|
2000-02-24 16:07:29 +08:00
|
|
|
Get line from file pointer and parse for CSV fields */
|
2001-08-05 09:43:02 +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 */
|
2002-05-23 15:03:43 +08:00
|
|
|
char enclosure = '"'; /* 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
|
|
|
|
2002-05-23 15:03:43 +08:00
|
|
|
zval **fd, **bytes, **p_delim, **p_enclosure;
|
2002-12-06 04:01:19 +08:00
|
|
|
int len, temp_len;
|
1999-06-11 17:23:00 +08:00
|
|
|
char *buf;
|
2002-03-16 09:34:52 +08:00
|
|
|
php_stream *stream;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
switch(ZEND_NUM_ARGS()) {
|
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;
|
2001-04-18 01:06:06 +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 */
|
2001-09-26 05:58:48 +08:00
|
|
|
if (Z_STRLEN_PP(p_delim) < 1) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Third parameter must be a character");
|
2002-05-23 15:03:43 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* use first character from string */
|
|
|
|
delimiter = Z_STRVAL_PP(p_delim)[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
if (zend_get_parameters_ex(4, &fd, &bytes, &p_delim, &p_enclosure) == FAILURE) {
|
1999-10-15 23:22:25 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
2002-05-23 15:03:43 +08:00
|
|
|
convert_to_string_ex(p_delim);
|
|
|
|
/* Make sure that there is at least one character in string */
|
|
|
|
if (Z_STRLEN_PP(p_delim) < 1) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Third parameter must be a character");
|
2002-05-23 15:03:43 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* use first character from string */
|
2001-08-17 17:08:03 +08:00
|
|
|
delimiter = Z_STRVAL_PP(p_delim)[0];
|
2002-05-23 15:03:43 +08:00
|
|
|
|
|
|
|
convert_to_string_ex(p_enclosure);
|
|
|
|
/* use first character from string */
|
|
|
|
enclosure = Z_STRVAL_PP(p_enclosure)[0];
|
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
break;
|
2001-04-18 01:06:06 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
1999-04-27 21:06:58 +08:00
|
|
|
}
|
|
|
|
|
2002-09-25 23:25:12 +08:00
|
|
|
php_stream_from_zval(stream, fd);
|
1999-04-27 21:06:58 +08:00
|
|
|
|
1999-10-15 23:22:25 +08:00
|
|
|
convert_to_long_ex(bytes);
|
2001-08-17 17:08:03 +08:00
|
|
|
len = Z_LVAL_PP(bytes);
|
2001-04-18 01:06:06 +08:00
|
|
|
if (len < 0) {
|
2002-08-24 09:19:28 +08:00
|
|
|
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter may not be negative");
|
2000-08-22 03:24:44 +08:00
|
|
|
RETURN_FALSE;
|
2001-04-18 01:06:06 +08:00
|
|
|
}
|
1999-10-15 23:22:25 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
buf = emalloc(len + 1);
|
2002-05-23 15:08:25 +08:00
|
|
|
/* needed because recv/read/gzread 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);
|
2002-03-16 05:03:08 +08:00
|
|
|
|
2002-05-23 15:08:25 +08:00
|
|
|
if (php_stream_gets(stream, buf, len) == NULL) {
|
1999-04-27 21:06:58 +08:00
|
|
|
efree(buf);
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
2002-05-23 15:03:43 +08:00
|
|
|
/* Now into new section that parses buf for delimiter/enclosure fields */
|
1999-04-27 21:06:58 +08:00
|
|
|
|
2002-05-23 15:03:43 +08:00
|
|
|
/* Strip trailing space from buf, saving end of line in case required for enclosure field */
|
1999-04-27 21:06:58 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
lineEnd = emalloc(len + 1);
|
2001-04-18 01:06:06 +08:00
|
|
|
bptr = buf;
|
|
|
|
tptr = buf + strlen(buf) -1;
|
2003-02-18 23:15:22 +08:00
|
|
|
while ( isspace((int)*(unsigned char *)tptr) && (*tptr!=delimiter) && (tptr > bptr) ) tptr--;
|
2001-04-18 01:06:06 +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 */
|
|
|
|
|
2002-12-06 04:01:19 +08:00
|
|
|
temp_len = len;
|
|
|
|
temp = emalloc(temp_len + 1); /* 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 */
|
2001-08-17 17:08:03 +08:00
|
|
|
array_init(return_value);
|
1999-04-27 21:06:58 +08:00
|
|
|
|
|
|
|
/* Main loop to read CSV fields */
|
|
|
|
/* NB this routine will return a single null entry for a blank line */
|
|
|
|
|
2002-05-23 15:08:25 +08:00
|
|
|
do {
|
2001-04-18 01:06:06 +08:00
|
|
|
/* 1. Strip any leading space */
|
2003-02-18 23:15:22 +08:00
|
|
|
while(isspace((int)*(unsigned char *)bptr) && (*bptr!=delimiter)) bptr++;
|
1999-04-27 21:06:58 +08:00
|
|
|
/* 2. Read field, leaving bptr pointing at start of next field */
|
2002-06-18 20:16:27 +08:00
|
|
|
if (enclosure && *bptr == enclosure) {
|
2002-08-18 14:55:32 +08:00
|
|
|
bptr++; /* move on to first character in field */
|
2002-12-06 04:01:19 +08:00
|
|
|
|
2002-05-23 15:03:43 +08:00
|
|
|
/* 2A. handle enclosure delimited field */
|
1999-04-27 21:06:58 +08:00
|
|
|
while (*bptr) {
|
2003-02-24 11:13:25 +08:00
|
|
|
/* we need to determine if the enclosure is 'real' or is it escaped */
|
|
|
|
if (*(bptr - 1) == '\\') {
|
|
|
|
int escape_cnt = 0;
|
|
|
|
char *bptr_p = bptr - 2;
|
|
|
|
|
|
|
|
while (bptr_p > buf && *bptr_p == '\\') {
|
|
|
|
escape_cnt++;
|
|
|
|
bptr_p--;
|
|
|
|
}
|
|
|
|
if (!(escape_cnt % 2)) {
|
|
|
|
goto normal_char;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-23 15:03:43 +08:00
|
|
|
if (*bptr == enclosure) {
|
|
|
|
/* handle the enclosure */
|
2002-06-18 20:16:27 +08:00
|
|
|
if ( *(bptr+1) == enclosure) {
|
2002-05-23 15:03:43 +08:00
|
|
|
/* embedded enclosure */
|
1999-04-27 21:06:58 +08:00
|
|
|
*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 {
|
2003-02-24 11:13:25 +08:00
|
|
|
normal_char:
|
1999-04-27 21:06:58 +08:00
|
|
|
/* normal character */
|
|
|
|
*tptr++ = *bptr++;
|
2000-04-19 21:03:47 +08:00
|
|
|
|
2001-04-18 01:06:06 +08:00
|
|
|
if (*bptr == 0) { /* embedded line end? */
|
|
|
|
*(tptr-1)=0; /* remove space character added on reading line */
|
2001-08-12 01:03:37 +08:00
|
|
|
strcat(temp, lineEnd); /* add the embedded line end to the field */
|
2000-04-19 21:03:47 +08:00
|
|
|
|
2001-04-18 01:06:06 +08:00
|
|
|
/* read a new line from input, as at start of routine */
|
2001-08-12 01:03:37 +08:00
|
|
|
memset(buf, 0, len+1);
|
2002-03-16 05:03:08 +08:00
|
|
|
|
2002-05-23 15:08:25 +08:00
|
|
|
if (php_stream_gets(stream, buf, len) == NULL) {
|
2002-12-06 04:01:19 +08:00
|
|
|
/* we've got an unterminated enclosure, assign all the data
|
|
|
|
* from the start of the enclosure to end of data to the last element
|
|
|
|
*/
|
|
|
|
if (temp_len > len) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
efree(lineEnd);
|
|
|
|
efree(temp);
|
|
|
|
efree(buf);
|
2003-01-10 06:49:18 +08:00
|
|
|
zval_dtor(return_value);
|
2001-04-18 01:06:06 +08:00
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
|
2002-12-06 04:01:19 +08:00
|
|
|
temp_len += len;
|
|
|
|
temp = erealloc(temp, temp_len+1);
|
2001-04-18 01:06:06 +08:00
|
|
|
bptr = buf;
|
|
|
|
tptr = buf + strlen(buf) -1;
|
2003-02-18 23:15:22 +08:00
|
|
|
while (isspace((int)*(unsigned char *)tptr) && (*tptr!=delimiter) && (tptr > bptr))
|
2001-08-17 17:08:03 +08:00
|
|
|
tptr--;
|
|
|
|
tptr++;
|
|
|
|
strcpy(lineEnd, tptr);
|
|
|
|
*tptr++ = ' ';
|
|
|
|
*tptr = 0;
|
|
|
|
|
|
|
|
tptr = temp; /* reset temp pointer to end of field as read so far */
|
|
|
|
while (*tptr)
|
|
|
|
tptr++;
|
2001-04-18 01:06:06 +08:00
|
|
|
}
|
1999-04-27 21:06:58 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2002-05-23 15:03:43 +08:00
|
|
|
/* 2B. Handle non-enclosure field */
|
2001-08-17 17:08:03 +08:00
|
|
|
while ((*bptr != delimiter) && *bptr)
|
|
|
|
*tptr++ = *bptr++;
|
1999-04-27 21:06:58 +08:00
|
|
|
*tptr=0; /* terminate temporary string */
|
2001-08-17 17:08:03 +08:00
|
|
|
|
1999-04-27 21:06:58 +08:00
|
|
|
if (strlen(temp)) {
|
|
|
|
tptr--;
|
2003-02-18 23:15:22 +08:00
|
|
|
while (isspace((int)*(unsigned char *)tptr) && (*tptr!=delimiter))
|
2001-08-17 17:08:03 +08:00
|
|
|
*tptr-- = 0; /* strip any trailing spaces */
|
1999-04-27 21:06:58 +08:00
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
|
|
|
|
if (*bptr == delimiter)
|
|
|
|
bptr++;
|
1999-04-27 21:06:58 +08:00
|
|
|
}
|
2001-08-17 17:08:03 +08:00
|
|
|
|
1999-04-27 21:06:58 +08:00
|
|
|
/* 3. Now pass our field back to php */
|
|
|
|
add_next_index_string(return_value, temp, 1);
|
2001-08-17 17:08:03 +08:00
|
|
|
tptr = temp;
|
1999-04-27 21:06:58 +08:00
|
|
|
} while (*bptr);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2000-04-19 21:03:47 +08:00
|
|
|
efree(lineEnd);
|
1999-04-27 21:06:58 +08:00
|
|
|
efree(temp);
|
|
|
|
efree(buf);
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
|
2002-09-05 22:25:07 +08:00
|
|
|
#if (!defined(PHP_WIN32) && !defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || 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);
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-08-17 17:08:03 +08:00
|
|
|
if (VCWD_REALPATH(Z_STRVAL_PP(path), resolved_path_buff)) {
|
2000-08-07 00:22:07 +08:00
|
|
|
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
|
|
|
|
|
2001-03-06 12:34:05 +08:00
|
|
|
/* See http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2 */
|
2001-03-06 12:42:04 +08:00
|
|
|
#define PHP_META_HTML401_CHARS "-_.:"
|
2001-03-06 12:34:05 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_next_meta_token
|
|
|
|
Tokenizes an HTML file for get_meta_tags */
|
2002-03-19 02:54:32 +08:00
|
|
|
php_meta_tags_token php_next_meta_token(php_meta_tags_data *md TSRMLS_DC)
|
2001-07-01 04:07:12 +08:00
|
|
|
{
|
|
|
|
int ch = 0, compliment;
|
2001-02-11 10:38:40 +08:00
|
|
|
char buff[META_DEF_BUFSIZE + 1];
|
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
memset((void *)buff, 0, META_DEF_BUFSIZE + 1);
|
2001-02-11 10:38:40 +08:00
|
|
|
|
2002-03-16 05:03:08 +08:00
|
|
|
while (md->ulc || (!php_stream_eof(md->stream) && (ch = php_stream_getc(md->stream)))) {
|
|
|
|
if(php_stream_eof(md->stream))
|
2001-02-11 10:38:40 +08:00
|
|
|
break;
|
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
if (md->ulc) {
|
|
|
|
ch = md->lc;
|
|
|
|
md->ulc = 0;
|
2001-02-11 10:38:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (ch) {
|
|
|
|
case '<':
|
|
|
|
return TOK_OPENTAG;
|
|
|
|
break;
|
|
|
|
case '>':
|
|
|
|
return TOK_CLOSETAG;
|
|
|
|
break;
|
|
|
|
case '=':
|
|
|
|
return TOK_EQUAL;
|
|
|
|
break;
|
|
|
|
case '/':
|
|
|
|
return TOK_SLASH;
|
|
|
|
break;
|
2001-03-05 08:20:41 +08:00
|
|
|
case '\'':
|
2001-02-11 10:38:40 +08:00
|
|
|
case '"':
|
2001-03-05 08:20:41 +08:00
|
|
|
compliment = ch;
|
2001-07-01 04:07:12 +08:00
|
|
|
md->token_len = 0;
|
2002-03-16 05:03:08 +08:00
|
|
|
while (!php_stream_eof(md->stream) &&
|
|
|
|
(ch = php_stream_getc(md->stream)) &&
|
2001-07-01 04:07:12 +08:00
|
|
|
ch != compliment && ch != '<' && ch != '>') {
|
2001-02-11 10:38:40 +08:00
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
buff[(md->token_len)++] = ch;
|
|
|
|
|
|
|
|
if (md->token_len == META_DEF_BUFSIZE)
|
2001-02-11 10:38:40 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-04-18 01:06:06 +08:00
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
if (ch == '<' || ch == '>') {
|
|
|
|
/* Was just an apostrohpe */
|
|
|
|
md->ulc = 1;
|
|
|
|
md->lc = ch;
|
|
|
|
}
|
|
|
|
|
2001-08-04 20:36:51 +08:00
|
|
|
/* We don't need to alloc unless we are in a meta tag */
|
|
|
|
if (md->in_meta) {
|
|
|
|
md->token_data = (char *) emalloc(md->token_len + 1);
|
2001-08-12 01:03:37 +08:00
|
|
|
memcpy(md->token_data, buff, md->token_len+1);
|
2001-08-04 20:36:51 +08:00
|
|
|
}
|
2001-02-11 10:38:40 +08:00
|
|
|
|
|
|
|
return TOK_STRING;
|
|
|
|
break;
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
case '\t':
|
|
|
|
break;
|
|
|
|
case ' ':
|
|
|
|
return TOK_SPACE;
|
|
|
|
break;
|
|
|
|
default:
|
2001-03-06 12:34:05 +08:00
|
|
|
if (isalnum(ch)) {
|
2001-07-01 04:07:12 +08:00
|
|
|
md->token_len = 0;
|
|
|
|
buff[(md->token_len)++] = ch;
|
2002-03-16 05:03:08 +08:00
|
|
|
while (!php_stream_eof(md->stream) &&
|
|
|
|
(ch = php_stream_getc(md->stream)) &&
|
2001-08-12 01:03:37 +08:00
|
|
|
(isalnum(ch) || strchr(PHP_META_HTML401_CHARS, ch))) {
|
2001-03-06 12:34:05 +08:00
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
buff[(md->token_len)++] = ch;
|
2001-02-11 10:38:40 +08:00
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
if (md->token_len == META_DEF_BUFSIZE)
|
2001-02-11 10:38:40 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is ugly, but we have to replace ungetc */
|
|
|
|
if (!isalpha(ch) && ch != '-') {
|
2001-07-01 04:07:12 +08:00
|
|
|
md->ulc = 1;
|
|
|
|
md->lc = ch;
|
2001-02-11 10:38:40 +08:00
|
|
|
}
|
|
|
|
|
2001-07-01 04:07:12 +08:00
|
|
|
md->token_data = (char *) emalloc(md->token_len + 1);
|
2001-08-12 01:03:37 +08:00
|
|
|
memcpy(md->token_data, buff, md->token_len+1);
|
2001-02-11 10:38:40 +08:00
|
|
|
|
|
|
|
return TOK_ID;
|
|
|
|
} else {
|
|
|
|
return TOK_OTHER;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TOK_EOF;
|
|
|
|
}
|
2001-08-04 20:36:51 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2001-02-11 10:38:40 +08:00
|
|
|
|
2002-03-22 03:18:13 +08:00
|
|
|
#ifdef HAVE_FNMATCH
|
|
|
|
/* {{{ proto bool fnmatch(string pattern, string filename [, int flags])
|
|
|
|
Match filename against pattern */
|
|
|
|
PHP_FUNCTION(fnmatch)
|
|
|
|
{
|
|
|
|
char *pattern = NULL;
|
|
|
|
char *filename = NULL;
|
|
|
|
int argc = ZEND_NUM_ARGS();
|
|
|
|
int pattern_len;
|
|
|
|
int filename_len;
|
|
|
|
long flags=0;
|
|
|
|
|
|
|
|
if (zend_parse_parameters(argc TSRMLS_CC, "ss|l",
|
|
|
|
&pattern, &pattern_len,
|
|
|
|
&filename, &filename_len,
|
|
|
|
&flags)
|
|
|
|
== FAILURE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
RETURN_BOOL( ! fnmatch( pattern, filename, flags ));
|
|
|
|
}
|
|
|
|
/* }}} */
|
|
|
|
#endif
|
|
|
|
|
2000-03-07 04:37:11 +08:00
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2002-01-11 18:44:24 +08:00
|
|
|
* vim600: noet sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: noet sw=4 ts=4
|
2000-03-07 04:37:11 +08:00
|
|
|
*/
|