Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

I'm looking for an open source library similar to picostorage, who can recommend a few?

I've been using picostorage,but recently i found that the File is very easy to damage. so i want to look for an open source library.

If the file is damaged,I can not get the data and I do not know the file has been damaged.

These two functions is my functions to manipulate files.

My operating system is window7.

C++
static void __store_data_of( IN ps::Dir &rootdir, IN std::string const &key, IN std::string const &data )
{
    if ( key == "" )
    {
        //  invalid key name, just return
        return;
    }

    ps::File file = rootdir.openFile( key.c_str() );
    if ( !file )
    {
        file = rootdir.createFile( key.c_str() );
        if ( !file )
        {
            thrd_core_dump_tm( __FUNCTION__", faile to createFile\n");
            return;
        }
    }
    file.setSize( data.size() );
    file.pwrite( data.c_str(), data.size(), 0 );
    file.commit();
}

static bool __fetch_data_of( IN ps::Dir &rootdir, IN std::string const &key, OUT std::string &data )
{
    if ( key == "" )
    {
        //  invalid key name, just return
        return  false;
    }

    ps::File file = rootdir.openFile( key.c_str() );
    if ( !file || !file.getSize() )
    {
        return  false;
    }

    size_t  len = (size_t)file.getSize();

    char *_data = (char*)malloc( len + 1);

    LOKI_ON_BLOCK_EXIT( &::free, _data );

    memset( _data, 0, len + 1 );

    file.pread( _data, len, 0 );

    data = std::string( _data, len );

    return  true;
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900