|
samba unix风格的配置文件配置信息读取C代码.(20) if( !Parameter( InFile, pfunc, c ) ) return( False ); c = EatWhitespace( InFile ); break; } } return( True ); } /* Parse */ /**************************************************************************** load a file into memory from a fd. ****************************************************************************/
char *fd_load(int fd, size_t *size) { struct stat sbuf; char *p; if (fstat(fd, &sbuf) != 0) return NULL; p = (char *)malloc(sbuf.st_size+1); if (!p) return NULL; if (read(fd, p, sbuf.st_size) != sbuf.st_size) { SAFE_FREE(p); return NULL; } p[sbuf.st_size] = 0; if (size) *size = sbuf.st_size; return p; } /**************************************************************************** load a file into memory ****************************************************************************/ char *file_load(char *fname, size_t *size) { int fd; char *p; if (!fname !*fname) return NULL; fd = open( fname, O_RDONLY ); if (fd == -1) return NULL; p = fd_load(fd, size); close(fd); return p; } static myFILE *OpenConfFile( char *FileName ) /* ------------------------------------------------------------------------ ** * Open a configuration file. * * Input: FileName - The pathname of the config file to be opened. * * Output: A pointer of type (char **) to the lines of the file * * ------------------------------------------------------------------------ **
|