Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Patch for zxcvbn-c to make it work with Qt
diff --git a/zxcvbn.c b/zxcvbn.c
index ebe9e31..5b2dcf3 100644
--- a/zxcvbn.c
+++ b/zxcvbn.c
@@ -41,6 +41,7 @@
#include <stdio.h>
#else
#include <fstream>
+#include <QFile>
#endif
#endif
@@ -263,11 +264,12 @@ typedef FILE *FileHandle;
#else
/* Use the C++ iostreams */
-typedef std::ifstream FileHandle;
+typedef QFile FileHandle;
static inline void MyOpenFile(FileHandle & f, const char *Name)
{
- f.open(Name, std::ifstream::in | std::ifstream::binary);
+ f.setFileName(QString(Name));
+ f.open(QIODevice::ReadOnly);
}
static inline bool MyReadFile(FileHandle & f, void *Buf, unsigned int Num)
{
@@ -342,8 +344,8 @@ int ZxcvbnInit(const char *Filename)
uint64_t Crc = CHK_INIT;
if (DictNodes)
return 1;
- MyOpenFile(f, Filename);
- if (f)
+ MyOpenFile(f, Filename);
+ if (f.isOpen())
{
unsigned int i, DictSize;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment