mirror of
https://github.com/nfc-tools/libnfc.git
synced 2026-04-11 17:16:18 +00:00
New str_nfc_target() function in API.
This allow to convert a nfc_target struct into allocated string.
This commit is contained in:
18
libnfc/nfc.c
18
libnfc/nfc.c
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user