+hTab *
+getRuntimeVariables(void)
+{
+ return _mainValues;
+}
+
+
+/* strncpy() with guaranteed NULL termination. */
+char *strncpyz(char *dest, const char *src, size_t n)
+{
+ assert(n > 0);
+
+ --n;
+ /* paranoia... */
+ if (strlen(src) > n)
+ {
+ fprintf(stderr, "strncpyz prevented buffer overrun!\n");
+ }
+
+ strncpy(dest, src, n);
+ dest[n] = 0;
+ return dest;
+}
+
+/* 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)
+{
+ size_t maxToCopy;
+ size_t destLen = strlen(dest);
+
+ assert(n > 0);
+ assert(n > destLen);
+
+ maxToCopy = n - destLen - 1;
+
+ /* paranoia... */
+ if (strlen(src) + destLen >= n)
+ {
+ fprintf(stderr, "strncatz prevented buffer overrun!\n");
+ }
+
+ strncat(dest, src, maxToCopy);
+ dest[n - 1] = 0;
+ return dest;
+}
+
+
+/*-----------------------------------------------------------------*/
+/* getBuildNumber - return build number */
+/*-----------------------------------------------------------------*/
+const char *getBuildNumber(void)
+{
+ return (SDCC_BUILD_NUMBER);
+}
+
+#if defined(HAVE_VSNPRINTF) || defined(HAVE_VSPRINTF)
+size_t SDCCsnprintf(char *dst, size_t n, const char *fmt, ...)
+{
+ va_list args;
+ int len;
+
+ va_start(args, fmt);
+
+# if defined(HAVE_VSNPRINTF)
+ len = vsnprintf(dst, n, fmt, args);
+# else
+ vsprintf(dst, fmt, args);
+ len = strlen(dst) + 1;
+# endif
+
+ va_end(args);
+
+ /* on some gnu systems, vsnprintf returns -1 if output is truncated.
+ * In the C99 spec, vsnprintf returns the number of characters that
+ * would have been written, were space available.
+ */
+ if ((len < 0) || (size_t) len >= n) {
+ fprintf(stderr, "internal error: sprintf truncated.\n");
+ }
+
+ return len;
+}
+#endif
+
+/** Pragma tokenizer
+ */
+void
+init_pragma_token(struct pragma_token_s *token)
+{
+ dbuf_init(&token->dbuf, 16);
+ token->type = TOKEN_UNKNOWN;
+}
+
+char *
+get_pragma_token(const char *s, struct pragma_token_s *token)
+{
+ dbuf_set_length(&token->dbuf, 0);
+
+ /* skip leading spaces */
+ while ('\n' != *s && isspace(*s))
+ ++s;
+
+ if ('\0' == *s || '\n' == *s)
+ {
+ token->type = TOKEN_EOL;
+ }
+ else
+ {
+ char *end;
+
+ long val = strtol(s, &end, 0);
+
+ if (end != s && ('\0' == *end || isspace(*end)))
+ {
+ token->val.int_val = val;
+ token->type = TOKEN_INT;
+ dbuf_append(&token->dbuf, s, end - s);
+ s = end;
+ }
+ else
+ {
+ while ('\0' != *s && !isspace(*s))
+ {
+ dbuf_append_char(&token->dbuf, *s);
+ ++s;
+ }
+
+ token->type = TOKEN_STR;
+ }
+ }
+
+ return (char *)s;
+}
+
+const char *
+get_pragma_string(struct pragma_token_s *token)
+{
+ return dbuf_c_str(&token->dbuf);
+}
+
+void
+free_pragma_token(struct pragma_token_s *token)
+{
+ dbuf_destroy(&token->dbuf);
+}