Ignore:
Timestamp:
Aug 29, 2009, 3:22:10 AM (15 years ago)
Author:
Bruno Cornec
Message:
  • Some more fgets => mr_getline transformations
  • XWIN define is gone
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/mondorestore/mondo-rstr-tools.c

    r2351 r2357  
    107107* @ingroup restoreUtilityGroup
    108108*/
    109 void ask_about_these_imagedevs(char *infname, char *outfname)
    110 {
     109void ask_about_these_imagedevs(char *infname, char *outfname) {
     110
    111111FILE *fin;
    112112FILE *fout;
    113 /************************************************************************
    114 * allocate memory regions. test and set  -sab 16 feb 2003              *
    115 ************************************************************************/
    116 char *incoming_ptr;
    117 char *question_ptr = NULL;
    118 
    119 char incoming[MAX_STR_LEN] = "\0";
     113char *incoming = NULL;
     114char *question = NULL;
    120115
    121116assert_string_is_neither_NULL_nor_zerolength(infname);
    122117assert_string_is_neither_NULL_nor_zerolength(outfname);
    123118
    124 incoming_ptr = malloc(sizeof(incoming));
    125 if (incoming_ptr == NULL) {
    126 fprintf(stderr, "Out of Memory\n");
    127 exit(EXIT_FAILURE);
    128 }
    129 
    130 memset(incoming_ptr, '\0', sizeof(incoming));
    131 
    132119if (!(fin = fopen(infname, "r"))) {
    133 fatal_error("Cannot openin infname");
     120    fatal_error("Cannot openin infname");
    134121}
    135122if (!(fout = fopen(outfname, "w"))) {
    136 fatal_error("Cannot openin outfname");
    137 }
    138 for (fgets(incoming_ptr, MAX_STR_LEN, fin);
    139  !feof(fin); fgets(incoming_ptr, MAX_STR_LEN, fin)) {
    140 strip_spaces(incoming_ptr);
    141 
    142 if (incoming[0] == '\0') {
    143     continue;
    144 }
    145 
    146 mr_asprintf(question_ptr, "Should I restore the image of %s ?", incoming_ptr);
    147 
    148 if (ask_me_yes_or_no(question_ptr)) {
    149     fprintf(fout, "%s\n", incoming_ptr);
    150 }
    151 }
    152 
    153 /*** free memory ***********/
    154 paranoid_free(incoming_ptr);
    155 incoming_ptr = NULL;
    156 mr_free(question_ptr);
     123    fatal_error("Cannot openin outfname");
     124}
     125for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
     126    mr_strip_spaces(incoming);
     127
     128    if (incoming[0] == '\0') {
     129        mr_free(incoming);
     130        continue;
     131    }
     132
     133    mr_asprintf(question, "Should I restore the image of %s ?", incoming);
     134   
     135    if (ask_me_yes_or_no(question)) {
     136        fprintf(fout, "%s\n", incoming);
     137    }
     138    mr_free(incoming);
     139}
     140mr_free(incoming);
     141mr_free(question);
    157142paranoid_fclose(fout);
    158143paranoid_fclose(fin);
     
    619604        mr_free(bkpinfo->media_device);
    620605        if (bkpinfo->disaster_recovery && does_file_exist("/tmp/CDROM-LIVES-HERE")) {
    621             mr_asprintf(bkpinfo->media_device, "%s", last_line_of_file("/tmp/CDROM-LIVES-HERE"));
     606            bkpinfo->media_device = last_line_of_file("/tmp/CDROM-LIVES-HERE");
    622607        } else {
    623608            bkpinfo->media_device = find_cdrom_device(TRUE);
     
    11191104char *command = NULL;
    11201105char *tmp;
     1106char *tmp1 = NULL;
    11211107int res = 0;
    11221108pid_t pid;
     
    12601246    if (g_text_mode) {
    12611247        printf("Restore which directory? --> ");
    1262         fgets(tmp, sizeof(tmp), stdin);
    1263         toggle_path_selection(filelist, tmp, TRUE);
    1264         if (strlen(tmp) == 0) {
     1248        mr_getline(tmp1, stdin);
     1249        toggle_path_selection(filelist, tmp1, TRUE);
     1250        if (strlen(tmp1) == 0) {
    12651251            res = 1;
    12661252        } else {
    12671253            res = 0;
    12681254        }
     1255        mr_free(tmp1);
    12691256    } else {
    12701257        res = edit_filelist(filelist);
     
    19381925    FILE *fin;
    19391926    FILE *fout;
    1940   /** malloc **/
    1941     char *incoming;
     1927    char *incoming = NULL;
    19421928
    19431929    assert_string_is_neither_NULL_nor_zerolength(output_file);
    19441930    assert_string_is_neither_NULL_nor_zerolength(input_file);
    1945     malloc_string(incoming);
    19461931
    19471932    if (!(fin = fopen(input_file, "r"))) {
     
    19521937        fatal_error("cannot open output_file");
    19531938    }
    1954     for (fgets(incoming, MAX_STR_LEN - 1, fin); !feof(fin);
    1955          fgets(incoming, MAX_STR_LEN - 1, fin)) {
     1939    for (mr_getline(incoming, fin); !feof(fin); mr_getline(incoming, fin)) {
    19561940        if (strncmp(incoming, "etc/adjtime", 11)
    19571941            && strncmp(incoming, "etc/mtab", 8)
     
    19621946            && strncmp(incoming, "var/", 4))
    19631947            fprintf(fout, "%s", incoming);  /* don't need \n here, for some reason.. */
    1964     }
     1948        mr_free(incoming);
     1949    }
     1950    mr_free(incoming);
    19651951    paranoid_fclose(fout);
    19661952    paranoid_fclose(fin);
    1967     paranoid_free(incoming);
    19681953}
    19691954
Note: See TracChangeset for help on using the changeset viewer.