Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Inserting

Name: Anonymous 2009-09-03 7:48

are there any open/write functions for C , which do not overwrite chars in a file , but insert them ?

or do i have to write a shitty loop that just reads , stores and writes a char ?

also discuss file and string handling libraries because most that i have seen suck .

Name: Anonymous 2009-09-03 8:56

>>9
Unfortunately, you can't patch large files fast. For this reason, many file formats that are designed to be both large and edited often tend to be designed like filesystems.

BTW : there is no function in libc which can insert into buffers ? i assume i would have to implement a read store write loop for a buffer too ? after allocating memory ofcourse .
Not that I know of, but that's easily fixed:

void meminsert(char *buffer, int index, char *insertData, char *insertDataSize)
{
    // assumes buffer has room for the extra insertDataSize bytes
    memmove(buffer + index + insertDataSize, buffer + index, insertDataSize);
    memcpy(buffer + index, insertData, insertDataSize);
}

Note that this is still rather slow, and that calling it once with much data to insert is way faster than calling it often with small chunks to insert.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List