summaryrefslogtreecommitdiff
path: root/ext/standard
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard')
-rw-r--r--ext/standard/base64.c23
-rw-r--r--ext/standard/basic_functions.c3
-rw-r--r--ext/standard/datetime.c61
-rw-r--r--ext/standard/exec.c44
-rw-r--r--ext/standard/fsock.c198
-rw-r--r--ext/standard/head.c11
-rw-r--r--ext/standard/head.h1
-rw-r--r--ext/standard/info.c1
-rw-r--r--ext/standard/string.c54
9 files changed, 169 insertions, 227 deletions
diff --git a/ext/standard/base64.c b/ext/standard/base64.c
index d0a565fde4..70675d14e3 100644
--- a/ext/standard/base64.c
+++ b/ext/standard/base64.c
@@ -71,24 +71,8 @@ unsigned char *_php3_base64_encode(const unsigned char *string, int length, int
unsigned char *_php3_base64_decode(const unsigned char *string, int length, int *ret_length) {
const unsigned char *current = string;
int ch, i = 0, j = 0, k;
- /* this sucks for threaded environments */
- static short reverse_table[256];
- static int table_built;
- unsigned char *result;
-
- if (++table_built == 1) {
- char *chp;
- for(ch = 0; ch < 256; ch++) {
- chp = strchr(base64_table, ch);
- if(chp) {
- reverse_table[ch] = chp - base64_table;
- } else {
- reverse_table[ch] = -1;
- }
- }
- }
- result = (unsigned char *)emalloc((length / 4 * 3 + 1) * sizeof(char));
+ unsigned char *result = (unsigned char *)emalloc((length / 4 * 3 + 1) * sizeof(char));
if (result == NULL) {
return NULL;
}
@@ -96,8 +80,9 @@ unsigned char *_php3_base64_decode(const unsigned char *string, int length, int
/* run through the whole string, converting as we go */
while ((ch = *current++) != '\0') {
if (ch == base64_pad) break;
- ch = reverse_table[ch];
- if (ch < 0) continue;
+ ch = (int)strchr(base64_table, ch);
+ if (ch == 0) continue;
+ ch -= (int)base64_table;
switch(i % 4) {
case 0:
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 3f445804a0..4ff386f0cd 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -284,7 +284,6 @@ function_entry basic_functions[] = {
PHP_FE(print_r, NULL)
{"setcookie", php3_SetCookie, NULL},
{"header", php3_Header, NULL},
- PHP_FE(headers_sent, NULL)
PHP_FE(function_exists, NULL)
PHP_FE(in_array, NULL)
PHP_FE(extract, NULL)
@@ -1414,7 +1413,7 @@ static int _php3_array_walk(const void *a)
pval retval;
CLS_FETCH();
- args[0] = *((pval **)a);
+ args[0] = (pval *)a;
call_user_function(CG(function_table), NULL, php3_array_walk_func_name, &retval, 1, args);
return 0;
diff --git a/ext/standard/datetime.c b/ext/standard/datetime.c
index 99038e0bd5..9be3bc80ae 100644
--- a/ext/standard/datetime.c
+++ b/ext/standard/datetime.c
@@ -60,8 +60,6 @@ static int phpday_tab[2][12] =
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
-#define isleap(year) (((year%4) == 0 && (year%100)!=0) || (year%400)==0)
-
PHP_FUNCTION(time)
{
return_value->value.lval = (long) time(NULL);
@@ -144,7 +142,7 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
pval *format, *timestamp;
time_t the_time;
struct tm *ta;
- int i, size = 0, length, h, beat;
+ int i, size = 0, length, h;
char tmp_buff[16];
switch(ARG_COUNT(ht)) {
@@ -183,45 +181,33 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
break;
case 'F': /* month, textual, full */
case 'l': /* day (of the week), textual */
- case 'T': /* timezone name */
size += 9;
break;
- case 'Z': /* timezone offset in seconds */
- size += 6;
- break;
case 'Y': /* year, numeric, 4 digits */
size += 4;
break;
case 'M': /* month, textual, 3 letters */
case 'D': /* day, textual, 3 letters */
- case 'z': /* day of the year, 1 to 366 */
+ case 'z': /* day of the year */
size += 3;
break;
case 'y': /* year, numeric, 2 digits */
case 'm': /* month, numeric */
- case 'n': /* month, numeric, no leading zeroes */
case 'd': /* day of the month, numeric */
case 'j': /* day of the month, numeric, no leading zeros */
case 'H': /* hour, numeric, 24 hour format */
case 'h': /* hour, numeric, 12 hour format */
- case 'G': /* hour, numeric, 24 hour format, no leading zeroes */
- case 'g': /* hour, numeric, 12 hour format, no leading zeroes */
case 'i': /* minutes, numeric */
case 's': /* seconds, numeric */
case 'A': /* AM/PM */
case 'a': /* am/pm */
case 'S': /* standard english suffix for the day of the month (e.g. 3rd, 2nd, etc) */
- case 't': /* days in current month */
size += 2;
break;
case '\\':
if(i < format->value.str.len-1) {
i++;
}
- case 'L': /* boolean for leap year */
- case 'B': /* Swatch Beat, 3 digits */
- size += 3;
- break;
case 'w': /* day of the week, numeric */
default:
size++;
@@ -275,10 +261,6 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
sprintf(tmp_buff, "%02d", ta->tm_mon + 1); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
break;
- case 'n': /* month, numeric, no leading zeros */
- sprintf(tmp_buff, "%d", ta->tm_mon + 1); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
case 'd': /* day of the month, numeric */
sprintf(tmp_buff, "%02d", ta->tm_mday); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
@@ -296,15 +278,6 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
sprintf(tmp_buff, "%02d", h); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
break;
- case 'G': /* hour, numeric, 24 hour format, no leading zeros */
- sprintf(tmp_buff, "%d", ta->tm_hour); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'g': /* hour, numeric, 12 hour format, no leading zeros */
- h = ta->tm_hour % 12; if (h==0) h = 12;
- sprintf(tmp_buff, "%d", h); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
case 'i': /* minutes, numeric */
sprintf(tmp_buff, "%02d", ta->tm_min); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
@@ -339,40 +312,10 @@ _php3_date(INTERNAL_FUNCTION_PARAMETERS, int gm)
}
}
break;
- case 't': /* days in current month */
- sprintf(tmp_buff, "%2d", phpday_tab[isleap((ta->tm_year+1900))][ta->tm_mon] );
- strcat(return_value->value.str.val, tmp_buff);
- break;
case 'w': /* day of the week, numeric EXTENSION */
sprintf(tmp_buff, "%01d", ta->tm_wday); /* SAFE */
strcat(return_value->value.str.val, tmp_buff);
break;
- case 'Z': /* timezone offset in seconds */
-#if HAVE_TM_GMTOFF
- sprintf(tmp_buff, "%ld", ta->tm_gmtoff );
-#else
- sprintf(tmp_buff, "%ld", timezone);
-#endif
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'L': /* boolean for leapyear */
- sprintf(tmp_buff, "%d", (isleap((ta->tm_year+1900)) ? 1 : 0 ) );
- strcat(return_value->value.str.val, tmp_buff);
- break;
- case 'T': /* timezone name */
-#if HAVE_TM_ZONE
- strcat(return_value->value.str.val, ta->tm_zone);
-#else
- strcat(return_value->value.str.val, tzname[0]);
-#endif
- break;
- case 'B': /* Swatch Beat a.k.a. Internet Time */
- beat = (((((long)the_time)-(((long)the_time) -
- ((((long)the_time) % 86400) + 3600))) * 10) / 864);
- if (beat > 999) beat = 0;
- sprintf(tmp_buff, "%03d", beat); /* SAFE */
- strcat(return_value->value.str.val, tmp_buff);
- break;
default:
length = strlen(return_value->value.str.val);
return_value->value.str.val[length] = format->value.str.val[i];
diff --git a/ext/standard/exec.c b/ext/standard/exec.c
index 87eaddadbf..c1bcb609ed 100644
--- a/ext/standard/exec.c
+++ b/ext/standard/exec.c
@@ -41,20 +41,12 @@
static int _Exec(int type, char *cmd, pval *array, pval *return_value)
{
FILE *fp;
- char *buf, *tmp=NULL;
- int buflen = 0;
+ char buf[EXEC_INPUT_BUF], *tmp=NULL;
int t, l, ret, output=1;
int overflow_limit, lcmd, ldir;
char *b, *c, *d=NULL;
PLS_FETCH();
- buf = (char*) emalloc(EXEC_INPUT_BUF);
- if (!buf) {
- php3_error(E_WARNING, "Unable to emalloc %d bytes for exec buffer", EXEC_INPUT_BUF);
- return -1;
- }
- buflen = EXEC_INPUT_BUF;
-
if (PG(safe_mode)) {
lcmd = strlen(cmd);
ldir = strlen(PG(safe_mode_exec_dir));
@@ -64,7 +56,6 @@ static int _Exec(int type, char *cmd, pval *array, pval *return_value)
if (c) *c = '\0';
if (strstr(cmd, "..")) {
php3_error(E_WARNING, "No '..' components allowed in path");
- efree(buf);
return -1;
}
d = emalloc(l);
@@ -94,7 +85,6 @@ static int _Exec(int type, char *cmd, pval *array, pval *return_value)
if (!fp) {
php3_error(E_WARNING, "Unable to fork [%s]", d);
efree(d);
- efree(buf);
return -1;
}
} else { /* not safe_mode */
@@ -105,7 +95,6 @@ static int _Exec(int type, char *cmd, pval *array, pval *return_value)
#endif
if (!fp) {
php3_error(E_WARNING, "Unable to fork [%s]", cmd);
- efree(buf);
return -1;
}
}
@@ -117,33 +106,7 @@ static int _Exec(int type, char *cmd, pval *array, pval *return_value)
}
}
if (type != 3) {
- l=0;
- while ( !feof(fp) || l != 0 ) {
- l = 0;
- /* Read a line or fill the buffer, whichever comes first */
- do {
- if ( buflen <= (l+1) ) {
- buf = erealloc(buf, buflen + EXEC_INPUT_BUF);
- if ( buf == NULL ) {
- php3_error(E_WARNING, "Unable to erealloc %d bytes for exec buffer",
- buflen + EXEC_INPUT_BUF);
- return -1;
- }
- buflen += EXEC_INPUT_BUF;
- }
-
- if ( fgets(&(buf[l]), buflen - l, fp) == NULL ) {
- /* eof */
- break;
- }
- l += strlen(&(buf[l]));
- } while ( (l > 0) && (buf[l-1] != '\n') );
-
- if ( feof(fp) && (l == 0) ) {
- break;
- }
-
-
+ while (fgets(buf, EXEC_INPUT_BUF - 1, fp)) {
if (type == 1) {
SLS_FETCH();
@@ -169,7 +132,7 @@ static int _Exec(int type, char *cmd, pval *array, pval *return_value)
/* strip trailing whitespaces */
l = strlen(buf);
t = l;
- while (l-- && isspace((int)buf[l]));
+ while (l && isspace((int)buf[--l]));
if (l < t) {
buf[l + 1] = '\0';
}
@@ -210,7 +173,6 @@ static int _Exec(int type, char *cmd, pval *array, pval *return_value)
#endif
if (d) efree(d);
- efree(buf);
return ret;
}
diff --git a/ext/standard/fsock.c b/ext/standard/fsock.c
index cc000f42b4..ab19214dec 100644
--- a/ext/standard/fsock.c
+++ b/ext/standard/fsock.c
@@ -20,7 +20,6 @@
/* $Id$ */
/* Synced with php3 revision 1.121 1999-06-18 [ssb] */
-/* Synced with php3 revision 1.133 1999-07-21 [sas] */
#include "php.h"
#include "php_globals.h"
@@ -71,9 +70,6 @@ extern int le_fp;
#define FREE_SOCK if(socketd >= 0) close(socketd); efree(sock); if (key) efree(key)
-#define SEARCHCR \
- p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen - 1));
-
#if WIN32|WINNT
#define EWOULDBLOCK WSAEWOULDBLOCK
#else
@@ -237,7 +233,6 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
int socketd = -1;
struct timeval timeout = { 60, 0 };
unsigned short portno;
- unsigned long conv;
char *key = NULL;
PLS_FETCH();
@@ -247,10 +242,8 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
}
switch(arg_count) {
case 5:
- convert_to_double(args[4]);
- conv = args[4]->value.dval * 1000000.0;
- timeout.tv_sec = conv / 1000000;
- timeout.tv_usec = conv % 1000000;
+ convert_to_long(args[4]);
+ timeout.tv_sec = args[4]->value.lval;
/* fall-through */
case 4:
if(!ParameterPassedByReference(ht,4)) {
@@ -278,7 +271,7 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
if (persistent && _php3_hash_find(&PG(ht_fsock_keys), key, strlen(key) + 1,
(void *) &sockp) == SUCCESS) {
- FREE_SOCK;
+ efree(key);
*sock = *sockp;
RETURN_LONG(php3_list_insert(sock, wsa_fp));
}
@@ -362,14 +355,14 @@ static void _php3_fsockopen(INTERNAL_FUNCTION_PARAMETERS, int persistent) {
}
/* }}} */
-/* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr [, double timeout]]])
+/* {{{ proto int fsockopen(string hostname, int port [, int errno [, string errstr]])
Open Internet or Unix domain socket connection */
PHP_FUNCTION(fsockopen)
{
_php3_fsockopen(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
}
/* }}} */
-/* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr [, double timeout]]])
+/* {{{ proto int pfsockopen(string hostname, int port [, int errno [, string errstr]])
Open persistent Internet or Unix domain socket connection */
PHP_FUNCTION(pfsockopen)
{
@@ -377,7 +370,40 @@ PHP_FUNCTION(pfsockopen)
}
/* }}} */
-#define CHUNK_SIZE 8192
+/* Known issues with the socket buffering code:
+ * - does not work reliably with persistent sockets yet
+ * (buffered data is not persistent)
+ * - php3_fopen_url_wrapper() is still doing single-byte lookahead/read
+ */
+
+static php3i_sockbuf *_php3_sock_findsock(int socket)
+{
+ /* FIXME: O(n) could be improved */
+
+ php3i_sockbuf *buf = NULL, *tmp;
+
+ for(tmp = phpsockbuf; tmp; tmp = tmp->next)
+ if(tmp->socket == socket) {
+ buf = tmp;
+ break;
+ }
+
+ return buf;
+}
+
+int _php3_sock_eof(int socket)
+{
+ php3i_sockbuf *sockbuf;
+ int ret = 0;
+
+ sockbuf = _php3_sock_findsock(socket);
+ if(sockbuf) {
+ ret = (sockbuf->writepos - sockbuf->readpos) == 0 ? 1 : 0;
+ }
+ return ret;
+}
+
+#define CHUNK_SIZE 2048
#define SOCK_DESTROY(sock) \
if(sock->readbuf) pefree(sock->readbuf, sock->persistent); \
if(sock->prev) sock->prev->next = sock->next; \
@@ -412,12 +438,12 @@ static php3i_sockbuf *_php3_sock_find(int socket)
{
php3i_sockbuf *buf = NULL, *tmp;
- for(tmp = phpsockbuf; tmp; tmp = tmp->next)
- if(tmp->socket == socket) {
+ for (tmp = phpsockbuf; tmp; tmp = tmp->next) {
+ if (tmp->socket == socket) {
buf = tmp;
break;
}
-
+ }
return buf;
}
@@ -428,8 +454,9 @@ static php3i_sockbuf *_php3_sock_create(int socket)
sock = pecalloc(sizeof(*sock), 1, persistent);
sock->socket = socket;
- if((sock->next = phpsockbuf))
+ if ((sock->next = phpsockbuf)) {
phpsockbuf->prev = sock;
+ }
sock->persistent = persistent;
sock->is_blocked = 1;
sock->chunk_size = def_chunk_size;
@@ -444,8 +471,9 @@ size_t _php3_sock_set_def_chunk_size(size_t size)
old = def_chunk_size;
- if(size <= CHUNK_SIZE || size > 0)
+ if (size <= CHUNK_SIZE || size > 0) {
def_chunk_size = size;
+ }
return old;
}
@@ -456,7 +484,7 @@ int _php3_sock_destroy(int socket)
php3i_sockbuf *sock;
sock = _php3_sock_find(socket);
- if(sock) {
+ if (sock) {
ret = 1;
SOCK_DESTROY(sock);
}
@@ -464,31 +492,24 @@ int _php3_sock_destroy(int socket)
return ret;
}
-#if !defined(WIN32) && !defined(WINNT)
-#undef closesocket
-#define closesocket close
-#endif
-
-#ifndef HAVE_SHUTDOWN
-#undef shutdown
-#define shutdown
-#endif
-
-#define SOCK_CLOSE(s) shutdown(s, 0); closesocket(s)
-
int _php3_sock_close(int socket)
{
int ret = 0;
php3i_sockbuf *sock;
sock = _php3_sock_find(socket);
- if(sock) {
- if(!sock->persistent) {
- SOCK_CLOSE(sock->socket);
+ if (sock) {
+ if (!sock->persistent) {
+#if HAVE_SHUTDOWN
+ shutdown(sock->socket, 0);
+#endif
+#if WIN32||WINNT
+ closesocket(sock->socket);
+#else
+ close(sock->socket);
+#endif
SOCK_DESTROY(sock);
}
- } else {
- SOCK_CLOSE(socket);
}
return ret;
@@ -503,64 +524,52 @@ static void _php3_sock_wait_for_data(php3i_sockbuf *sock)
FD_ZERO(&fdr);
FD_SET(sock->socket, &fdr);
- while(1) {
+ while (1) {
tfdr = fdr;
- if(select(sock->socket + 1, &tfdr, NULL, NULL, NULL) == 1)
+ if(select(sock->socket + 1, &tfdr, NULL, NULL, NULL) == 1) {
break;
+ }
}
}
-static size_t _php3_sock_read_internal(php3i_sockbuf *sock)
+static size_t _php3_sock_read_limited(php3i_sockbuf *sock, int maxread)
{
char buf[CHUNK_SIZE];
int nr_bytes;
size_t nr_read = 0;
-
- /* For blocking sockets, we wait until there is some
- data to read (real data or EOF)
-
- Otherwise, recv() may time out and return 0 and
- therefore sock->eof would be set errornously.
- */
-
- if(sock->is_blocked) {
+ if (sock->eof || TOREAD(sock) >= maxread) {
+ return 0;
+ }
+ if (sock->is_blocked) {
_php3_sock_wait_for_data(sock);
}
- /* read at a maximum sock->chunk_size */
nr_bytes = recv(sock->socket, buf, sock->chunk_size, 0);
- if(nr_bytes > 0) {
- if(sock->writepos + nr_bytes > sock->readbuflen) {
+ if (nr_bytes > 0) {
+ if (sock->writepos + nr_bytes > sock->readbuflen) {
sock->readbuflen += sock->chunk_size;
sock->readbuf = perealloc(sock->readbuf, sock->readbuflen,
- sock->persistent);
+ sock->persistent);
}
memcpy(WRITEPTR(sock), buf, nr_bytes);
sock->writepos += nr_bytes;
nr_read = nr_bytes;
- } else if(nr_bytes == 0 || (nr_bytes < 0 && errno != EWOULDBLOCK)) {
+ } else if (nr_bytes == 0 || (nr_bytes < 0 && errno != EWOULDBLOCK)) {
sock->eof = 1;
}
return nr_read;
}
-static void _php3_sock_read_total(php3i_sockbuf *sock, size_t maxread)
-{
- while(!sock->eof && TOREAD(sock) < maxread) {
- _php3_sock_read_internal(sock);
- }
-}
-
static size_t _php3_sock_read(php3i_sockbuf *sock)
{
size_t nr_bytes;
size_t nr_read = 0;
int i;
-
- for(i = 0; !sock->eof && i < MAX_CHUNKS_PER_READ; i++) {
- nr_bytes = _php3_sock_read_internal(sock);
+
+ for (i = 0; !sock->eof && i < MAX_CHUNKS_PER_READ; i++) {
+ nr_bytes = _php3_sock_read_limited(sock, CHUNK_SIZE);
if(nr_bytes == 0) break;
nr_read += nr_bytes;
}
@@ -574,60 +583,64 @@ int _php3_sock_set_blocking(int socket, int mode)
SOCK_FIND(sock, socket);
old = sock->is_blocked;
-
+
sock->is_blocked = mode;
-
+
return old;
}
#define SOCK_FIND_AND_READ_MAX(max) \
- SOCK_FIND(sock, socket); \
- if(sock->is_blocked) _php3_sock_read_total(sock, max); else _php3_sock_read(sock)
+ SOCK_FIND(sock, socket); \
+ if(sock->is_blocked) _php3_sock_read_limited(sock, max); else _php3_sock_read(sock)
/* {{{ _php3_sock_fgets() */
/*
- * FIXME: fgets depends on '\n' as line delimiter
+ * FIXME: fgets depends on '\n' as line delimiters
*/
char *_php3_sock_fgets(char *buf, size_t maxlen, int socket)
{
char *p = NULL;
char *ret = NULL;
size_t amount = 0;
+ size_t nr_read;
+ size_t nr_toread;
SOCK_FIND(sock, socket);
- SEARCHCR;
+ if (maxlen < 0) {
+ return ret;
+ }
- if(!p) {
- if(sock->is_blocked) {
- while(!p && !sock->eof && TOREAD(sock) < maxlen - 1) {
- _php3_sock_read_internal(sock);
- SEARCHCR;
+ if (sock->is_blocked) {
+ nr_toread = 0;
+ for (nr_read = 1; !sock->eof && nr_read < maxlen; ) {
+ nr_read += _php3_sock_read_limited(sock, nr_toread);
+ if ((p = memchr(READPTR(sock), '\n', TOREAD(sock))) != NULL) {
+ break;
}
- } else {
- _php3_sock_read(sock);
- SEARCHCR;
+ nr_toread = 512;
}
+ } else {
+ _php3_sock_read(sock);
+ p = memchr(READPTR(sock), '\n', MIN(TOREAD(sock), maxlen - 1));
}
-
- if(p) {
+ if (p) {
amount = (ptrdiff_t) p - (ptrdiff_t) READPTR(sock) + 1;
} else {
- amount = TOREAD(sock);
+ amount = MIN(TOREAD(sock), maxlen - 1);
}
-
- amount = MIN(amount, maxlen - 1);
- if(amount > 0) {
+ if (amount > 0) {
memcpy(buf, READPTR(sock), amount);
sock->readpos += amount;
}
buf[amount] = '\0';
-
- /* signal error only, if we don't return data from this call and
+
+ /* signal error only, if we don't return data from this call and
if there is no data to read and if the eof flag is set */
- if(amount || TOREAD(sock) || !sock->eof)
+ if (amount || TOREAD(sock) || !sock->eof) {
ret = buf;
+ }
return ret;
}
@@ -646,7 +659,7 @@ int _php3_sock_fgetc(int socket)
int ret = EOF;
SOCK_FIND_AND_READ_MAX(1);
- if(TOREAD(sock) > 0) {
+ if (TOREAD(sock) > 0) {
ret = *READPTR(sock);
sock->readpos++;
}
@@ -659,11 +672,9 @@ int _php3_sock_feof(int socket)
int ret = 0;
SOCK_FIND(sock, socket);
- if(!sock->is_blocked)
- _php3_sock_read(sock);
-
- if(!TOREAD(sock) && sock->eof)
+ if (!TOREAD(sock) && sock->eof) {
ret = 1;
+ }
return ret;
}
@@ -675,11 +686,12 @@ size_t _php3_sock_fread(char *ptr, size_t size, int socket)
size_t ret = 0;
SOCK_FIND_AND_READ_MAX(size);
- if(size < 0)
+ if (size < 0) {
return ret;
+ }
ret = MIN(TOREAD(sock), size);
- if(ret) {
+ if (ret) {
memcpy(ptr, READPTR(sock), ret);
sock->readpos += ret;
}
diff --git a/ext/standard/head.c b/ext/standard/head.c
index cfc6930f7d..f1bd0dcdc8 100644
--- a/ext/standard/head.c
+++ b/ext/standard/head.c
@@ -24,7 +24,6 @@
#include "main.h"
#include "head.h"
#include "post.h"
-#include "SAPI.h"
#ifdef TM_IN_SYS_TIME
#include <sys/time.h>
#else
@@ -557,16 +556,6 @@ int php3_headers_unsent(void)
}
}
-PHP_FUNCTION(headers_sent)
-{
- SLS_FETCH();
-
- if (SG(headers_sent)) {
- RETURN_TRUE;
- } else {
- RETURN_FALSE;
- }
-}
function_entry php3_header_functions[] = {
{NULL, NULL, NULL}
diff --git a/ext/standard/head.h b/ext/standard/head.h
index a8096ecaca..977fc83345 100644
--- a/ext/standard/head.h
+++ b/ext/standard/head.h
@@ -55,7 +55,6 @@ extern php3_module_entry php3_header_module_entry;
extern int php3_init_head(INIT_FUNC_ARGS);
PHP_FUNCTION(Header);
PHP_FUNCTION(SetCookie);
-PHP_FUNCTION(headers_sent);
void php4i_add_header_information(char *header_information, uint header_length);
diff --git a/ext/standard/info.c b/ext/standard/info.c
index eb87281301..fe4e55120e 100644
--- a/ext/standard/info.c
+++ b/ext/standard/info.c
@@ -310,7 +310,6 @@ void php_print_credits(int flag)
CREDIT_LINE("Sybase", "Zeev Suraski");
CREDIT_LINE("System V Shared Memory", "Christian Cartus");
CREDIT_LINE("System V Semaphores", "Tom May");
- CREDIT_LINE("WDDX", "Andrey Zmievski");
CREDIT_LINE("XML", "Stig Bakken");
CREDIT_LINE("Yellow Pages", "Stephanie Wehner");
CREDIT_LINE("Zlib", "Rasmus Lerdorf, Stefan Ruhrich");
diff --git a/ext/standard/string.c b/ext/standard/string.c
index 1836e2a4d6..e645cda6f6 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -1344,6 +1344,11 @@ PHPAPI void _php3_char_to_str(char *str,uint len,char from,char *to,int to_len,p
*target = 0;
}
+#if 0
+/*
+ * this is a binary safe equivalent to strnstr
+ * note that we don't check for the end in str_to_str but here
+ */
static inline char *
_php3_memnstr(char *haystack, char *needle, int needle_len, char *end)
@@ -1409,6 +1414,55 @@ finish:
return new;
}
+#else
+
+static char *_php3_memstr(char *s, char *c, size_t n, size_t m)
+{
+ char *p;
+
+ for(p = s; (p - s) < n; p++)
+ if(memcmp(p, c, m) == 0)
+ return p;
+ return NULL;
+}
+
+#define ATTCHSTR(st, sz) \
+ nl += sz; \
+ n = erealloc(n, nl + 1); \
+ memcpy(n + no, st, sz); \
+ no += sz
+
+
+PHPAPI char *_php3_str_to_str(char *a, int al, char *b, int bl, char *c, int cl,
+ int *newlen)
+{
+ char *n = NULL, *p, *q;
+ int nl = 0;
+ int no = 0;
+
+ /* run through all occurences of b in a */
+ for(p = q = a; (p = _php3_memstr(p, b, al - (p - a), bl)); q = p) {
+ /* attach everything between the previous occ. and this one */
+ ATTCHSTR(q, p - q);
+ /* attach the replacement string c */
+ ATTCHSTR(c, cl);
+ /* jump over string b in a */
+ p += bl;
+ }
+
+ /* anything left over ? */
+ if((al - (q - a)) > 0) {
+ ATTCHSTR(q, al - (q - a));
+ }
+
+ if(newlen) *newlen = nl;
+ n[nl] = '\0';
+
+ return n;
+}
+
+#undef ATTCHSTR
+#endif
/* {{{ proto string str_replace(string needle, string str, string haystack)
Replace all occurrences of needle in haystack with str */