]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/loclass/fileutils.c
9 * @brief checks if a file exists
13 int fileExists(const char *filename
) {
15 int result
= stat(filename
, &st
);
19 int saveFile(const char *preferredName
, const char *suffix
, const void* data
, size_t datalen
)
21 int size
= sizeof(char) * (strlen(preferredName
)+strlen(suffix
)+10);
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 PrintAndLog("Failed to write to file '%s'", fileName
);
41 fwrite(data
, 1, datalen
, fileHandle
);
43 PrintAndLog(">Saved data to '%s'", fileName
);
51 * Utility function to print to console. This is used consistently within the library instead
52 * of printf, but it actually only calls printf (and adds a linebreak).
53 * The reason to have this method is to
54 * make it simple to plug this library into proxmark, which has this function already to
55 * write also to a logfile. When doing so, just delete this function.
58 void prnlog(char *fmt
, ...)
63 PrintAndLog(fmt
, args
);