-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
util/SPrintf: wrapper for snprintf()
- Loading branch information
1 parent
ef7c111
commit c754835
Showing
3 changed files
with
37 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
// author: Max Kellermann <[email protected]> | ||
|
||
#pragma once | ||
|
||
#include <span> | ||
|
||
#include <stdio.h> | ||
|
||
template<typename... Args> | ||
static inline std::string_view | ||
SPrintf(std::span<char> buffer, const char *fmt, Args&&... args) noexcept | ||
{ | ||
int length = snprintf(buffer.data(), buffer.size(), fmt, args...); | ||
if (length < 0) | ||
return {}; | ||
|
||
return {buffer.data(), static_cast<std::size_t>(length)}; | ||
} |