Ignore:
Timestamp:
Feb 16, 2007, 12:25:24 PM (17 years ago)
Author:
Bruno Cornec
Message:

merges from trunk for memory management for libmondo-mountlist.c mainly

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/stable/mondo/src/common/libmondo-fork.c

    r1168 r1173  
    4646
    4747    assert_string_is_neither_NULL_nor_zerolength(call);
     48
    4849    if ((fin = popen(call, "r"))) {
    4950        for (fgets(tmp, MAX_STR_LEN, fin); !feof(fin);
     
    184185    char *callstr = NULL;
    185186    char *incoming = NULL;
    186     char *tmp = NULL;
    187187
    188188    /*@ int ********************************************************* */
    189189    int res = 0;
    190190    size_t n = 0;
    191     int i;
    192     int len;
    193191    bool log_if_failure = FALSE;
    194192    bool log_if_success = FALSE;
     
    325323        }
    326324    }
    327 #ifdef _XWIN
    328     /* This only can update when newline goes into the file,
    329        but it's *much* prettier/faster on Qt. */
    330     while (does_file_exist(lockfile)) {
    331         while (!feof(fin)) {
    332             if (!fgets(tmp, 512, fin))
    333                 break;
    334             log_to_screen(tmp);
    335         }
    336         usleep(500000);
    337     }
    338 #else
    339325    /* This works on Newt, and it gives quicker updates. */
    340326    for (; does_file_exist(lockfile); sleep(1)) {
     
    342328        update_evalcall_form(1);
    343329    }
    344 #endif
    345330    /* Evaluate the status returned by pclose to get the exit code of the called program. */
    346331    errno = 0;
     
    379364// if dir=='r' then copy from archived to orig
    380365    char *tmp = NULL;
     366    char *tmp1 = NULL;
    381367    char *buf = NULL;
    382368    long int bytes_to_be_read, bytes_read_in, bytes_written_out =
     
    396382        fin = f_orig;
    397383        fout = f_archived;
    398         sprintf(tmp, "%-64s", PIMP_START_SZ);
    399         if (fwrite(tmp, 1, 64, fout) != 64) {
     384        mr_asprintf(&tmp1, "%-64s", PIMP_START_SZ);
     385        if (fwrite(tmp1, 1, 64, fout) != 64) {
    400386            fatal_error("Can't write the introductory block");
    401387        }
     388        mr_free(tmp1);
     389
    402390        while (1) {
    403391            bytes_to_be_read = bytes_read_in = fread(buf, 1, bufcap, fin);
     
    405393                break;
    406394            }
    407             sprintf(tmp, "%-64ld", bytes_read_in);
    408             if (fwrite(tmp, 1, 64, fout) != 64) {
     395            mr_asprintf(&tmp1, "%-64ld", bytes_read_in);
     396            if (fwrite(tmp1, 1, 64, fout) != 64) {
    409397                fatal_error("Cannot write introductory block");
    410398            }
     399            mr_free(tmp1);
     400
    411401            mr_msg(7,
    412402                    "subslice #%ld --- I have read %ld of %ld bytes in from f_orig",
    413403                    subsliceno, bytes_read_in, bytes_to_be_read);
    414404            bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
    415             sprintf(tmp, "%-64ld", subsliceno);
    416             if (fwrite(tmp, 1, 64, fout) != 64) {
     405            mr_asprintf(&tmp1, "%-64ld", subsliceno);
     406            if (fwrite(tmp1, 1, 64, fout) != 64) {
    417407                fatal_error("Cannot write post-thingy block");
    418408            }
     409            mr_free(tmp1);
     410
    419411            mr_msg(7, "Subslice #%d written OK", subsliceno);
    420412            subsliceno++;
     
    427419        fin = f_archived;
    428420        fout = f_orig;
     421        tmp = mr_malloc(64L);
    429422        if (fread(tmp, 1, 64L, fin) != 64L) {
    430423            fatal_error("Cannot read the introductory block");
     
    447440            }
    448441            bytes_written_out += fwrite(buf, 1, bytes_read_in, fout);
    449             if (fread(tmp, 1, 64, fin) != 64) {
     442            if (fread(tmp, 1, 64L, fin) != 64L) {
    450443                fatal_error("Cannot read post-thingy block");
    451444            }
     
    456449            mr_msg(7, "Subslice #%ld read OK", subsliceno);
    457450            subsliceno++;
    458             if (fread(tmp, 1, 64, fin) != 64) {
     451            if (fread(tmp, 1, 64L, fin) != 64L) {
    459452                fatal_error("Cannot read introductory block");
    460453            }
     
    466459
    467460    if (direction == 'w') {
    468         sprintf(tmp, "%-64s", PIMP_END_SZ);
    469         if (fwrite(tmp, 1, 64, fout) != 64) {
     461        mr_asprintf(&tmp1, "%-64s", PIMP_END_SZ);
     462        if (fwrite(tmp1, 1, 64L, fout) != 64L) {
    470463            fatal_error("Can't write the final block");
    471464        }
     465        mr_free(tmp1);
    472466    } else {
    473467        mr_msg(1, "tmpA is %s", tmp);
    474468        if (!strstr(tmp, PIMP_END_SZ)) {
    475             if (fread(tmp, 1, 64, fin) != 64) {
     469            if (fread(tmp, 1, 64L, fin) != 64L) {
    476470                fatal_error("Can't read the final block");
    477471            }
     
    479473            if (!strstr(tmp, PIMP_END_SZ)) {
    480474                ftmp = fopen("/tmp/out.leftover", "w");
    481                 bytes_read_in = fread(tmp, 1, 64, fin);
     475                bytes_read_in = fread(tmp, 1, 64L, fin);
    482476                mr_msg(1, "bytes_read_in = %ld", bytes_read_in);
    483477//      if (bytes_read_in!=128+64) { fatal_error("Can't read the terminating block"); }
Note: See TracChangeset for help on using the changeset viewer.