Skip to content

Instantly share code, notes, and snippets.

@Furkanzmc
Created August 31, 2018 20:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Furkanzmc/d24b14171688134423ce912998f2d093 to your computer and use it in GitHub Desktop.
Save Furkanzmc/d24b14171688134423ce912998f2d093 to your computer and use it in GitHub Desktop.
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