New str_nfc_target() function in API.

This allow to convert a nfc_target struct into allocated string.
This commit is contained in:
Romuald Conty
2012-09-17 13:47:54 +00:00
parent 82e3416619
commit 310d7eba07
13 changed files with 726 additions and 622 deletions

View File

@@ -78,6 +78,7 @@
#include <nfc/nfc.h>
#include "nfc-internal.h"
#include "target-subr.h"
#include "drivers.h"
#define LOG_CATEGORY "libnfc.general"
@@ -1152,3 +1153,20 @@ str_nfc_modulation_type(const nfc_modulation_type nmt)
// Should never go there..
return "";
}
/** @ingroup string-converter
* @brief Convert \a nfc_modulation_type value to string
* @return Upon successful return, this function returns the number of characters printed (excluding the null byte used to end output to strings), otherwise returns libnfc's error code (negative value)
* @param nt \a nfc_target struct to print
* @param buf pointer where string will be allocated, then nfc target information printed
*
* @warning *buf must be freed.
*/
int
str_nfc_target(char **buf, const nfc_target nt, bool verbose)
{
*buf = malloc(4096);
(*buf)[0] = '\0';
sprint_nfc_target(*buf, nt, verbose);
return strlen(*buf);
}