]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/loclass/fileutils.c
ADD: Holimans new changes in master.
[proxmark3-svn] / client / loclass / fileutils.c
index deab3137a5704d798374430725f48661c3b07ff8..443070c121b0817bb8adfc7fe9a7a7fb3c9a502e 100644 (file)
  * @return
  */
 int fileExists(const char *filename) {
+
+#ifdef _WIN32
        struct _stat fileStat;
        int result = _stat(filename, &fileStat);
+#else
+       struct stat fileStat;
+       int result = stat(filename, &fileStat);
+#endif
        return result == 0;
 }
 
@@ -73,6 +79,7 @@ int saveFile(const char *preferredName, const char *suffix, const void* data, si
        FILE *fh=fopen(fileName,"wb");
        if(!fh) {
                PrintAndLog("Failed to write to file '%s'", fileName);
+               free(fh);
                return 1;
        }
        fwrite(data, 1, datalen, fh);
@@ -88,10 +95,12 @@ int loadFile(const char *fileName, void* data, size_t datalen)
        FILE *filehandle = fopen(fileName, "rb");
        if(!filehandle) {
                PrintAndLog("Failed to read from file '%s'", fileName);
+               free(filehandle);
                return 1;
        }
        fread(data,datalen,1,filehandle);
        fclose(filehandle);
+       free(filehandle);
        return 0;
 }
 /**
Impressum, Datenschutz