/*c语言实现,可在linux平台上用了,在Windows下可以用GetPrivateProfileString或GetPrivateProfileInt方便读取.ini配置文件内容,但是在Linux平台上就一筹莫展了。为了解决该问题,打算用C来读取.ini,即可不受平台的限制了*/
#define CONF_FILE_PATH "Config.ini"
#include <string.h>
#ifdef WIN32
#include <Windows.h>
#include <stdio.h>
#else
#define MAX_PATH 260
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#endif
char g_szConfigPath[MAX_PATH];
//获取当前程序目录
int GetCurrentPath(char buf[],char *pFileName)
{
#ifdef WIN32
GetModuleFileName(NULL,buf,MAX_PATH);
#else
char pidfile[64];
int bytes;
int fd;
sprintf(pidfile, "/proc/%d/cmdline", getpid());
fd = open(pidfile, O_RDONLY, 0);
bytes = read(fd, buf, 256);
close(fd);
buf[MAX_PATH] = '\0';
#endif
char * p = &buf[strlen(buf)];
do
{
*p = '\0';
p--;
#i
用C读取INI配置文件 (可在linux平台上用)
最新推荐文章于 2024-07-16 12:57:18 发布