ebmDevMag.com home
ebm Developer's Magazine
links

developer's mag
main page

article
part 1
part 2
part 3
part 4
part 5
part 6


3 - New Files

The most obvious error for ebo_mapin() is that the file doesn't exist. To solve that, we need to create the file, using ebo_new():

int ebo_new (const ebo_name_t * name, off_t size, int clobber)

Again, the file description structure is needed. To create your own in code, simply define the structure, and pass a pointer to it:

const ebo_name_t mySampleFile={ "","My Company","Sample File","ext" };
ebo_new(&mySampleFile, ...

clobber is a flag that tells what to do if the file already exists. If one, the old file is erased, but if zero, the call fails. Since we know the file doesn't exist at this point, either value will work here.

The size value determines the final file size, and should be as small as reasonable, since this call actually sets aside memory. A safe value is the smallest virtual chunk, defined as EBO_BLK_SIZE. Of course, if you happen to know your file's final size, you can set it here once and for all; again, remembering to use ebo_roundup() on the value.

On success, you have a fresh file, ready to use, and all cleaned up; according to the API documentation, every new block is filled with null bytes, for security reasons. However, if you prefer, you can clear it yourself with memset:

memset(ptr,0,size);


Previous Section
Next Section

Copyright © 2001-2006 ebmDevMag.com - Legal Notice