const char *msg = "<<Unknown>>";
char *supp = NULL;
long native_code = 0;
- char *message = NULL;
+ zend_string *message = NULL;
zval info;
if (dbh == NULL || dbh->error_mode == PDO_ERRMODE_SILENT) {
}
if (supp) {
- spprintf(&message, 0, "SQLSTATE[%s]: %s: %ld %s", *pdo_err, msg, native_code, supp);
+ message = strpprintf(0, "SQLSTATE[%s]: %s: %ld %s", *pdo_err, msg, native_code, supp);
} else {
- spprintf(&message, 0, "SQLSTATE[%s]: %s", *pdo_err, msg);
+ message = strpprintf(0, "SQLSTATE[%s]: %s", *pdo_err, msg);
}
if (dbh->error_mode == PDO_ERRMODE_WARNING) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", message);
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", message->val);
} else if (EG(exception) == NULL) {
zval ex;
zend_class_entry *def_ex = php_pdo_get_exception_base(1 TSRMLS_CC), *pdo_ex = php_pdo_get_exception();
object_init_ex(&ex, pdo_ex);
- zend_update_property_string(def_ex, &ex, "message", sizeof("message") - 1, message TSRMLS_CC);
+ zend_update_property_str(def_ex, &ex, "message", sizeof("message") - 1, message TSRMLS_CC);
zend_update_property_string(def_ex, &ex, "code", sizeof("code") - 1, *pdo_err TSRMLS_CC);
if (!Z_ISUNDEF(info)) {
}
if (message) {
- efree(message);
+ STR_RELEASE(message);
}
if (supp) {
php_fsockopen_stream(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
+
/* {{{ proto resource pfsockopen(string hostname, int port [, int errno [, string errstr [, float timeout]]])
Open persistent Internet or Unix domain socket connection */
PHP_FUNCTION(pfsockopen)
size_t dec_point_len, char *thousand_sep, size_t thousand_sep_len)
{
zend_string *res;
- char *tmpbuf;
+ zend_string *tmpbuf;
char *s, *t; /* source, target */
char *dp;
int integral;
- int tmplen, reslen = 0;
+ int reslen = 0;
int count = 0;
int is_negative=0;
dec = MAX(0, dec);
d = _php_math_round(d, dec, PHP_ROUND_HALF_UP);
- tmplen = spprintf(&tmpbuf, 0, "%.*F", dec, d);
+ tmpbuf = strpprintf(0, "%.*F", dec, d);
if (tmpbuf == NULL) {
return NULL;
- } else if (!isdigit((int)tmpbuf[0])) {
- res = STR_INIT(tmpbuf, tmplen, 0);
- efree(tmpbuf);
- return res;
+ } else if (!isdigit((int)tmpbuf->val[0])) {
+ return tmpbuf;
}
/* find decimal point, if expected */
if (dec) {
- dp = strpbrk(tmpbuf, ".,");
+ dp = strpbrk(tmpbuf->val, ".,");
} else {
dp = NULL;
}
/* calculate the length of the return buffer */
if (dp) {
- integral = dp - tmpbuf;
+ integral = dp - tmpbuf->val;
} else {
/* no decimal point was found */
- integral = tmplen;
+ integral = tmpbuf->len;
}
/* allow for thousand separators */
}
res = STR_ALLOC(reslen, 0);
- s = tmpbuf + tmplen - 1;
+ s = tmpbuf->val + tmpbuf->len - 1;
t = res->val + reslen;
*t-- = '\0';
/* copy the numbers before the decimal point, adding thousand
* separator every three digits */
- while(s >= tmpbuf) {
+ while (s >= tmpbuf->val) {
*t-- = *s--;
- if (thousand_sep && (++count%3)==0 && s>=tmpbuf) {
+ if (thousand_sep && (++count%3)==0 && s>=tmpbuf->val) {
t -= thousand_sep_len;
memcpy(t + 1, thousand_sep, thousand_sep_len);
}
}
res->len = reslen;
- efree(tmpbuf);
+ STR_RELEASE(tmpbuf);
return res;
}
#else
zend_bool more_entropy = 0;
#endif
- char *uniqid;
+ zend_string *uniqid;
int sec, usec, prefix_len = 0;
struct timeval tv;
* digits for usecs.
*/
if (more_entropy) {
- spprintf(&uniqid, 0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
+ uniqid = strpprintf(0, "%s%08x%05x%.8F", prefix, sec, usec, php_combined_lcg(TSRMLS_C) * 10);
} else {
- spprintf(&uniqid, 0, "%s%08x%05x", prefix, sec, usec);
+ uniqid = strpprintf(0, "%s%08x%05x", prefix, sec, usec);
}
- // TODO: avoid reallocation ???
- RETVAL_STRING(uniqid);
- efree(uniqid);
+ RETURN_STR(uniqid);
}
#endif
/* }}} */