-#include <stdio.h>
-#include <stdarg.h>
-#include <stddef.h>
-#include <errno.h>
-
-/**
- * Safer version of snprintf that writes up to buflen characters to
- * the output buffer and ensures that the resultant string is null-terminated,
- * that is, it writes at most buflen-1 actual string characters to buffer. The
- * return value is the number of characters which should be written to the
- * buffer, so string truncation can be detected by the caller by checking if
- * the return value is greater than or equal to the buflen.
- *
- * @param buffer
- * The buffer into which the output is to be written
- *
- * @param buflen
- * The size of the output buffer
- *
- * @param format
- * The format string to be printed to the buffer
- *
- * @return
- * The number of characters written to the buffer, or if the string has been
- * truncated, the number of characters which would have been written had the
- * buffer been sufficiently big.
- *
- */
-static inline int
-rte_snprintf(char *buffer, int buflen, const char *format, ...)
-{
- int len;
- va_list ap;
-
- if (buffer == NULL && buflen != 0)
- goto einval_error;
- if (format == NULL) {
- if (buflen > 0)
- buffer[0] = '\0';
- goto einval_error;
- }
-
- va_start(ap, format);
- len = vsnprintf(buffer, buflen, format, ap);
- va_end(ap);
- if (len >= buflen && buflen > 0)
- buffer[buflen - 1] = '\0';
-
- return len;
-
-einval_error:
- errno = EINVAL;
- return -1;
-}
-
-