Arduino DLNA Server
Loading...
Searching...
No Matches
Printf.h
Go to the documentation of this file.
1#pragma once
2#include "Print.h"
3#include "dlna_config.h"
4namespace tiny_dlna {
5
12class Printf {
13 public:
14 Printf(Print& out) { p_print = &out; }
15
16 size_t printf(const char* fmt, ...) {
17 char buf[MAX_PRINTF_SIZE];
18 va_list args;
19 va_start(args, fmt);
20 int n = vsnprintf(buf, sizeof(buf), fmt, args);
21 va_end(args);
22 if (n <= 0) return 0;
23 // vsnprintf returns the number of characters that would have been
24 // written if the buffer were large enough. Assert buffer was sufficient.
25 assert(n < (int)sizeof(buf));
26 int toWrite = n;
27 if (toWrite >= (int)sizeof(buf)) toWrite = (int)sizeof(buf) - 1;
28 // Return the actual bytes written by the Print object (which may expand
29 // characters when using wrappers like EscapingPrint)
30 size_t written = p_print->write((const uint8_t*)buf, (size_t)toWrite);
31 return written;
32 }
33
34 protected:
35 Print* p_print = nullptr;
36};
37
38} // namespace tiny_dlna
Printf support with output to Print. This class does not do any heap allocations!
Definition: Printf.h:12
Printf(Print &out)
Definition: Printf.h:14
Print * p_print
Definition: Printf.h:35
size_t printf(const char *fmt,...)
Definition: Printf.h:16
#define MAX_PRINTF_SIZE
Max printf buffer size.
Definition: dlna_config.h:50
Definition: Allocator.h:13