configfile.c
来自「系统迁移的源代码: http://www.diku.dk/hjemmeside」· C语言 代码 · 共 75 行
C
75 行
#include <stdio.h>#include <stdlib.h>#include <string.h>#include "configfile.h"void read_config(char* cfgfile, char* ip, char* ip2, char* initrd, char* kernel, char* cmdline, int* mem_mb, int* maxmem_mb, int* console, int* vif, int* num_vbds,struct vbd* vbds){ char key[256]; char value[256]; struct vbd* vbd = vbds; FILE* f = fopen(cfgfile,"r"); *num_vbds=0; if(!f) { printf("error opening cfg file %s\n", cfgfile); exit(-1); } while( fscanf(f, "%[^=] = %[^\n]\n", key, value)!= EOF) { if(!strcmp(key, "kernel")) { strcpy(kernel,value); } else if(!strcmp(key, "initrd")) { strcpy(initrd,value); } else if(!strcmp(key, "ip")) { strcpy(ip,value); } else if(!strcmp(key, "ip2")) { strcpy(ip2,value); } else if(!strcmp(key, "cmdline")) { strcpy(cmdline,value); } else if(vbd && !strcmp(key, "vbd")) { strcpy(vbd->mode,"r"); sscanf(value, "%x,%x,%s\n", &vbd->pdev,&vbd->vdev,vbd->mode); vbd++; ++(*num_vbds); } else if(!strcmp(key, "mem")) { sscanf(value, "%dM", mem_mb); } else if(!strcmp(key, "maxmem")) { sscanf(value, "%dM", maxmem_mb); } else if(!strcmp(key, "console")) { sscanf(value, "%d", console); } else if(!strcmp(key, "vif")) { sscanf(value, "%d", vif); } } fclose(f);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?