OsStatus OsConfigDb::storeToFile(const char *filename) { if (filename == NULL) { return OS_INVALID_ARGUMENT; } OsStatus retval = OS_UNSPECIFIED; OsReadLock lock(mRWMutex); // take lock for writing while the database // is loaded setIdentityLabel(filename); OsConfigEncryption *encryption = getEncryption(); if (encryption != NULL && encryption->isWriteEncryptedEnabled() && encryption->isNormallyEncrypted(this)) { retval = storeToEncryptedFile(filename); } else { FILE *fp = fopen(filename,"wb"); if (!fp) { osPrintf("Could not open %s. errno = %d\n",filename,errno); return retval; } retval = storeToFile(fp); fclose(fp); } return retval; }
bool StoreData(EntityManager *entityManager) { bool pass = true; const char *fileName = "store.txt"; EntityManager e1; EntityManager *loadedEntityManager; EntityManager_New(&e1); loadedEntityManager = &e1; if (storeToFile(entityManager, fileName, StorageSecret, StorageSalt) == true) { if (loadFromFile(loadedEntityManager, fileName, StorageSecret, StorageSalt) == true) { if (EntityManager_IsEqual(entityManager, loadedEntityManager) == false) { printf("Stored data != loaded one"); EntityManager_PrintFull(stdout, "Stored data:", entityManager); EntityManager_PrintFull(stdout, "Loaded data:", loadedEntityManager); pass = false; }else { EntityManager_PrintFull(stdout, "Loaded data is equal to the stored one:", loadedEntityManager); pass = true; } EntityManager_FreeAll(loadedEntityManager); }else pass = false; // Utils_RemoveFile(fileName); }else pass = false; return pass; }
/* * Open the file with @param path and wirte @param sz byte of data starting from @param buf into the file * @param path the path of the file to open and write * @param buf the starting address of the data to write into file * @param sz how many bytes to write at most * @return the byte we've written */ int rtw_store_to_file(char *path, u8* buf, u32 sz) { #ifdef PLATFORM_LINUX int ret =storeToFile(path, buf, sz); return ret>=0?ret:0; #else //Todo... return 0; #endif }
/* * Open the file with @param path and wirte @param sz byte of data starting from @param buf into the file * @param path the path of the file to open and write * @param buf the starting address of the data to write into file * @param sz how many bytes to write at most * @return the byte we've written */ int rtw_store_to_file(char *path, u8 __user *buf, u32 sz) { int ret =storeToFile(path, buf, sz); return ret >= 0 ? ret : 0; }