]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/loclass/fileutils.c
08e1c1a798ce6eb18bd49fb642674af76f61b0b0
9 * @brief checks if a file exists
13 int fileExists(const char *filename
) {
14 struct _stat fileStat
;
15 int result
= _stat(filename
, &fileStat
);
19 int saveFile(const char *preferredName
, const char *suffix
, const void* data
, size_t datalen
)
21 int size
= sizeof(char) * (strlen(preferredName
)+strlen(suffix
)+5);
22 char * fileName
= malloc(size
);
24 memset(fileName
,0,size
);
26 sprintf(fileName
,"%s.%s", preferredName
, suffix
);
27 while(fileExists(fileName
))
29 sprintf(fileName
,"%s-%d.%s", preferredName
, num
, suffix
);
32 /* We should have a valid filename now, e.g. dumpdata-3.bin */
34 /*Opening file for writing in binary mode*/
35 FILE *fileHandle
=fopen(fileName
,"wb");
37 prnlog("Failed to write to file '%s'", fileName
);
40 fwrite(data
, 1, datalen
, fileHandle
);
42 prnlog("Saved data to '%s'", fileName
);
49 * Utility function to print to console. This is used consistently within the library instead
50 * of printf, but it actually only calls printf (and adds a linebreak).
51 * The reason to have this method is to
52 * make it simple to plug this library into proxmark, which has this function already to
53 * write also to a logfile. When doing so, just delete this function.
56 void prnlog(char *fmt
, ...)
61 PrintAndLog(fmt
, args
);