Make stdarg an optional header. Some works remain to do to make stdio fully optional

This commit is contained in:
Patrick Pelissier committed 2021-01-10 09:40:37 +01:00
1 parent 3df2408ffb
commit 5f05c1e169
2 files changed
+25 -6

No files matched your search

+13 -1
View File
@@ -29,7 +29,6 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <limits.h> #include <limits.h>
#include <stdarg.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
@@ -44,6 +43,15 @@
# include <stdio.h> # include <stdio.h>
#endif #endif
/* By default, always use stdarg. Can be turned off in specific environement if needed
by defining M_USE_STDARG to 0 */
#ifndef M_USE_STDARG
# define M_USE_STDARG 1
#endif
#if M_USE_STDARG
# include <stdarg.h>
#endif
/***************************************************************/ /***************************************************************/
/************************ Compiler Macro ***********************/ /************************ Compiler Macro ***********************/
@@ -2054,6 +2062,8 @@ M_PARSE_DEFAULT_TYPE_DEF(m_core_parse_ldouble, long double, strtold, )
#endif #endif
#if M_USE_STDARG
/* Define the allocation of the temporary string used by M_CSTR /* Define the allocation of the temporary string used by M_CSTR
Default is 256 bytes (so 255 characters excluding the final null char). Default is 256 bytes (so 255 characters excluding the final null char).
It can be overriden by users if needed. It can be overriden by users if needed.
@@ -2123,6 +2133,8 @@ m_core_snprintf(char *str, size_t size, const char *format, ...)
#endif #endif
#endif // Have stdarg
/************************************************************/ /************************************************************/
/********************* HASH selection ***********************/ /********************* HASH selection ***********************/
+12 -5
View File
@@ -26,11 +26,6 @@
#ifndef MSTARLIB_STRING_H #ifndef MSTARLIB_STRING_H
#define MSTARLIB_STRING_H #define MSTARLIB_STRING_H
#include <ctype.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "m-core.h" #include "m-core.h"
M_BEGIN_PROTECTED_CODE M_BEGIN_PROTECTED_CODE
@@ -909,6 +904,8 @@ string_replace_all (string_t v, const string_t str1, const string_t str2)
} }
} }
#if M_USE_STDARG
/* Format in the string the given printf format */ /* Format in the string the given printf format */
static inline int static inline int
string_vprintf (string_t v, const char format[], va_list args) string_vprintf (string_t v, const char format[], va_list args)
@@ -989,6 +986,10 @@ string_cat_printf (string_t v, const char format[], ...)
return size; return size;
} }
#endif // Have stdarg
#if M_USE_STDIO
/* Get a line/pureline/file from the FILE and store it in the string */ /* Get a line/pureline/file from the FILE and store it in the string */
static inline bool static inline bool
string_fgets(string_t v, FILE *f, string_fgets_t arg) string_fgets(string_t v, FILE *f, string_fgets_t arg)
@@ -1099,6 +1100,8 @@ string_fputs(FILE *f, const string_t v)
return fputs(string_get_cstr(v), f) >= 0; return fputs(string_get_cstr(v), f) >= 0;
} }
#endif // Have stdio
/* Test if the string starts with the given C string */ /* Test if the string starts with the given C string */
static inline bool static inline bool
string_start_with_str_p(const string_t v, const char str[]) string_start_with_str_p(const string_t v, const char str[])
@@ -1260,6 +1263,8 @@ string_get_str(string_t v, const string_t v2, bool append)
STRINGI_CONTRACT (v); STRINGI_CONTRACT (v);
} }
#if M_USE_STDIO
/* Transform the string 'v2' into a formatted string /* Transform the string 'v2' into a formatted string
and output it in the given FILE */ and output it in the given FILE */
static inline void static inline void
@@ -1343,6 +1348,8 @@ string_in_str(string_t v, FILE *f)
return c == '"'; return c == '"';
} }
#endif // Have stdio
/* Read the formatted string from the C string /* Read the formatted string from the C string
and set the converted value in the string 'v'. and set the converted value in the string 'v'.
Return true in case of success Return true in case of success