CVS update: php3/functions

From: Date: Fri, 25 Jun 1999 22:53:23 +0000
Subject: CVS update: php3/functions
Groups: php.dev 
Request: Send a blank email to php-dev+get-7566@lists.php.net to get a copy of this message
Date: Friday June 25, 1999 @ 18:53 Author: sas Update of /repository/php3/functions In directory php:/tmp/cvs-serv8777/functions Modified Files: basic_functions.c basic_functions.h Log Message: basic alarm functionality. Index: php3/functions/basic_functions.c diff -u php3/functions/basic_functions.c:1.267 php3/functions/basic_functions.c:1.268 --- php3/functions/basic_functions.c:1.267 Sun Jun 20 13:40:05 1999 +++ php3/functions/basic_functions.c Fri Jun 25 18:53:23 1999 @@ -28,7 +28,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: basic_functions.c,v 1.267 1999/06/20 17:40:05 jim Exp $ */ +/* $Id: basic_functions.c,v 1.268 1999/06/25 22:53:23 sas Exp $ */ #ifdef THREAD_SAFE #include "tls.h" #endif @@ -47,7 +47,7 @@ #ifdef HAVE_UNISTD_H # include <unistd.h> #endif -#if HAVE_STRING_H +#ifdef HAVE_STRING_H #include <string.h> #else #include <strings.h> @@ -59,6 +59,11 @@ #include <netdb.h> #include <arpa/inet.h> #endif + +#ifdef HAVE_SIGNAL_H +#include <signal.h> +#endif + #include "safe_mode.h" #include "functions/basic_functions.h" #include "functions/phpmath.h" @@ -95,6 +100,9 @@ static pval *user_compare_func_name; static HashTable *user_shutdown_function_names; +typedef void (*php_sighandler_t)(int); +static php_sighandler_t old_alrm_handler; + /* some prototypes for local functions */ void user_shutdown_function_dtor(pval *user_shutdown_function_name); int user_shutdown_function_executor(pval *user_shutdown_function_name); @@ -328,6 +336,7 @@ PHP_FE(extract, NULL) PHP_FE(function_exists, NULL) + PHP_FE(alarm, NULL) {NULL, NULL, NULL} }; @@ -606,6 +615,40 @@ } RETVAL_LONG(old_error_reporting); +} +/* }}} */ + +static void _php_alrm_handler(int i) +{ + signal(SIGALRM, old_alrm_handler); + old_alrm_handler = NULL; +} + +/* {{{ proto int alarm(int seconds) + user-level alarm() call. Returns remaining seconds */ +PHP_FUNCTION(alarm) +{ + pval *value; + unsigned int remaining = 0; + + if(ARG_COUNT(ht) != 1 || getParameters(ht, 1, &value) == FAILURE) { + WRONG_PARAM_COUNT; + } + + convert_to_long(value); + + if(value->value.lval == 0 && old_alrm_handler != NULL) { + /* deinstall our handler */ + signal(SIGALRM, old_alrm_handler); + old_alrm_handler = NULL; + } else if(value->value.lval > 0 && old_alrm_handler == NULL) { + /* install our handler, if not already installed */ + old_alrm_handler = signal(SIGALRM, _php_alrm_handler); + } + + remaining = alarm(value->value.lval); + + RETURN_LONG(remaining); } /* }}} */ Index: php3/functions/basic_functions.h diff -u php3/functions/basic_functions.h:1.42 php3/functions/basic_functions.h:1.43 --- php3/functions/basic_functions.h:1.42 Sun May 16 14:55:08 1999 +++ php3/functions/basic_functions.h Fri Jun 25 18:53:23 1999 @@ -29,7 +29,7 @@ */ -/* $Id: basic_functions.h,v 1.42 1999/05/16 18:55:08 jim Exp $ */ +/* $Id: basic_functions.h,v 1.43 1999/06/25 22:53:23 sas Exp $ */ #ifndef _BASIC_FUNCTIONS_H #define _BASIC_FUNCTIONS_H @@ -106,6 +106,7 @@ extern PHP_FUNCTION(extract); PHP_FUNCTION(register_shutdown_function); +PHP_FUNCTION(alarm); #if HAVE_PUTENV typedef struct {

« previous php.dev (#7566) next »