* Makefile.common.in: unused PORT, SCC and SAS removed, fixed docdir
[fw/sdcc] / src / SDCCutil.h
index 7d8f1e2b3c7420c21cf2e22fb7b05f3b2d1c7a20..ad9a1a4c9e38401ffa555dbf2792f222992d3218 100644 (file)
@@ -26,9 +26,7 @@
 #define SDCCUTIL_H
 
 #include "SDCChasht.h"
-
-/* PENDING: Hacks as I can't work autoconf */
-#define BINDIR PREFIX "/bin"
+#include <stdarg.h>
 
 /** Given an array of name, value string pairs creates a new hash
     containing all of the pairs.
@@ -74,7 +72,7 @@ void setMainValue (const char *pname, const char *pvalue);
 
 void populateMainValues (const char **ppin);
 
-void buildCmdLine2 (char *pbuffer, const char *pcmd);
+void buildCmdLine2 (char *pbuffer, const char *pcmd, size_t len);
 
 /** Returns true if sz starts with the string given in key.
  */
@@ -85,5 +83,43 @@ bool startsWith (const char *sz, const char *key);
 */
 void chomp (char *sz);
 
+hTab *
+getRuntimeVariables(void);
+
+/* strncpy() with guaranteed NULL termination. */
+char *strncpyz(char *dest, const char *src, size_t n);
+
+/* like strncat() with guaranteed NULL termination
+ * The passed size should be the size of the dest buffer, not the number of 
+ * bytes to copy.
+ */
+char *strncatz(char *dest, const char *src, size_t n);
+
+/* snprintf, by hook or by crook. */
+size_t SDCCsnprintf(char *, size_t, const char *, ...);
+
+# if defined(HAVE_VSNPRINTF)
+
+// best option: we can define our own snprintf which logs errors.
+#  define SNPRINTF SDCCsnprintf
+
+# elif defined(HAVE_SPRINTF)
+
+// if we can't build a safe snprintf for lack of vsnprintf but there
+// is a native snprintf, use it.
+#  define SNPRINTF snprintf
+
+# elif defined(HAVE_VSPRINTF)
+
+// we can at least define our own unsafe version.
+#  define SNPRINTF SDCCsnprintf
+
+# else
+// We don't have a native snprintf nor the functions we need to write one.
+#  error "Need at least one of snprintf, vsnprintf, vsprintf!"
+# endif
+
+
+
 #endif