]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/loclass/fileutils.c
206d9695c0e37f4f8decd168a667fb9d5208b5b4
9 * @brief checks if a file exists
13 int fileExists(const char *filename
) {
17 int result
= _stat(filename
, &st
);
20 int result
= stat(filename
, &st
);
25 int saveFile(const char *preferredName
, const char *suffix
, const void* data
, size_t datalen
)
27 int size
= sizeof(char) * (strlen(preferredName
)+strlen(suffix
)+10);
28 char * fileName
= malloc(size
);
30 memset(fileName
,0,size
);
32 sprintf(fileName
,"%s.%s", preferredName
, suffix
);
33 while(fileExists(fileName
))
35 sprintf(fileName
,"%s-%d.%s", preferredName
, num
, suffix
);
38 /* We should have a valid filename now, e.g. dumpdata-3.bin */
40 /*Opening file for writing in binary mode*/
41 FILE *fileHandle
=fopen(fileName
,"wb");
43 PrintAndLog("Failed to write to file '%s'", fileName
);
47 fwrite(data
, 1, datalen
, fileHandle
);
49 PrintAndLog("Saved data to '%s'", fileName
);
57 * Utility function to print to console. This is used consistently within the library instead
58 * of printf, but it actually only calls printf (and adds a linebreak).
59 * The reason to have this method is to
60 * make it simple to plug this library into proxmark, which has this function already to
61 * write also to a logfile. When doing so, just delete this function.
64 void prnlog(char *fmt
, ...)
66 char buffer
[2048] = {0};
69 vsprintf (buffer
,fmt
, args
);