[asterisk-commits] Replace strdupa with more portable ast strdupa (asterisk[13])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Aug 1 15:36:50 CDT 2016


Anonymous Coward #1000019 has submitted this change and it was merged.

Change subject: Replace strdupa with more portable ast_strdupa
......................................................................


Replace strdupa with more portable ast_strdupa

The strdupa function is a GNU extension, and not widely portable. We
have an ast_strdupa function used within Asterisk which is preferred.
I pulled the definition up from menuselect.c into the menuselect.h
header file so it can be shared across menuselect.

Change-Id: I9593c97f78386b47dc1e83201e80cb2f62b36c2e
---
M menuselect/menuselect.c
M menuselect/menuselect.h
M menuselect/menuselect_curses.c
3 files changed, 13 insertions(+), 13 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/menuselect/menuselect.c b/menuselect/menuselect.c
index efae311..f6a7fb3 100644
--- a/menuselect/menuselect.c
+++ b/menuselect/menuselect.c
@@ -103,18 +103,6 @@
 };
 AST_LIST_HEAD_NOLOCK_STATIC(deps_file, dep_file);
 
-#if !defined(ast_strdupa) && defined(__GNUC__)
-#define ast_strdupa(s)                                                    \
-	(__extension__                                                    \
-	({                                                                \
-		const char *__old = (s);                                  \
-		size_t __len = strlen(__old) + 1;                         \
-		char *__new = __builtin_alloca(__len);                    \
-		memcpy (__new, __old, __len);                             \
-		__new;                                                    \
-	}))
-#endif
-
 /*! \brief return a pointer to the first non-whitespace character */
 static inline char *skip_blanks(char *str)
 {
diff --git a/menuselect/menuselect.h b/menuselect/menuselect.h
index 7b3fe26..328ac9a 100644
--- a/menuselect/menuselect.h
+++ b/menuselect/menuselect.h
@@ -162,4 +162,16 @@
 	return (!s || (*s == '\0'));
 }
 
+#if !defined(ast_strdupa) && defined(__GNUC__)
+#define ast_strdupa(s)                                                    \
+	(__extension__                                                    \
+	({                                                                \
+		const char *__old = (s);                                  \
+		size_t __len = strlen(__old) + 1;                         \
+		char *__new = __builtin_alloca(__len);                    \
+		memcpy (__new, __old, __len);                             \
+		__new;                                                    \
+	}))
+#endif
+
 #endif /* MENUSELECT_H */
diff --git a/menuselect/menuselect_curses.c b/menuselect/menuselect_curses.c
index e799574..260cf69 100644
--- a/menuselect/menuselect_curses.c
+++ b/menuselect/menuselect_curses.c
@@ -211,7 +211,7 @@
 
 	if (mem->displayname) {
 		char buf[maxlen + 1];
-		char *displayname = strdupa(mem->displayname);
+		char *displayname = ast_strdupa(mem->displayname);
 		char *word;
 		int current_line = 1;
 		int new_line = 1;

-- 
To view, visit https://gerrit.asterisk.org/3383
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9593c97f78386b47dc1e83201e80cb2f62b36c2e
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: David M. Lee <dlee at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-commits mailing list