]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/loclass/fileutils.c
Merge branch 'master' of https://github.com/Proxmark/proxmark3
[proxmark3-svn] / client / loclass / fileutils.c
index 6d9901718848845e4eb990ed33d559b3760cf438..e5e5c5b0569270c422c53e83078d738a64f9e106 100644 (file)
@@ -35,6 +35,7 @@
  * 
  * 
  ****************************************************************************/
+#ifndef ON_DEVICE
 
 #include <stdio.h>
 #include <string.h>
  * @return
  */
 int fileExists(const char *filename) {
-       struct _stat fileStat;
-       int result = _stat(filename, &fileStat);
+
+#ifdef _WIN32
+       struct _stat st;
+       int result = _stat(filename, &st);
+#else
+       struct stat st;
+       int result = stat(filename, &st);
+#endif
        return result == 0;
 }
 
 int saveFile(const char *preferredName, const char *suffix, const void* data, size_t datalen)
 {
-       int size = sizeof(char) * (strlen(preferredName)+strlen(suffix)+5);
+       int size = sizeof(char) * (strlen(preferredName)+strlen(suffix)+10);
        char * fileName = malloc(size);
 
        memset(fileName,0,size);
@@ -73,6 +80,7 @@ int saveFile(const char *preferredName, const char *suffix, const void* data, si
        FILE *fileHandle=fopen(fileName,"wb");
        if(!fileHandle) {
                prnlog("Failed to write to file '%s'", fileName);
+               free(fileName);
                return 1;
        }
        fwrite(data, 1, datalen, fileHandle);
@@ -83,17 +91,6 @@ int saveFile(const char *preferredName, const char *suffix, const void* data, si
        return 0;
 }
 
-int loadFile(const char *fileName, void* data, size_t datalen)
-{
-       FILE *filehandle = fopen(fileName, "rb");
-       if(!filehandle) {
-               prnlog("Failed to read from file '%s'", fileName);
-               return 1;
-       }
-       fread(data,datalen,1,filehandle);
-       fclose(filehandle);
-       return 0;
-}
 /**
  * Utility function to print to console. This is used consistently within the library instead
  * of printf, but it actually only calls printf (and adds a linebreak).
@@ -104,11 +101,18 @@ int loadFile(const char *fileName, void* data, size_t datalen)
  */
 void prnlog(char *fmt, ...)
 {
-
+       char buffer[2048] = {0};
        va_list args;
        va_start(args,fmt);
-    PrintAndLog(fmt, args);
-    //vprintf(fmt,args);
+       vsprintf (buffer,fmt, args);
        va_end(args);
-    //printf("\n");
+       PrintAndLog(buffer);
+
 }
+#else //if we're on ARM
+void prnlog(char *fmt,...)
+{
+       return;
+}
+
+#endif
Impressum, Datenschutz