From 2f6ded9ac9bb8826eb9b3b79b8cdc018c90aff54 Mon Sep 17 00:00:00 2001 From: Sascha Schumann Date: Fri, 26 Nov 1999 16:51:57 +0000 Subject: [PATCH] Convert more source files to use thread-safe functions --- ext/filepro/filepro.c | 15 ++++++++------- ext/ftp/ftp.c | 4 ++-- ext/hyperwave/hw.c | 19 +++++++++++-------- ext/rpc/com/COM.c | 7 ++++--- sapi/isapi/php4isapi.c | 5 +++-- win32/registry.c | 6 +++--- 6 files changed, 31 insertions(+), 25 deletions(-) diff --git a/ext/filepro/filepro.c b/ext/filepro/filepro.c index 83a63e8f3e..a9b7ec3064 100644 --- a/ext/filepro/filepro.c +++ b/ext/filepro/filepro.c @@ -182,6 +182,7 @@ PHP_FUNCTION(filepro) FILE *fp; char workbuf[256]; /* FIX - should really be the max filename length */ char readbuf[256]; + char *strtok_buf = NULL; int i; FP_FIELD *new_field, *tmp; FP_TLS_VARS; @@ -221,13 +222,13 @@ PHP_FUNCTION(filepro) } /* Get the field count, assume the file is readable! */ - if (strcmp(strtok(readbuf, ":"), "map")) { + if (strcmp(strtok_r(readbuf, ":", &strtok_buf), "map")) { php_error(E_WARNING, "filePro: map file corrupt or encrypted"); RETURN_FALSE; } - FP_GLOBAL(fp_keysize) = atoi(strtok(NULL, ":")); - strtok(NULL, ":"); - FP_GLOBAL(fp_fcount) = atoi(strtok(NULL, ":")); + FP_GLOBAL(fp_keysize) = atoi(strtok_r(NULL, ":", &strtok_buf)); + strtok_r(NULL, ":", &strtok_buf); + FP_GLOBAL(fp_fcount) = atoi(strtok_r(NULL, ":", &strtok_buf)); /* Read in the fields themselves */ for (i = 0; i < FP_GLOBAL(fp_fcount); i++) { @@ -239,9 +240,9 @@ PHP_FUNCTION(filepro) } new_field = emalloc(sizeof(FP_FIELD)); new_field->next = NULL; - new_field->name = estrdup(strtok(readbuf, ":")); - new_field->width = atoi(strtok(NULL, ":")); - new_field->format = estrdup(strtok(NULL, ":")); + new_field->name = estrdup(strtok_r(readbuf, ":", &strtok_buf)); + new_field->width = atoi(strtok_r(NULL, ":", &strtok_buf)); + new_field->format = estrdup(strtok_r(NULL, ":", &strtok_buf)); /* Store in forward-order to save time later */ if (!FP_GLOBAL(fp_fieldlist)) { diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c index 47131efa31..0e39e89cf5 100644 --- a/ext/ftp/ftp.c +++ b/ext/ftp/ftp.c @@ -609,7 +609,7 @@ time_t ftp_mdtm(ftpbuf_t *ftp, const char *path) { time_t stamp; - struct tm *gmt; + struct tm *gmt, tmbuf; struct tm tm; char *ptr; int n; @@ -635,7 +635,7 @@ ftp_mdtm(ftpbuf_t *ftp, const char *path) /* figure out the GMT offset */ stamp = time(NULL); - gmt = gmtime(&stamp); + gmt = gmtime_r(&stamp, &tmbuf); gmt->tm_isdst = -1; /* apply the GMT offset */ diff --git a/ext/hyperwave/hw.c b/ext/hyperwave/hw.c index 87925916c7..be4f3adbb5 100644 --- a/ext/hyperwave/hw.c +++ b/ext/hyperwave/hw.c @@ -285,6 +285,7 @@ int make2_return_array_from_objrec(pval **return_value, char *objrec, zval *sarr char *attrname, *str, *temp, language[3]; int i, count; zval *spec_arr; + char *strtok_buf = NULL; /* Create an array with an entry containing specs for each attribute and fill in the specs for Title, Description, Keyword, Group. @@ -314,7 +315,7 @@ int make2_return_array_from_objrec(pval **return_value, char *objrec, zval *sarr to the return_value array. */ temp = estrdup(objrec); - attrname = strtok(temp, "\n"); + attrname = strtok_r(temp, "\n", &strtok_buf); while(attrname != NULL) { zval *data, **dataptr; long spec; @@ -370,7 +371,7 @@ int make2_return_array_from_objrec(pval **return_value, char *objrec, zval *sarr } } - attrname = strtok(NULL, "\n"); + attrname = strtok_r(NULL, "\n", &strtok_buf); } if(NULL == sarr){ // spec_arr->refcount--; @@ -395,6 +396,7 @@ int make_return_array_from_objrec(pval **return_value, char *objrec) { int hasDescription = 0; int hasKeyword = 0; int hasGroup = 0; + char *strtok_buf; MAKE_STD_ZVAL(title_arr); MAKE_STD_ZVAL(desc_arr); @@ -410,7 +412,7 @@ int make_return_array_from_objrec(pval **return_value, char *objrec) { /* Fill Array of titles, descriptions and keywords */ temp = estrdup(objrec); - attrname = strtok(temp, "\n"); + attrname = strtok_r(temp, "\n", &strtok_buf); while(attrname != NULL) { str = attrname; iTitle = 0; @@ -465,7 +467,7 @@ int make_return_array_from_objrec(pval **return_value, char *objrec) { if(iGroup) add_next_index_string(group_arr, str, 1); } - attrname = strtok(NULL, "\n"); + attrname = strtok_r(NULL, "\n", &strtok_buf); } efree(temp); @@ -504,7 +506,7 @@ int make_return_array_from_objrec(pval **return_value, char *objrec) { /* All other attributes. Make a another copy first */ temp = estrdup(objrec); - attrname = strtok(temp, "\n"); + attrname = strtok_r(temp, "\n", &strtok_buf); while(attrname != NULL) { str = attrname; /* We don't want to insert titles, descr., keywords a second time */ @@ -518,7 +520,7 @@ int make_return_array_from_objrec(pval **return_value, char *objrec) { str++; add_assoc_string(*return_value, attrname, str, 1); } - attrname = strtok(NULL, "\n"); + attrname = strtok_r(NULL, "\n", &strtok_buf); } efree(temp); @@ -1140,6 +1142,7 @@ PHP_FUNCTION(hw_who) { zval *user_arr; char *object, *ptr, *temp, *attrname; int i; + char *strtok_buf; object = php3_hw_command(INTERNAL_FUNCTION_PARAM_PASSTHRU, WHO_COMMAND); if(object == NULL) @@ -1167,7 +1170,7 @@ php_printf("%s\n", ptr); } temp = estrdup(ptr); - attrname = strtok(temp, "\n"); + attrname = strtok_r(temp, "\n", &strtok_buf); i = 0; while(attrname != NULL) { char *name; @@ -1241,7 +1244,7 @@ php_printf("%s\n", ptr); /* Add the user array */ zend_hash_index_update(return_value->value.ht, i++, &user_arr, sizeof(pval), NULL); - attrname = strtok(NULL, "\n"); + attrname = strtok_r(NULL, "\n", &strtok_buf); } efree(temp); efree(object); diff --git a/ext/rpc/com/COM.c b/ext/rpc/com/COM.c index 5bc41c10c8..a818eb1576 100644 --- a/ext/rpc/com/COM.c +++ b/ext/rpc/com/COM.c @@ -150,6 +150,7 @@ static PHP_INI_MH(OnTypelibFileChange) { FILE *typelib_file; char *typelib_name_buffer; + char *strtok_buf = NULL; #if SUPPORT_INTERACTIVE int interactive; ELS_FETCH(); @@ -179,9 +180,9 @@ static PHP_INI_MH(OnTypelibFileChange) if (typelib_name_buffer[0]==';') { continue; } - typelib_name = strtok(typelib_name_buffer, "\r\n"); /* get rid of newlines */ - typelib_name = strtok(typelib_name, "#"); - modifier = strtok(NULL, "#"); + typelib_name = strtok_r(typelib_name_buffer, "\r\n", &strtok_buf); /* get rid of newlines */ + typelib_name = strtok_r(typelib_name, "#", &strtok_buf); + modifier = strtok_r(NULL, "#", &strtok_buf); if (modifier) { if (!strcmp(modifier, "cis") || !strcmp(modifier, "case_insensitive")) { mode &= ~CONST_CS; diff --git a/sapi/isapi/php4isapi.c b/sapi/isapi/php4isapi.c index b352c32a89..a72eacdcf0 100644 --- a/sapi/isapi/php4isapi.c +++ b/sapi/isapi/php4isapi.c @@ -390,6 +390,7 @@ static void hash_isapi_variables(ELS_D SLS_DC) char *variable_buf; DWORD variable_len = ISAPI_SERVER_VAR_BUF_SIZE; char *variable; + char *strtok_buf = NULL; LPEXTENSION_CONTROL_BLOCK lpECB; lpECB = (LPEXTENSION_CONTROL_BLOCK) SG(server_context); @@ -407,7 +408,7 @@ static void hash_isapi_variables(ELS_D SLS_DC) return; } } - variable = strtok(variable_buf, "\r\n"); + variable = strtok_r(variable_buf, "\r\n", &strtok_buf); while (variable) { char *colon = strchr(variable, ':'); @@ -426,7 +427,7 @@ static void hash_isapi_variables(ELS_D SLS_DC) zend_hash_add(&EG(symbol_table), variable, strlen(variable)+1, &entry, sizeof(zval *), NULL); *colon = ':'; } - variable = strtok(NULL, "\r\n"); + variable = strtok_r(NULL, "\r\n", &strtok_buf); } if (variable_buf!=static_variable_buf) { efree(variable_buf); diff --git a/win32/registry.c b/win32/registry.c index ec43b30596..2d098a14a0 100644 --- a/win32/registry.c +++ b/win32/registry.c @@ -6,7 +6,7 @@ void UpdateIniFromRegistry(char *path) { char *p, *orig_path; HKEY MainKey; - + char *strtok_buf = NULL; if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\PHP\\Per Directory Values", 0, KEY_READ, &MainKey)!=ERROR_SUCCESS) { return; @@ -43,7 +43,7 @@ void UpdateIniFromRegistry(char *path) path++; /* step over the first / */ - path = p = strtok(path, "\\/"); + path = p = strtok_r(path, "\\/", &strtok_buf); while (p) { HKEY hKey; @@ -67,7 +67,7 @@ void UpdateIniFromRegistry(char *path) } RegCloseKey(hKey); - p = strtok(NULL, "\\/"); + p = strtok_r(NULL, "\\/", &strtok_buf); } RegCloseKey(MainKey); efree(orig_path); -- 2.40.0