c实现linux下的数据库备份

2020-01-06 13:22:38王冬梅
  • int stat_val;  pid_t child_pid; 
  •   child_pid = wait(&stat_val); 
  •   if (!WIFEXITED(stat_val)) { 
  • fprintf(stdout, "Child terminated abnormalyn");  } 
  • exit(1);   
  • }   
  • free_dblist();   
  • exit(0);   
  • }   
  • void malloc_dblist()  { 
  • int i = 0;  //malloc for db_list 
  • for (i = 0; i < NUM; i++) {  db_list[i] = malloc(LEN); 
  • memset(db_list[i], '', LEN);  } 
  • }  void free_dblist() 
  • {  int i; 
  • //free db_list's memory  for (i = 0; i < NUM; i++) { 
  • free(db_list[i]);  } 
  • }   
  • void readDbFile()  { 
  • FILE *fp;   
  • fp = fopen(DB_FILE, "r");  if (!fp) { 
  • fprintf(stderr, "%s not foundn", DB_FILE);  } 
  • else {  malloc_dblist(); 
  •   read_num = 0; 
  • while (fscanf(fp, "%127[^rn]n", db_list[read_num]) == 1) {  puts(db_list[read_num]); 
  • read_num++;  } 
  •   fclose(fp);  
  • }