⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 file.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	}	context = decode_context_param(zcontext TSRMLS_CC);	ZEND_VERIFY_RESOURCE(context);	*return_value = *context->options;	zval_copy_ctor(return_value);	INIT_PZVAL(return_value);}/* }}} *//* {{{ proto bool stream_context_set_option(resource context|resource stream, string wrappername, string optionname, mixed value)   Set an option for a wrapper */PHP_FUNCTION(stream_context_set_option){	zval *options = NULL, *zcontext = NULL, *zvalue = NULL;	php_stream_context *context;	char *wrappername, *optionname;	int wrapperlen, optionlen;	if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,				"rssz", &zcontext, &wrappername, &wrapperlen,				&optionname, &optionlen, &zvalue) == FAILURE) {		if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, ZEND_NUM_ARGS() TSRMLS_CC,					"ra", &zcontext, &options) == FAILURE) {			php_error_docref(NULL TSRMLS_CC, E_WARNING, "called with wrong number or type of parameters; please RTM");			RETURN_FALSE;		}	}	/* figure out where the context is coming from exactly */	context = decode_context_param(zcontext TSRMLS_CC);	ZEND_VERIFY_RESOURCE(context);	if (options) {		/* handle the array syntax */		RETVAL_BOOL(parse_context_options(context, options) == SUCCESS);	} else {		php_stream_context_set_option(context, wrappername, optionname, zvalue);		RETVAL_TRUE;	}}/* }}} *//* {{{ proto bool stream_context_set_params(resource context|resource stream, array options)   Set parameters for a file context */PHP_FUNCTION(stream_context_set_params){	zval *params, *zcontext;	php_stream_context *context;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &zcontext, &params) == FAILURE) {		RETURN_FALSE;	}	context = decode_context_param(zcontext TSRMLS_CC);	ZEND_VERIFY_RESOURCE(context);	RETVAL_BOOL(parse_context_params(context, params) == SUCCESS);}/* }}} *//* {{{ proto resource stream_context_create([array options])   Create a file context and optionally set parameters */PHP_FUNCTION(stream_context_create){	zval *params = NULL;	php_stream_context *context;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|a", &params) == FAILURE) {		RETURN_FALSE;	}	context = php_stream_context_alloc();	if (params)		parse_context_options(context, params);	ZEND_REGISTER_RESOURCE(return_value, context, le_stream_context);}/* }}} *//* {{{ streams filter functions */static void apply_filter_to_stream(int append, INTERNAL_FUNCTION_PARAMETERS){	zval *zstream;	php_stream *stream;	char *filtername, *filterparams = NULL;	int filternamelen, filterparamslen = 0;	php_stream_filter *filter;	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs|s", &zstream,				&filtername, &filternamelen, &filterparams, &filterparamslen) == FAILURE) {		RETURN_FALSE;	}	PHP_STREAM_TO_ZVAL(stream, &zstream);	filter = php_stream_filter_create(filtername, filterparams, filterparamslen, php_stream_is_persistent(stream) TSRMLS_CC);	if (filter == NULL)		RETURN_FALSE;	if (append)		php_stream_filter_append(stream, filter);	else		php_stream_filter_prepend(stream, filter);	RETURN_TRUE;}/* {{{ proto bool stream_filter_prepend(resource stream, string filtername[, string filterparams])   Prepend a filter to a stream */PHP_FUNCTION(stream_filter_prepend){	apply_filter_to_stream(0, INTERNAL_FUNCTION_PARAM_PASSTHRU);}/* }}} *//* {{{ proto bool stream_filter_append(resource stream, string filtername[, string filterparams])   Append a filter to a stream */PHP_FUNCTION(stream_filter_append){	apply_filter_to_stream(1, INTERNAL_FUNCTION_PARAM_PASSTHRU);}/* }}} *//* }}} *//* {{{ 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;	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) {		ZEND_FETCH_RESOURCE(context, php_stream_context*, &zcontext, -1, "stream-context", le_stream_context);	}	stream = php_stream_open_wrapper_ex(filename, mode,				(use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS,				NULL, context);	if (stream == NULL)	{		RETURN_FALSE;	}	php_stream_to_zval(stream, return_value);	if (zcontext) {		zend_list_addref(Z_RESVAL_P(zcontext));	}}/* }}} *//* {{{ proto bool fclose(resource fp)   Close an open file pointer */PHPAPI PHP_FUNCTION(fclose){	zval **arg1;	php_stream *stream;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {		WRONG_PARAM_COUNT;	}	PHP_STREAM_TO_ZVAL(stream, arg1);	if (!stream->is_persistent) {		zend_list_delete(stream->rsrc_id);	} else {		php_stream_pclose(stream);	}	RETURN_TRUE;}/* }}} *//* {{{ proto resource popen(string command, string mode)   Execute a command and open either a read or a write pipe to it */PHP_FUNCTION(popen){	zval **arg1, **arg2;	FILE *fp;	char *p, *tmp = NULL;	char *b, *buf = 0;	php_stream *stream;	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_string_ex(arg1);	convert_to_string_ex(arg2);	p = estrndup(Z_STRVAL_PP(arg2), Z_STRLEN_PP(arg2));#ifndef PHP_WIN32	{		char *z = memchr(p, 'b', Z_STRLEN_PP(arg2));		if (z) {			memmove(p + (z - p), z + 1, Z_STRLEN_PP(arg2) - (z - p));		}	}#endif	if (PG(safe_mode)){		b = strchr(Z_STRVAL_PP(arg1), ' ');		if (!b) {			b = strrchr(Z_STRVAL_PP(arg1), '/');		} else {			char *c;			c = Z_STRVAL_PP(arg1);			while((*b != '/') && (b != c)) {				b--;			}			if (b == c) {				b = NULL;			}		}				if (b) {			spprintf(&buf, 0, "%s%s", PG(safe_mode_exec_dir), b);		} else {			spprintf(&buf, 0, "%s/%s", PG(safe_mode_exec_dir), Z_STRVAL_PP(arg1));		}		tmp = php_escape_shell_cmd(buf);		fp = VCWD_POPEN(tmp, p);		efree(tmp);		if (!fp) {			php_error_docref2(NULL TSRMLS_CC, buf, p, E_WARNING, "%s", strerror(errno));			efree(p);			efree(buf);			RETURN_FALSE;		}				efree(buf);	} else {		fp = VCWD_POPEN(Z_STRVAL_PP(arg1), p);		if (!fp) {			php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(arg1), p, E_WARNING, "%s", strerror(errno));			efree(p);			RETURN_FALSE;		}	}	stream = php_stream_fopen_from_pipe(fp, p);	if (stream == NULL)	{		php_error_docref2(NULL TSRMLS_CC, Z_STRVAL_PP(arg1), p, E_WARNING, "%s", strerror(errno));		RETVAL_FALSE;	} else {		php_stream_to_zval(stream, return_value);	}	efree(p);}/* }}} *//* {{{ proto int pclose(resource fp)   Close a file pointer opened by popen() */PHP_FUNCTION(pclose){	zval **arg1;	php_stream *stream;	if (ARG_COUNT(ht) != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {		WRONG_PARAM_COUNT;	}	PHP_STREAM_TO_ZVAL(stream, arg1);	zend_list_delete(stream->rsrc_id);	RETURN_LONG(FG(pclose_ret));}/* }}} *//* {{{ proto bool feof(resource fp)   Test for end-of-file on a file pointer */PHPAPI PHP_FUNCTION(feof){	zval **arg1;	php_stream *stream;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {		WRONG_PARAM_COUNT;	}	PHP_STREAM_TO_ZVAL(stream, arg1);	if (php_stream_eof(stream)) {		RETURN_TRUE;	} else {		RETURN_FALSE;	}}/* }}} *//* {{{ proto bool stream_set_blocking(resource socket, int mode)   Set blocking/non-blocking mode on a socket or stream */PHP_FUNCTION(stream_set_blocking){	zval **arg1, **arg2;	int block;	php_stream *stream;	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &arg1, &arg2) == FAILURE) {		WRONG_PARAM_COUNT;	}	PHP_STREAM_TO_ZVAL(stream, arg1);	convert_to_long_ex(arg2);	block = Z_LVAL_PP(arg2);	if (php_stream_set_option(stream, PHP_STREAM_OPTION_BLOCKING, block == 0 ? 0 : 1, NULL) == -1)		RETURN_FALSE;	RETURN_TRUE;}/* }}} *//* {{{ proto bool set_socket_blocking(resource socket, int mode)   Set blocking/non-blocking mode on a socket */PHP_FUNCTION(set_socket_blocking){	php_error_docref(NULL TSRMLS_CC, E_NOTICE, "This function is deprecated, use stream_set_blocking() instead");	PHP_FN(stream_set_blocking)(INTERNAL_FUNCTION_PARAM_PASSTHRU);}/* }}} *//* {{{ proto bool stream_set_timeout(resource stream, int seconds, int microseconds)   Set timeout on stream read to seconds + microseonds */#if HAVE_SYS_TIME_H || defined(PHP_WIN32)PHP_FUNCTION(stream_set_timeout){	zval **socket, **seconds, **microseconds;	struct timeval t;	php_stream *stream;	if (ZEND_NUM_ARGS() < 2 || ZEND_NUM_ARGS() > 3 ||		zend_get_parameters_ex(ZEND_NUM_ARGS(), &socket, &seconds, &microseconds)==FAILURE) {		WRONG_PARAM_COUNT;	}	PHP_STREAM_TO_ZVAL(stream, socket);	convert_to_long_ex(seconds);	t.tv_sec = Z_LVAL_PP(seconds);	if (ZEND_NUM_ARGS() == 3) {		convert_to_long_ex(microseconds);		t.tv_usec = Z_LVAL_PP(microseconds) % 1000000;		t.tv_sec += Z_LVAL_PP(microseconds) / 1000000;	}	else		t.tv_usec = 0;	if (PHP_STREAM_OPTION_RETURN_OK == php_stream_set_option(stream, PHP_STREAM_OPTION_READ_TIMEOUT, 0, &t)) {		RETURN_TRUE;	}	RETURN_FALSE;}#endif /* HAVE_SYS_TIME_H || defined(PHP_WIN32) *//* }}} *//* {{{ proto string fgets(resource fp[, int length])   Get a line from file pointer */PHPAPI PHP_FUNCTION(fgets){	zval **arg1, **arg2;	int len = 1024;	char *buf = NULL;	int argc = ZEND_NUM_ARGS();	size_t line_len = 0;	php_stream *stream;	if (argc<1 || argc>2 || zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE) {		WRONG_PARAM_COUNT;	}	PHP_STREAM_TO_ZVAL(stream, arg1);	if (argc == 1) {		/* ask streams to give us a buffer of an appropriate size */		buf = php_stream_get_line(stream, NULL, 0, &line_len);		if (buf == NULL)			goto exit_failed;	} else if (argc > 1) {		convert_to_long_ex(arg2);		len = Z_LVAL_PP(arg2);		if (len <= 0) {			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0.");			RETURN_FALSE;		}		buf = ecalloc(len + 1, sizeof(char));		if (php_stream_get_line(stream, buf, len, &line_len) == NULL)			goto exit_failed;	}	if (PG(magic_quotes_runtime)) {		Z_STRVAL_P(return_value) = php_addslashes(buf, line_len, &Z_STRLEN_P(return_value), 1 TSRMLS_CC);		Z_TYPE_P(return_value) = IS_STRING;	} else {		ZVAL_STRINGL(return_value, buf, line_len, 0);		/* resize buffer if it's much larger than the result.		 * Only needed if the user requested a buffer size. */		if (argc > 1 && Z_STRLEN_P(return_value) < len / 2) {			Z_STRVAL_P(return_value) = erealloc(buf, line_len + 1);		}	}	return;exit_failed:	RETVAL_FALSE;	if (buf)		efree(buf);}/* }}} *//* {{{ proto string fgetc(resource fp)   Get a character from file pointer */PHPAPI PHP_FUNCTION(fgetc){	zval **arg1;	char *buf;	int result;	php_stream *stream;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg1) == FAILURE) {		WRONG_PARAM_COUNT;	}	PHP_STREAM_TO_ZVAL(stream, arg1);	buf = emalloc(2 * sizeof(char));	result = php_stream_getc(stream);	if (result == EOF) {		efree(buf);		RETVAL_FALSE;	} else {		buf[0] = result;		buf[1] = '\0';		RETURN_STRINGL(buf, 1, 0);	}}/* }}} *//* {{{ proto string fgetss(resource fp, int length [, string allowable_tags])   Get a line from file pointer and strip HTML tags */PHPAPI PHP_FUNCTION(fgetss){	zval **fd, **bytes, **allow=NULL;	int len;	size_t actual_len, retval_len;	char *buf;	php_stream *stream;	char *allowed_tags=NULL;	int allowed_tags_len=0;	switch(ZEND_NUM_ARGS()) {	case 2:		if (zend_get_parameters_ex(2, &fd, &bytes) == FAILURE) {			RETURN_FALSE;		}		break;	case 3:		if (zend_get_parameters_ex(3, &fd, &bytes, &allow) == FAILURE) {			RETURN_FALSE;		}		convert_to_string_ex(allow);		allowed_tags = Z_STRVAL_PP(allow);		allowed_tags_len = Z_STRLEN_PP(allow);		break;	default:		WRONG_PARAM_COUNT;		/* NOTREACHED */		break;	}	PHP_STREAM_TO_ZVAL(stream, fd);	convert_to_long_ex(bytes);	len = Z_LVAL_PP(bytes);	if (len <= 0) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Length parameter must be greater than 0.");		RETURN_FALSE;	}	buf = safe_emalloc(sizeof(char), (len + 1), 0);	/*needed because recv doesnt set null char at end*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -