Skip to content
Snippets Groups Projects
Commit 73f7a391 authored by Olof Barring's avatar Olof Barring Committed by Steven Murray
Browse files

Go back to use strtok_r instead of strpbrk

parent e80fdd95
No related branches found
No related tags found
No related merge requests found
/*
* $Id: getconfent.c,v 1.5 1999/07/21 12:42:20 jdurand Exp $
* $Id: getconfent.c,v 1.6 1999/07/22 15:29:53 obarring Exp $
* $Log: getconfent.c,v $
* Revision 1.6 1999/07/22 15:29:53 obarring
* Go back to use strtok_r instead of strpbrk
*
* Revision 1.5 1999/07/21 12:42:20 jdurand
* HP-UX's cc [without options] don't like function prototypes. Changed it
* to old C style.
......@@ -23,16 +26,9 @@
#endif
#endif /* PATH_CONFIG */
#ifdef CONST
#undef CONST
#endif
#if defined(__STDC__)
#define CONST const
#else
#define CONST
#endif
CONST char char_set[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+|~`\\=-{}[]:;''\",./<>?";
#if defined(_REENTRANT) || defined(_THREAD_SAFE)
#define strtok(X,Y) strtok_r(X,Y,&last)
#endif /* _REENTRANT || _THREAD_SAFE */
char *getconfent_r(category, name, flags, buffer, bufsiz)
......@@ -42,72 +38,67 @@ char *getconfent_r(category, name, flags, buffer, bufsiz)
char *buffer;
int bufsiz;
{
char *filename=PATH_CONFIG;
FILE *fp;
char *p, *cp, *ep;
char *getenv();
int found = 0;
char path_config[256];
char *separator;
if ((p = getenv("PATH_CONFIG")) != NULL) {
filename=p;
}
char *filename=PATH_CONFIG;
FILE *fp;
char *p, *cp;
char *getenv();
int found = 0;
char path_config[256];
char *separator;
#if defined(_REENTRANT) || defined(_THREAD_SAFE)
char *last = NULL;
#endif /* _REENTRANT || _THREAD_SAFE */
if ((p = getenv("PATH_CONFIG")) != NULL) {
filename=p;
}
#if defined(_WIN32)
if (strncmp (filename, "%SystemRoot%\\", 13) == 0 &&
(p = getenv ("SystemRoot")))
sprintf (path_config, "%s\\%s", p, strchr (filename, '\\'));
else
if (strncmp (filename, "%SystemRoot%\\", 13) == 0 &&
(p = getenv ("SystemRoot")))
sprintf (path_config, "%s\\%s", p, strchr (filename, '\\'));
else
#endif
strcpy (path_config, filename);
strcpy (path_config, filename);
if ((fp = fopen(path_config,"r")) == NULL) {
serrno = SENOCONFIG;
return (NULL);
if ((fp = fopen(path_config,"r")) == NULL) {
serrno = SENOCONFIG;
return (NULL);
}
for (;;) {
p = fgets(buffer, bufsiz-1, fp);
if (p == NULL) {
break;
}
for (;;) {
p = fgets(buffer, bufsiz-1, fp);
if (p == NULL) {
break;
if ( (cp = strtok(p," \t")) == NULL) continue; /* empty line */
if (*cp == '#') continue; /* comment */
if (strcmp(cp,category) == 0) { /* A category match */
if ( (cp = strtok(NULL," \t")) == NULL ) continue;
if (*cp == '#') continue; /* comment, invalid */
if ( strcmp(cp,name) == 0) { /* A match */
if (flags != 0) {
/* Don't tokenize next arg */
separator = "#\n";
} else {
separator = "#\t \n";
}
if (*p == '#') continue;
if ((cp = strpbrk(p,char_set)) == NULL) continue;
if (*cp == '#') continue;
if ((ep = strpbrk(cp," \t")) == NULL) ep = &cp[strlen(cp)];
if ( *ep == '\n' ) continue;
*ep = '\0';
if (strcmp(cp,category) == 0) {
p = &ep[1];
if ((cp = strpbrk(p,char_set)) == NULL ) continue;
if (*cp == '#') continue;
if ((ep = strpbrk(cp," \t")) == NULL) ep = &cp[strlen(cp)];
if ( *ep == '\n' ) continue;
*ep = '\0';
if ( strcmp(cp,name) == 0) {
if (flags != 0) {
separator = "#\n";
} else {
separator = "#\t \n";
}
p = &ep[1];
if ((cp = strpbrk(p,char_set)) == NULL) continue;
if (*cp == '#') continue;
if ((ep = strpbrk(cp,separator)) == NULL) ep = &cp[strlen(cp)];
*ep = '\0';
found++;
break;
}
else {
continue;
}
} else {
continue;
}
}
if (fclose(fp)) return(NULL);
if (found == 0) return(NULL);
else return(cp);
if ( (cp = strtok(NULL, separator)) == NULL ) continue;
if (*cp == '#') continue;
found++;
break;
}
else {
continue;
}
} else {
continue;
}
}
if (fclose(fp)) return(NULL);
if (found == 0) return(NULL);
else return(cp);
}
static int value_key = -1;
......@@ -117,12 +108,12 @@ char *getconfent(category, name, flags)
char *name;
int flags;
{
char *value = NULL;
char *value = NULL;
Cglobals_get(&value_key,(void **) &value,BUFSIZ+1);
if ( value == NULL ) {
return(NULL);
}
Cglobals_get(&value_key,(void **) &value,BUFSIZ+1);
if ( value == NULL ) {
return(NULL);
}
return(getconfent_r(category,name,flags,value,BUFSIZ+1));
return(getconfent_r(category,name,flags,value,BUFSIZ+1));
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment