Skip to content

Commit 84ff5b5

Browse files
author
Michael Meskes
committed
In ecpglib rewrote code that used strtok_r to not use library functions
anymore. This way we don't have to worry which compiler on which OS offers which version of strtok.
1 parent 759c95c commit 84ff5b5

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/interfaces/ecpg/ecpglib/connect.c

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
#include "extern.h"
1111
#include "sqlca.h"
1212

13-
#ifdef WIN32_ONLY_COMPILER
14-
#define strtok_r(s,d,p) strtok_s(s,d,p)
15-
#endif
16-
1713
#ifdef ENABLE_THREAD_SAFETY
1814
static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
1915
static pthread_key_t actual_connection_key;
@@ -560,25 +556,37 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
560556
}
561557
if (options)
562558
{
563-
char *saveptr, *token1, *token2, *str;
559+
char *str;
564560

565561
/* options look like this "option1 = value1 option2 = value2 ... */
566562
/* we have to break up the string into single options */
567-
for (str = options; ; str = NULL)
563+
for (str = options; *str;)
568564
{
569-
token1 = strtok_r(str, "=", &saveptr);
570-
if (token1 == NULL)
571-
break;
572-
/* strip leading blanks */
573-
for (; *token1 && *token1 == ' '; token1++);
565+
int e, a;
566+
char *token1, *token2;
574567

575-
token2 = strtok_r(NULL, "&", &saveptr);
576-
if (token2 == NULL)
577-
break;
568+
for (token1 = str; *token1 && *token1 == ' '; token1++);
569+
for (e = 0; token1[e] && token1[e] != '='; e++);
570+
if (token1[e]) /* found "=" */
571+
{
572+
token1[e] = '\0';
573+
for (token2 = token1 + e + 1; *token2 && *token2 == ' '; token2++);
574+
for (a = 0; token2[a] && token2[a] != '&'; a++);
575+
if (token2[a]) /* found "&" => another option follows */
576+
{
577+
token2[a] = '\0';
578+
str = token2 + a + 1;
579+
}
580+
else
581+
str = token2 + a;
578582

579-
conn_keywords[i] = token1;
580-
conn_values[i] = token2;
581-
i++;
583+
conn_keywords[i] = token1;
584+
conn_values[i] = token2;
585+
i++;
586+
}
587+
else
588+
/* the parser should not be able to create this invalid option */
589+
str = token1 + e;
582590
}
583591

584592
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy