]> granicus.if.org Git - php/commitdiff
Conver to use new parameter parsing API.
authorAndrei Zmievski <andrei@php.net>
Fri, 19 Oct 2001 18:26:30 +0000 (18:26 +0000)
committerAndrei Zmievski <andrei@php.net>
Fri, 19 Oct 2001 18:26:30 +0000 (18:26 +0000)
ext/standard/syslog.c
ext/standard/uniqid.c

index d3e05fa5e9595ee9ceff11b1735e8cff030cd088..bd15b99c9d51db035cbe9500d9c6628910482edd 100644 (file)
@@ -191,6 +191,12 @@ static void start_syslog(TSRMLS_D)
    Initializes all syslog-related variables */
 PHP_FUNCTION(define_syslog_variables)
 {
+       if (ZEND_NUM_ARGS() != 0) {
+               php_error(E_WARNING, "%s() expects no parameters, %d given",
+                                 get_active_function_name(TSRMLS_C), ZEND_NUM_ARGS());
+               return;
+       }
+
        if (!BG(syslog_started)) {
                start_syslog(TSRMLS_C);
        }
@@ -206,19 +212,19 @@ PHP_FUNCTION(define_syslog_variables)
  */
 PHP_FUNCTION(openlog)
 {
-       pval **ident, **option, **facility;
+       char *ident;
+       long option, facility;
+       int ident_len;
 
-       if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &ident, &option, &facility) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sll", &ident, &option,
+                                                         &facility) == FAILURE) {
+               return;
        }
-       convert_to_string_ex(ident);
-       convert_to_long_ex(option);
-       convert_to_long_ex(facility);
        if (BG(syslog_device)) {
                efree(BG(syslog_device));
        }
-       BG(syslog_device) = estrndup(Z_STRVAL_PP(ident), Z_STRLEN_PP(ident));
-       openlog(BG(syslog_device), Z_LVAL_PP(option), Z_LVAL_PP(facility));
+       BG(syslog_device) = estrndup(ident, ident_len);
+       openlog(BG(syslog_device), option, facility);
        RETURN_TRUE;
 }
 /* }}} */
@@ -227,6 +233,12 @@ PHP_FUNCTION(openlog)
    Close connection to system logger */
 PHP_FUNCTION(closelog)
 {
+       if (ZEND_NUM_ARGS() != 0) {
+               php_error(E_WARNING, "%s() expects no parameters, %d given",
+                                 get_active_function_name(TSRMLS_C), ZEND_NUM_ARGS());
+               return;
+       }
+
        closelog();
        if (BG(syslog_device)) {
                efree(BG(syslog_device));
@@ -240,20 +252,21 @@ PHP_FUNCTION(closelog)
    Generate a system log message */
 PHP_FUNCTION(syslog)
 {
-       pval **priority, **message;
+       long priority;
+       char *message;
+       int message_len;
 
-       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &priority, &message) == FAILURE) {
-               WRONG_PARAM_COUNT;
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ls", &priority,
+                                                         &message, &message_len) == FAILURE) {
+               return;
        }
-       convert_to_long_ex(priority);
-       convert_to_string_ex(message);
 
        /*
         * CAVEAT: if the message contains patterns such as "%s",
         * this will cause problems.
         */
 
-       php_syslog(Z_LVAL_PP(priority), "%.500s", Z_STRVAL_PP(message));
+       php_syslog(priority, "%.500s", message);
        RETURN_TRUE;
 }
 /* }}} */
index 20f8973d634c0788b44c54fcabbdc578ca097bec..9356ed134b49e2461f1c17227ecf2c23fed5eed4 100644 (file)
 #include "php_lcg.h"
 #include "uniqid.h"
 
-#define MORE_ENTROPY (argc == 2 && Z_LVAL_PP(flags))
-
 /* {{{ proto string uniqid(string prefix, [bool more_entropy])
    Generate a unique id */
 PHP_FUNCTION(uniqid)
 {
 #ifdef HAVE_GETTIMEOFDAY
-       pval **prefix, **flags;
+       char *prefix;
+       zend_bool more_entropy = 0;
        char uniqid[138];
-       int sec, usec, argc;
+       int sec, usec, argc, prefix_len;
        struct timeval tv;
 
        argc = ZEND_NUM_ARGS();
-       if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &prefix, &flags)) {
-               WRONG_PARAM_COUNT;
-       }
-       convert_to_string_ex(prefix);
-       if (argc == 2) {
-               convert_to_boolean_ex(flags);
+       if (zend_parse_parameters(argc TSRMLS_CC, "s|b", &prefix, &prefix_len,
+                                                         &more_entropy)) {
+               return;
        }
 
        /* Do some bounds checking since we are using a char array. */
-       if (Z_STRLEN_PP(prefix) > 114) {
+       if (prefix_len > 114) {
                php_error(E_WARNING, "The prefix to uniqid should not be more than 114 characters.");
                return;
        }
 #if HAVE_USLEEP && !defined(PHP_WIN32)
-       if (!MORE_ENTROPY) {
+       if (!more_entropy) {
                usleep(1);
        }
 #endif
@@ -76,10 +72,10 @@ PHP_FUNCTION(uniqid)
        /* The max value usec can have is 0xF423F, so we use only five hex
         * digits for usecs.
         */
-       if (MORE_ENTROPY) {
-               sprintf(uniqid, "%s%08x%05x%.8f", Z_STRVAL_PP(prefix), sec, usec, php_combined_lcg(TSRMLS_C) * 10);
+       if (more_entropy) {
+               sprintf(uniqid, "%s%08x%05x%.8f", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
        } else {
-               sprintf(uniqid, "%s%08x%05x", Z_STRVAL_PP(prefix), sec, usec);
+               sprintf(uniqid, "%s%08x%05x", prefix, sec, usec);
        }
 
        RETURN_STRING(uniqid, 1);