[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] Created platform.c with replacements for common
From:       Dan Fandrich <dan () coneharvesters ! com>
Date:       2009-10-31 18:19:50
Message-ID: 20091031181949.GA16791 () coneharvesters ! com
[Download RAW message or body]

[Attachment #2 (multipart/signed)]

[Attachment #4 (multipart/mixed)]


On Thu, Oct 29, 2009 at 03:56:35AM +0100, Denys Vlasenko wrote:
> Please send it as attachement, it is damaged (space -> =20 etc).

One man's damaged is another man's escaped :^)  Here is is again.

>>> Dan
-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved

["0001-added-replacements-for-more-functions-that-aren-t-av.patch" (text/x-patch)]

From 16da1ebd0b56fb39e62c32c8704f2bc2da972ee4 Mon Sep 17 00:00:00 2001
From: Dan Fandrich <dan@coneharvesters.com>
Date: Tue, 27 Oct 2009 13:11:10 -0700
Subject: [PATCH] Added replacements for more functions that aren't available everywhere.

Signed-off-by: Dan Fandrich <dan@coneharvesters.com>
---
 TODO               |    7 +----
 include/platform.h |   39 +++++++++++++++++++++++++++++++---
 libbb/platform.c   |   58 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 9 deletions(-)

diff --git a/TODO b/TODO
index 493932a..9be1b07 100644
--- a/TODO
+++ b/TODO
@@ -6,11 +6,8 @@ do one of these bounce an email off the person it's listed under to see if they
 have any suggestions how they plan to go about it, and to minimize conflicts
 between your work and theirs.  But otherwise, all of these are fair game.
 
-Rob Landley suggested these:
-  Add a libbb/platform.c
-    Implement fdprintf() for platforms that haven't got one.
-    Implement bb_realpath() that can handle NULL on non-glibc.
-    Cleanup bb_asprintf()
+Rob Landley suggested this:
+  Implement bb_realpath() that can handle NULL on non-glibc.
 
   Remove obsolete _() wrapper crud for internationalization we don't do.
   Figure out where we need utf8 support, and add it.
diff --git a/include/platform.h b/include/platform.h
index 1fa2ece..9a328f0 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -11,7 +11,12 @@
  * true will #undef them below.
  */
 #define HAVE_FDPRINTF 1
+#define HAVE_MEMRCHR 1
+#define HAVE_MKDTEMP 1
+#define HAVE_SETBIT 1
+#define HAVE_STRCASESTR 1
 #define HAVE_STRCHRNUL 1
+#define HAVE_STRSIGNAL 1
 #define HAVE_VASPRINTF 1
 
 /* Convenience macros to test the version of gcc. */
@@ -340,7 +345,12 @@ typedef unsigned smalluint;
 
 #if defined(__WATCOMC__)
 #undef HAVE_FDPRINTF
+#undef HAVE_MEMRCHR
+#undef HAVE_MKDTEMP
+#undef HAVE_SETBIT
+#undef HAVE_STRCASESTR
 #undef HAVE_STRCHRNUL
+#undef HAVE_STRSIGNAL
 #undef HAVE_VASPRINTF
 #endif
 
@@ -353,16 +363,37 @@ typedef unsigned smalluint;
  * These must come after all the HAVE_* macros are defined (or not)
  */
 
+#ifndef HAVE_FDPRINTF
+extern int fdprintf(int fd, const char *format, ...);
+#endif
+
+#ifndef HAVE_MEMRCHR
+extern void *memrchr(const void *s, int c, size_t n) FAST_FUNC;
+#endif
+
+#ifndef HAVE_MKDTEMP
+extern char *mkdtemp(char *template) FAST_FUNC;
+#endif
+
+#ifndef HAVE_SETBIT
+#define setbit(a,b)	((a)[(b)/8] |= 1<<((b)%8))
+#define clrbit(a,b)	((a)[(b)/8] &= ~(1<<((b)%8)))
+#endif
+
+#ifndef HAVE_STRCASESTR
+extern char *strcasestr(const char *s, const char *pattern) FAST_FUNC;
+#endif
+
 #ifndef HAVE_STRCHRNUL
 extern char *strchrnul(const char *s, int c) FAST_FUNC;
 #endif
 
-#ifndef HAVE_VASPRINTF
-extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC;
+#ifndef HAVE_STRSIGNAL
+extern char *strsignal(int sig) FAST_FUNC;
 #endif
 
-#ifndef HAVE_FDPRINTF
-extern int fdprintf(int fd, const char *format, ...);
+#ifndef HAVE_VASPRINTF
+extern int vasprintf(char **string_ptr, const char *format, va_list p) FAST_FUNC;
 #endif
 
 #endif
diff --git a/libbb/platform.c b/libbb/platform.c
index 470185a..0555563 100644
--- a/libbb/platform.c
+++ b/libbb/platform.c
@@ -38,6 +38,7 @@ int FAST_FUNC vasprintf(char **string_ptr, const char *format, va_list p)
 #endif
 
 #ifndef HAVE_FDPRINTF
+/* dprintf is now actually part of POSIX.1, but was only added in 2008 */
 int fdprintf(int fd, const char *format, ...)
 {
 	va_list p;
@@ -55,3 +56,60 @@ int fdprintf(int fd, const char *format, ...)
 }
 #endif
 
+#ifndef HAVE_MEMRCHR
+/* Copyright (C) 2005 Free Software Foundation, Inc.
+ * memrchr() is a GNU function that might not be available everywhere.
+ * It's basically the inverse of memchr() - search backwards in a
+ * memory block for a particular character.
+ */
+void * FAST_FUNC memrchr(const void *s, int c, size_t n)
+{
+	const unsigned char *start = s, *end = s;
+
+	end += n - 1;
+
+	while (end >= start) {
+		if (*end == c)
+			return (void *) end;
+		else
+			end--;
+	}
+
+	return NULL;
+}
+#endif
+
+#ifndef HAVE_MKDTEMP
+/* This is now actually part of POSIX.1, but was only added in 2008 */
+char * FAST_FUNC mkdtemp(char *template)
+{
+	if (!mktemp(template) || mkdir(template, 0700))
+		return NULL;
+	return template;
+}
+#endif
+
+#ifndef HAVE_STRCASESTR
+/* Copyright (c) 1999, 2000 The ht://Dig Group */
+char * FAST_FUNC strcasestr(const char *s, const char *pattern)
+{
+	int length = strlen(pattern);
+
+	while (*s) {
+		if (strncasecmp(s, pattern, length) == 0)
+			return (char *)s;
+		s++;
+	}
+	return 0;
+}
+#endif
+
+#ifndef HAVE_STRSIGNAL
+/* This is now actually part of POSIX.1, but was only added in 2008 */
+char * FAST_FUNC strsignal(int sig)
+{
+	static char sigbuf[32];
+	snprintf(sigbuf, sizeof(sigbuf), "Signal %d", sig);
+	return sigbuf;
+}
+#endif
-- 
1.5.3.2


[Attachment #8 (application/pgp-signature)]

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic