Permalink
Browse files

* Added wrapper for snprintf.

* Changed wrappers from nstring to not call function if not necessary.
  • Loading branch information...
1 parent 2f3ca6d commit fbef471f87ee6ddfb63e50755dacbe87e4bfae16 @bobbens committed Feb 25, 2012
Showing with 29 additions and 6 deletions.
  1. +19 −6 src/nstring.c
  2. +10 −0 src/nstring.h
View
@@ -12,8 +12,6 @@
#include "naev.h"
-#include <string.h>
-
#include "log.h"
@@ -65,11 +63,9 @@ const char *nstrnstr( const char *haystack, const char *needle, size_t size )
* @param needle String to find.
* @return Pointer in haystack where needle was found or NULL if not found.
*/
+#if !HAS_POSIX
const char *nstrcasestr( const char *haystack, const char *needle )
{
-#if HAS_POSIX
- return strcasestr( haystack, needle );
-#else /* HAS_POSIX */
size_t hay_len, needle_len;
/* Get lengths. */
@@ -86,8 +82,25 @@ const char *nstrcasestr( const char *haystack, const char *needle )
}
return NULL;
-#endif /* HAS_POSIX */
}
+#endif /* !HAS_POSIX */
+
+
+/**
+ * @brief snprintf wrapper.
+ */
+#if !HAS_POSIX
+int nsnprintf( char *text, size_t maxlen, const char *fmt, ... )
+{
+ va_list ap;
+ int retval;
+ va_start(ap, fmt);
+ retval = vsnprintf(text, maxlen, fmt, ap);
+ va_end(ap);
+
+ return retval;
+}
+#endif /* !HAS_POSIX */
View
@@ -8,10 +8,20 @@
#include <stdlib.h>
+#include <string.h>
+
+#include <ncompat.h>
const char *nstrnstr( const char *haystack, const char *needle, size_t size );
+#if HAS_POSIX
+#define nstrcasestr strcasestr
+#define nsnprintf snprintf
+#else /* HAVE_POSIX */
const char *nstrcasestr( const char *haystack, const char *needle );
+int nsnprintf( char *text, size_t maxlen, const char *fmt, ... );
+#endif /* HAVE_POSIX */
+
#endif /* NSTRING_H */

0 comments on commit fbef471

Please sign in to comment.