📄 util.c
字号:
/***************************
util.c
***************************/
/*
*
*
* 08/01/2002 Andrew Bond, HP
* - Configuration values are stored in a
filesystem file under Linux
* rather than the Windows registry.
*
*/
#include <stdio.h>
#define MAXCFGLINE 255
#define CONFIGFILENAME "/usr/local/etc/tpcc.conf"
/* FUNCTION: int GetConfigValue(char *option, char *value)
*
* Read the Linux tpcc configuration file
*
*/
int GetConfigValue(char *option, char *value)
{
FILE *cfFD;
char line[MAXCFGLINE];
char optname[MAXCFGLINE];
char *poptname, *tmpValue, *linep;
int full_len, half_len, len;
short notfound=1;
poptname=(char *)&optname;
cfFD=fopen(CONFIGFILENAME, "r");
if (cfFD == NULL)
{
printf("Error opening file\n");
return -1;
}
linep=(char *)&line;
while ((fgets(linep, MAXCFGLINE, cfFD) != NULL) && (notfound))
{
tmpValue=(char *)index(linep, '=');
if (tmpValue==NULL)
{
printf("Equals sign not found\n");
continue;
}
full_len=strlen(linep);
half_len=strlen(tmpValue);
strncpy(poptname,linep, full_len-half_len);
optname[full_len-half_len] = '\0';
tmpValue++;
if (!strcmp(optname, option))
{
len=strlen(tmpValue);
strncpy(value, tmpValue, len-1);
value[len-1] = '\0';
notfound=0;
}
}
fclose(cfFD);
if (notfound)
return(0);
else
return(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -