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

📄 basic_functions.c

📁 php-4.4.7学习linux时下载的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
		ptr = getenv(str);	}	if (ptr) {		RETURN_STRING(ptr, 1);	}	RETURN_FALSE;}/* }}} */#ifdef HAVE_PUTENV/* {{{ proto bool putenv(string setting)   Set the value of an environment variable */PHP_FUNCTION(putenv){	pval **str;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_string_ex(str);	if (Z_STRVAL_PP(str) && *(Z_STRVAL_PP(str))) {		char *p, **env;		putenv_entry pe;		pe.putenv_string = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));		pe.key = estrndup(Z_STRVAL_PP(str), Z_STRLEN_PP(str));		if ((p = strchr(pe.key, '='))) {	/* nullify the '=' if there is one */			*p = '\0';		}		pe.key_len = strlen(pe.key);		if (PG(safe_mode)) {			/* Check the protected list */			if (zend_hash_exists(&BG(sm_protected_env_vars), pe.key, pe.key_len)) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Safe Mode warning: Cannot override protected environment variable '%s'", pe.key);				efree(pe.putenv_string);				efree(pe.key);				RETURN_FALSE;			}			/* Check the allowed list */			if (BG(sm_allowed_env_vars) && *BG(sm_allowed_env_vars)) {				char *allowed_env_vars = estrdup(BG(sm_allowed_env_vars));				char *allowed_prefix = strtok(allowed_env_vars, ", ");				zend_bool allowed = 0;				while (allowed_prefix) {					if (!strncmp(allowed_prefix, pe.key, strlen(allowed_prefix))) {						allowed = 1;						break;					}					allowed_prefix = strtok(NULL, ", ");				}				efree(allowed_env_vars);				if (!allowed) {					php_error_docref(NULL TSRMLS_CC, E_WARNING, "Safe Mode warning: Cannot set environment variable '%s' - it's not in the allowed list", pe.key);					efree(pe.putenv_string);					efree(pe.key);					RETURN_FALSE;				}			}		}		zend_hash_del(&BG(putenv_ht), pe.key, pe.key_len+1);		/* find previous value */		pe.previous_value = NULL;		for (env = environ; env != NULL && *env != NULL; env++) {			if (!strncmp(*env, pe.key, pe.key_len) && (*env)[pe.key_len] == '=') {	/* found it */				pe.previous_value = *env;				break;			}		}#if _MSC_VER		/* VS.Net has a bug in putenv() when setting a variable that		 * is already set; if the SetEnvironmentVariable() API call		 * fails, the Crt will double free() a string.		 * We try to avoid this by setting our own value first */		SetEnvironmentVariable(pe.key, "bugbug");#endif		if (putenv(pe.putenv_string) == 0) {	/* success */			zend_hash_add(&BG(putenv_ht), pe.key, pe.key_len+1, (void **) &pe, sizeof(putenv_entry), NULL);#ifdef HAVE_TZSET			if (!strncmp(pe.key, "TZ", pe.key_len)) {				tzset();			}#endif			RETURN_TRUE;		} else {			efree(pe.putenv_string);			efree(pe.key);			RETURN_FALSE;		}	}}/* }}} */#endif#ifdef HAVE_GETOPT/* {{{ free_argv   Free the memory allocated to an argv array. */static void free_argv(char **argv, int argc){	int i;	if (argv) {		for (i = 0; i < argc; i++) {			if (argv[i]) {				efree(argv[i]);			}		}		efree(argv);	}}/* }}} */#ifdef HARTMUT_0/* {{{ free_longopts   Free the memory allocated to an longopt array. */static void free_longopts(struct option *longopts){	struct option *p;	if(longopts) {		for(p=longopts; p->name; p++) {			efree((char *)(p->name));		}				efree(longopts);	}}/* }}} */#endif/* {{{ proto array getopt(string options [, array longopts])   Get options from the command line argument list */PHP_FUNCTION(getopt){	char *options = NULL, **argv = NULL;	char opt[2] = { '\0' };	char *optname;	int argc = 0, options_len = 0, o;	zval *val, **args = NULL, *p_longopts = NULL;#ifdef HARTMUT_0	struct option *longopts = NULL;	int longindex = 0;#endif	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|a",							  &options, &options_len, &p_longopts) == FAILURE) {		RETURN_FALSE;	}	/*	 * Get argv from the global symbol table.  We calculate argc ourselves	 * in order to be on the safe side, even though it is also available	 * from the symbol table.	 */	if (zend_hash_find(HASH_OF(PG(http_globals)[TRACK_VARS_SERVER]), "argv", sizeof("argv"), (void **) &args) != FAILURE ||	    zend_hash_find(&EG(symbol_table), "argv", sizeof("argv"), (void **) &args) != FAILURE) {		int pos = 0;		zval **arg;		argc = zend_hash_num_elements(Z_ARRVAL_PP(args));		/* 		 * Attempt to allocate enough memory to hold all of the arguments		 * and a trailing NULL 		 */		if ((argv = (char **) safe_emalloc(sizeof(char *), (argc + 1), 0)) == NULL) {			RETURN_FALSE;		}		/* Reset the array indexes. */		zend_hash_internal_pointer_reset(Z_ARRVAL_PP(args));		/* Iterate over the hash to construct the argv array. */		while (zend_hash_get_current_data(Z_ARRVAL_PP(args),										  (void **)&arg) == SUCCESS) {			argv[pos++] = estrdup(Z_STRVAL_PP(arg));			zend_hash_move_forward(Z_ARRVAL_PP(args));		}		/* 		 * The C Standard requires argv[argc] to be NULL - this might		 * keep some getopt implementations happy. 		 */		argv[argc] = NULL;	} else {		/* Return false if we can't find argv. */		RETURN_FALSE;	}	if(p_longopts) {#ifdef HARTMUT_0		int len, c = zend_hash_num_elements(Z_ARRVAL_P(p_longopts));		struct option *p;		zval **arg;		char *name;		longopts = (struct option *)ecalloc(c+1, sizeof(struct option));		if(!longopts) RETURN_FALSE;		/* Reset the array indexes. */		zend_hash_internal_pointer_reset(Z_ARRVAL_P(p_longopts));		p = longopts;		/* Iterate over the hash to construct the argv array. */		while (zend_hash_get_current_data(Z_ARRVAL_P(p_longopts),										  (void **)&arg) == SUCCESS) {			p->has_arg = 0;			name = estrdup(Z_STRVAL_PP(arg));			len = strlen(name);			if((len > 0) && (name[len-1] == ':')) {				p->has_arg++;				name[len-1] = '\0';				if((len > 1) && (name[len-2] == ':')) {					p->has_arg++;					name[len-2] = '\0';				}			}							p->name = name; 			p->flag = NULL;			p->val = 0;			zend_hash_move_forward(Z_ARRVAL_P(p_longopts));			p++;		}#else		php_error_docref(NULL TSRMLS_CC, E_WARNING, "No support for long options in this build");#endif		}	/* Initialize the return value as an array. */	array_init(return_value);	/* Disable getopt()'s error messages. */	opterr = 0;	/* Force reinitialization of getopt() (via optind reset) on every call. */	optind = 1;	/* Invoke getopt(3) on the argument array. */#ifdef HARTMUT_0	while ((o = getopt_long(argc, argv, options, longopts, &longindex)) != -1) {#else	while ((o = getopt(argc, argv, options)) != -1) {#endif		/* Skip unknown arguments. */		if (o == '?') {			continue;		}		/* Prepare the option character and the argument string. */		if(o == 0) {#ifdef HARTMUT_0			optname = (char *)longopts[longindex].name;#else                      			/* o == 0 shall never happen so this only fixes a compiler warning */			optname = NULL;#endif		} else {					if(o == 1) o = '-';			opt[0] = o;			optname = opt;		}		MAKE_STD_ZVAL(val);		if (optarg != NULL) {			ZVAL_STRING(val, optarg, 1);		} else {			ZVAL_FALSE(val);		}		/* Add this option / argument pair to the result hash. */		if(zend_hash_find(HASH_OF(return_value), optname, strlen(optname)+1, (void **)&args) != FAILURE) {			if(Z_TYPE_PP(args) != IS_ARRAY) {				convert_to_array_ex(args);			}  			zend_hash_next_index_insert(HASH_OF(*args),  (void *)&val, sizeof(zval *), NULL);		} else {			zend_hash_add(HASH_OF(return_value), optname, strlen(optname)+1, (void *)&val,						  sizeof(zval *), NULL);		}	}	free_argv(argv, argc);#ifdef HARTMUT_0	free_longopts(longopts);#endif}/* }}} */#endif/* {{{ proto void flush(void)   Flush the output buffer */PHP_FUNCTION(flush){	sapi_flush(TSRMLS_C);}/* }}} *//* {{{ proto void sleep(int seconds)   Delay for a given number of seconds */PHP_FUNCTION(sleep){	long num;  	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num) == FAILURE) {		RETURN_FALSE;	}	if (num < 0) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of seconds must be greater than or equal to 0");		RETURN_FALSE;	}	php_sleep(num);}/* }}} *//* {{{ proto void usleep(int micro_seconds)   Delay for a given number of micro seconds */PHP_FUNCTION(usleep){#if HAVE_USLEEP	long num;  	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &num) == FAILURE) {		RETURN_FALSE;	}	if (num < 0) {		php_error_docref(NULL TSRMLS_CC, E_WARNING, "Number of microseconds must be greater than or equal to 0");		RETURN_FALSE;	}	usleep(num);#endif}/* }}} *//* {{{ proto string get_current_user(void)   Get the name of the owner of the current PHP script */PHP_FUNCTION(get_current_user){	if (ZEND_NUM_ARGS() != 0) {		WRONG_PARAM_COUNT;	}	RETURN_STRING(php_get_current_user(), 1);}/* }}} *//* {{{ proto string get_cfg_var(string option_name)   Get the value of a PHP configuration option */PHP_FUNCTION(get_cfg_var){	pval **varname;	char *value;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &varname) == FAILURE) {		WRONG_PARAM_COUNT;	}	convert_to_string_ex(varname);	if (cfg_get_string(Z_STRVAL_PP(varname), &value) == FAILURE) {		RETURN_FALSE;	}	RETURN_STRING(value, 1);}/* }}} *//* {{{ proto bool set_magic_quotes_runtime(int new_setting)   Set the current active configuration setting of magic_quotes_runtime and return previous */PHP_FUNCTION(set_magic_quotes_runtime){	pval **new_setting;	if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &new_setting) == FAILURE) {		RETURN_FALSE;	}	convert_to_boolean_ex(new_setting);	PG(magic_quotes_runtime) = (zend_bool) Z_LVAL_PP(new_setting);	RETURN_TRUE;}/* }}} *//* {{{ proto int get_magic_quotes_runtime(void)   Get the current active configuration setting of magic_quotes_runtime */PHP_FUNCTION(get_magic_quotes_runtime){	RETURN_LONG(PG(magic_quotes_runtime));}/* }}} *//* {{{ proto int get_magic_quotes_gpc(void)   Get the current active configuration setting of magic_quotes_gpc */PHP_FUNCTION(get_magic_quotes_gpc){	RETURN_LONG(PG(magic_quotes_gpc));}/* }}} *//*	1st arg = error message	2nd arg = error option	3rd arg = optional parameters (email address or tcp address)	4th arg = used for additional headers if emailerror options:    0 = send to php_error_log (uses syslog or file depending on ini setting)	1 = send via email to 3rd parameter 4th option = additional headers	2 = send via tcp/ip to 3rd parameter (name or ip:port)	3 = save to file in 3rd parameter*//* {{{ proto bool error_log(string message [, int message_type [, string destination [, string extra_headers]]])   Send an error message somewhere */PHP_FUNCTION(error_log){	pval **string, **erropt = NULL, **option = NULL, **emailhead = NULL;	int opt_err = 0;	char *message, *opt = NULL, *headers = NULL;	switch (ZEND_NUM_ARGS()) {		case 1:			if (zend_get_parameters_ex(1, &string) == FAILURE) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Argument 1 invalid");				RETURN_FALSE;			}			break;		case 2:			if (zend_get_parameters_ex(2, &string, &erropt) == FAILURE) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments");				RETURN_FALSE;			}			convert_to_long_ex(erropt);			opt_err = Z_LVAL_PP(erropt);			break;			case 3:			if (zend_get_parameters_ex(3, &string, &erropt, &option) == FAILURE) {				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid arguments");				RETURN_FALSE;

⌨️ 快捷键说明

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