bool WriteFile( const std::string &path, const Buffer &buf ) { s32 fd; int i; u64 written; i = sysFsOpen( path.c_str(), SYS_O_WRONLY | SYS_O_CREAT | SYS_O_TRUNC, &fd, NULL, 0 ); if( i ) { printf("sysFsOpen( %s ): %i\n", path.c_str(), i ); return false; } i = sysFsWrite( fd, (void*)buf.ConstData(), buf.Size(), &written ); if( i ) { sysFsClose( fd ); sysFsUnlink( path.c_str() ); printf("sysFsWrite( %s ): %i\n", path.c_str(), i ); return false; } sysFsClose( fd ); if( written != buf.Size() ) { printf("WriteFile() failed to write all the data to \"%s\"\n", path.c_str() ); sysFsUnlink( path.c_str() ); return false; } return true; }
int file_simple_save(const char *filePath, void *buf, unsigned int fileSize) { int ret; int fd; uint64_t writelen; if (buf == NULL) { LOG(lm_main, LOG_ERROR, ("buffer is null\n")); } ret = sysFsOpen(filePath, SYS_O_WRONLY | SYS_O_CREAT | SYS_O_TRUNC, &fd, NULL, 0); if ((ret != 0)) // && (ret != EPERM) ){ { LOG(lm_main, LOG_ERROR, ("file %s open error : 0x%x\n", filePath, ret)); return -1; } ret = sysFsWrite(fd, buf, fileSize, &writelen); if (ret != 0 || fileSize != writelen) { LOG(lm_main, LOG_ERROR, ("file %s read error : 0x%x\n", filePath, ret)); sysFsClose(fd); return -1; } ret = sysFsClose(fd); if (ret != 0) { LOG(lm_main, LOG_ERROR, ("file %s close error : 0x%x\n", filePath, ret)); return -1; } return 0; }
bool WriteFile( const std::string &path, const u8* stuff, u32 size ) { //hexdump( stuff, size ); s32 fd; int i; u64 written; i = sysFsOpen( path.c_str(), SYS_O_WRONLY | SYS_O_CREAT | SYS_O_TRUNC, &fd, NULL, 0 ); if( i ) { printf("sysFsOpen( %s ): %i\n", path.c_str(), i ); return false; } i = sysFsWrite( fd, (void*)stuff, size, &written ); if( i ) { sysFsClose( fd ); sysFsUnlink( path.c_str() ); printf("sysFsWrite( %s ): %i\n", path.c_str(), i ); return false; } sysFsClose( fd ); if( written != size ) { printf("WriteFile() failed to write all the data to \"%s\"\n", path.c_str() ); sysFsUnlink( path.c_str() ); return false; } return true; }