Esempio n. 1
0
int MFILE::vprintf(const char* format, va_list ap) {
    char buf2[BUFSIZE];
    int n, k;

    k = vsnprintf(buf2, BUFSIZE, format, ap);
    if (k<=-1 || k>=BUFSIZE) {
        fprintf(stderr, "ERROR: buffer too small in MFILE::vprintf()\n");
        fprintf(stderr, "ERROR: format: %s\n", format);
        fprintf(stderr, "ERROR: k=%d, BUFSIZE=%d\n", k, BUFSIZE);
        return -1;
    }
    n = (int)strlen(buf2);
    buf = (char*)realloc_aux(buf, len+n+1);
    if (!buf) {
        fprintf(stderr,
            "ERROR: realloc() failed in MFILE::vprintf(); len %d n %d\n",
            len, n
        );
        exit(1);
    }
    strncpy(buf+len, buf2, n);
    len += n;
    buf[len] = 0;
    return k;
}
Esempio n. 2
0
int MFILE::_putchar(wxChar c) {
    buf = (wxChar*)realloc_aux(buf, len+1+1);
    if (!buf) {
        _ftprintf(stderr, wxT("ERROR: realloc() failed in MFILE::_putchar()\n"));
        exit(1);
    }
    buf[len] = c;
    len++;
    buf[len] = 0;
    return c;
}
Esempio n. 3
0
size_t MFILE::write(const void *ptr, size_t size, size_t nitems) {
    buf = (wxChar*)realloc_aux( buf, len+(size*nitems)+1 );
    if (!buf) {
        _ftprintf(stderr, wxT("ERROR: realloc() failed in MFILE::write()\n"));
        exit(1);
    }
    memcpy( buf+len, ptr, size*nitems );
    len += (int)size*(int)nitems;
    buf[len] = 0;
    return nitems;
}
Esempio n. 4
0
int MFILE::puts(const wxChar* p) {
    int n = (int)_tcslen(p);
    buf = (wxChar*)realloc_aux(buf, len+n+1);
    if (!buf) {
        _ftprintf(stderr, wxT("ERROR: realloc() failed in MFILE::puts()\n"));
        exit(1);
    }
    _tcsncpy(buf+len, p, n);
    len += n;
    buf[len] = 0;
    return n;
}
Esempio n. 5
0
int MFILE::_putchar(char c) {
    buf = (char*)realloc_aux(buf, len+1+1);
    if (!buf) {
        fprintf(stderr,
            "ERROR: realloc() failed in MFILE::_putchar(); len %d\n", len
        );
        exit(1);
    }
    buf[len] = c;
    len++;
    buf[len] = 0;
    return c;
}
Esempio n. 6
0
int MFILE::puts(const char* p) {
    int n = (int)strlen(p);
    buf = (char*)realloc_aux(buf, len+n+1);
    if (!buf) {
        fprintf(stderr,
            "ERROR: realloc() failed in MFILE::puts() len %d n %d\n", len, n
        );
        exit(1);
    }
    strncpy(buf+len, p, n);
    len += n;
    buf[len] = 0;
    return n;
}
Esempio n. 7
0
size_t MFILE::write(const void *ptr, size_t size, size_t nitems) {
    buf = (char *)realloc_aux( buf, len+(size*nitems)+1 );
    if (!buf) {
        fprintf(stderr,
            "ERROR: realloc() failed in MFILE::write(); len %d size %lu nitems %lu\n",
            len, size, nitems
        );
        exit(1);
    }
    memcpy( buf+len, ptr, size*nitems );
    len += (int)size*(int)nitems;
    buf[len] = 0;
    return nitems;
}
Esempio n. 8
0
int MFILE::vprintf(const wxChar* format, va_list ap) {
    wxChar buf2[BUFSIZE];
    int n, k;

    k = _vsntprintf(buf2, BUFSIZE, format, ap);
    if (k<=-1 || k>=BUFSIZE) {
        _ftprintf(stderr, wxT("ERROR: buffer too small in MFILE::vprintf()\n"));
        _ftprintf(stderr, wxT("ERROR: format: %s\n"), format);
        _ftprintf(stderr, wxT("ERROR: k=%d, BUFSIZE=%d\n"), k, BUFSIZE);
        return -1;
    }
    n = (int)_tcslen(buf2);
    buf = (wxChar*)realloc_aux(buf, len+n+1);
    if (!buf) {
        _ftprintf(stderr, wxT("ERROR: realloc() failed in MFILE::vprintf()\n"));
        exit(1);
    }
    _tcsncpy(buf+len, buf2, n);
    len += n;
    buf[len] = 0;
    return k;
}