diff libcore/core/util.h @ 236:4896bb07a8db

core: add pprintf function
author David Demelier <markand@malikania.fr>
date Fri, 27 Nov 2020 13:31:16 +0100
parents c89e2f7dbc01
children
line wrap: on
line diff
--- a/libcore/core/util.h	Thu Nov 26 18:00:45 2020 +0100
+++ b/libcore/core/util.h	Fri Nov 27 13:31:16 2020 +0100
@@ -50,6 +50,21 @@
 delay(unsigned int ms);
 
 /**
+ * Construct a temporary path to a file that can fit in a PATH_MAX array.
+ *
+ * This function is useful when specifying paths into a function invocation such
+ * as `fopen(pprintf("%s.png", i), "r"))`.
+ *
+ * \pre fmt != NULL
+ * \param fmt the format string
+ * \warning This function is not reentrant, it returns a static storage path.
+ * \return A non null path to a file.
+ * \post Returned string is never NULL.
+ */
+const char *
+pprintf(const char *fmt, ...);
+
+/**
  * Generate a random number between lower and upper (included).
  *
  * \pre upper must be <= RAND_MAX