From 7925ff844f31b470f102f28bfdb757ebf3affac6 Mon Sep 17 00:00:00 2001 From: Hiroshi Inoue Date: Wed, 6 Nov 2002 09:44:55 +0000 Subject: [PATCH] 1) Change to use thread-safe functions(xxxx_r) if possible. --- connection.c | 19 +++++++++++++++++++ convert.c | 22 ++++++++++++++++++++++ drvconn.c | 14 ++++++++++++++ info.c | 19 +++++++++++++++++++ socket.c | 9 +++++++-- 5 files changed, 81 insertions(+), 2 deletions(-) diff --git a/connection.c b/connection.c index 6b65e47..1d7c265 100644 --- a/connection.c +++ b/connection.c @@ -1776,6 +1776,9 @@ CC_send_settings(ConnectionClass *self) char status = TRUE; char *cs, *ptr; +#ifdef HAVE_STRTOK_R + char *last; +#endif /* HAVE_STRTOK_R */ static char *func = "CC_send_settings"; @@ -1826,7 +1829,11 @@ CC_send_settings(ConnectionClass *self) if (ci->drivers.conn_settings[0] != '\0') { cs = strdup(ci->drivers.conn_settings); +#ifdef HAVE_STRTOK_R + ptr = strtok_r(cs, ";", &last); +#else ptr = strtok(cs, ";"); +#endif /* HAVE_STRTOK_R */ while (ptr) { result = PGAPI_ExecDirect(hstmt, ptr, SQL_NTS); @@ -1835,7 +1842,11 @@ CC_send_settings(ConnectionClass *self) mylog("%s: result %d, status %d from '%s'\n", func, result, status, ptr); +#ifdef HAVE_STRTOK_R + ptr = strtok_r(NULL, ";", &last); +#else ptr = strtok(NULL, ";"); +#endif /* HAVE_STRTOK_R */ } free(cs); @@ -1845,7 +1856,11 @@ CC_send_settings(ConnectionClass *self) if (ci->conn_settings[0] != '\0') { cs = strdup(ci->conn_settings); +#ifdef HAVE_STRTOK_R + ptr = strtok_r(cs, ";", &last); +#else ptr = strtok(cs, ";"); +#endif /* HAVE_STRTOK_R */ while (ptr) { result = PGAPI_ExecDirect(hstmt, ptr, SQL_NTS); @@ -1854,7 +1869,11 @@ CC_send_settings(ConnectionClass *self) mylog("%s: result %d, status %d from '%s'\n", func, result, status, ptr); +#ifdef HAVE_STRTOK_R + ptr = strtok_r(NULL, ";", &last); +#else ptr = strtok(NULL, ";"); +#endif /* HAVE_STRTOK_R */ } free(cs); diff --git a/convert.c b/convert.c index 1f7e0e6..ffefab1 100644 --- a/convert.c +++ b/convert.c @@ -246,7 +246,11 @@ timestamp2stime(const char *str, SIMPLE_TIME *st, BOOL *bZone, int *zone) if (timediff == 0) /* the same time zone */ return TRUE; time0 -= timediff; +#ifdef HAVE_LOCALTIME_R + if (time0 >= 0 && (tm2 = localtime_r(&time0, &tm)) != NULL) +#else if (time0 >= 0 && (tm2 = localtime(&time0)) != NULL) +#endif /* HAVE_LOCALTIME_R */ { st->y = tm2->tm_year + 1900; st->m = tm2->tm_mon + 1; @@ -346,6 +350,9 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 SIMPLE_TIME st; time_t t = time(NULL); struct tm *tim; +#ifdef HAVE_LOCALTIME_R + struct tm tm; +#endif /* HAVE_LOCALTIME_R */ int pcbValueOffset, rgbValueOffset; char *rgbValueBindRow; @@ -402,7 +409,11 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 memset(&st, 0, sizeof(SIMPLE_TIME)); /* Initialize current date */ +#ifdef HAVE_LOCALTIME_R + tim = localtime_r(&t, &tm); +#else tim = localtime(&t); +#endif /* HAVE_LOCALTIME_R */ st.m = tim->tm_mon + 1; st.d = tim->tm_mday; st.y = tim->tm_year + 1900; @@ -504,7 +515,11 @@ copy_and_convert_field(StatementClass *stmt, Int4 field_type, void *value, Int2 * like the epoch */ t = 0; +#ifdef HAVE_LOCALTIME_R + tim = localtime_r(&t, &tm); +#else tim = localtime(&t); +#endif /* HAVE_LOCALTIME_R */ st.m = tim->tm_mon + 1; st.d = tim->tm_mday; st.y = tim->tm_year + 1900; @@ -2177,6 +2192,9 @@ ResolveOneParam(QueryBuild *qb) SIMPLE_TIME st; time_t t; struct tm *tim; +#ifdef HAVE_LOCALTIME_R + struct tm tm; +#endif /* HAVE_LOCALTIME_R */ SDWORD used; char *buffer, *buf, *allocbuf; Oid lobj_oid; @@ -2279,7 +2297,11 @@ ResolveOneParam(QueryBuild *qb) cbuf[0] = '\0'; memset(&st, 0, sizeof(st)); t = time(NULL); +#ifdef HAVE_LOCALTIME_R + tim = localtime_r(&t, &tm); +#else tim = localtime(&t); +#endif /* HAVE_LOCALTIME_R */ st.m = tim->tm_mon + 1; st.d = tim->tm_mday; st.y = tim->tm_year + 1900; diff --git a/drvconn.c b/drvconn.c index 3dc772f..ae75411 100644 --- a/drvconn.c +++ b/drvconn.c @@ -352,6 +352,9 @@ dconn_get_connect_attributes(const UCHAR FAR * connect_string, ConnInfo *ci) *value, *equals; char *strtok_arg; +#ifdef HAVE_STRTOK_R + char *last; +#endif /* HAVE_STRTOK_R */ CC_conninfo_init(ci); @@ -362,7 +365,11 @@ dconn_get_connect_attributes(const UCHAR FAR * connect_string, ConnInfo *ci) while (1) { +#ifdef HAVE_STRTOK_R + pair = strtok_r(strtok_arg, ";", &last); +#else pair = strtok(strtok_arg, ";"); +#endif /* HAVE_STRTOK_R */ if (strtok_arg) strtok_arg = 0; if (!pair) @@ -398,6 +405,9 @@ dconn_get_common_attributes(const UCHAR FAR * connect_string, ConnInfo *ci) *value, *equals; char *strtok_arg; +#ifdef HAVE_STRTOK_R + char *last; +#endif /* HAVE_STRTOK_R */ our_connect_string = strdup(connect_string); strtok_arg = our_connect_string; @@ -406,7 +416,11 @@ dconn_get_common_attributes(const UCHAR FAR * connect_string, ConnInfo *ci) while (1) { +#ifdef HAVE_STRTOK_R + pair = strtok_r(strtok_arg, ";", &last); +#else pair = strtok(strtok_arg, ";"); +#endif /* HAVE_STRTOK_R */ if (strtok_arg) strtok_arg = 0; if (!pair) diff --git a/info.c b/info.c index f130f9d..56a716f 100644 --- a/info.c +++ b/info.c @@ -1201,6 +1201,9 @@ PGAPI_Tables( char table_name[MAX_INFO_STRING], table_owner[MAX_INFO_STRING], relkind_or_hasrules[MAX_INFO_STRING]; +#ifdef HAVE_STRTOK_R + char *last; +#endif /* HAVE_STRTOK_R */ ConnectionClass *conn; ConnInfo *ci; char *prefix[32], @@ -1268,9 +1271,17 @@ PGAPI_Tables( /* Parse the extra systable prefix */ strcpy(prefixes, ci->drivers.extra_systable_prefixes); i = 0; +#ifdef HAVE_STRTOK_R + prefix[i] = strtok_r(prefixes, ";", &last); +#else prefix[i] = strtok(prefixes, ";"); +#endif /* HAVE_STRTOK_R */ while (prefix[i] && i < sizeof(prefix)) +#ifdef HAVE_STRTOK_R + prefix[++i] = strtok_r(NULL, ";", &last); +#else prefix[++i] = strtok(NULL, ";"); +#endif /* HAVE_STRTOK_R */ /* Parse the desired table types to return */ show_system_tables = FALSE; @@ -1284,9 +1295,17 @@ PGAPI_Tables( strcpy(table_types, tableType); free(tableType); i = 0; +#ifdef HAVE_STRTOK_R + table_type[i] = strtok_r(table_types, ",", &last); +#else table_type[i] = strtok(table_types, ","); +#endif /* HAVE_STRTOK_R */ while (table_type[i] && i < 32) +#ifdef HAVE_STRTOK_R + table_type[++i] = strtok_r(NULL, ",", &last); +#else table_type[++i] = strtok(NULL, ","); +#endif /* HAVE_STRTOK_R */ /* Check for desired table types to return */ i = 0; diff --git a/socket.c b/socket.c index 4f904f7..0b08088 100644 --- a/socket.c +++ b/socket.c @@ -135,9 +135,11 @@ SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname) if (iaddr == INADDR_NONE) { #if defined (POSIX_MULTITHREAD_SUPPORT) - #if defined (PGS_REENTRANT_API_1) // solaris, irix + #if defined (HAVE_GETIPNODEBYNAME) /* Free-BSD ? */ + hp = getipnodebyname(hostname, AF_INET, 0, &error); + #elif defined (PGS_REENTRANT_API_1) /* solaris, irix */ hp = gethostbyname_r(hostname, hp, buf, bufsz, &error); - #elif defined (PGS_REENTRANT_API_2) // linux + #elif defined (PGS_REENTRANT_API_2) /* linux */ int result = 0; result = gethostbyname_r(hostname, hp, buf, bufsz, &hp, &error); if (result) @@ -159,6 +161,9 @@ SOCK_connect_to(SocketClass *self, unsigned short port, char *hostname) else memcpy(&(self->sadr.sin_addr), (struct in_addr *) & iaddr, sizeof(iaddr)); +#if defined (HAVE_GETIPNODEBYNAME) + freehostent(hp); +#endif /* HAVE_GETIPNODEBYNAME */ self->sadr.sin_family = AF_INET; self->sadr.sin_port = htons(port); -- 2.39.5