summaryrefslogtreecommitdiffstats
path: root/cygwin-1.7.9-strdupa.patch
blob: d1ec29ef61ff20e5b7a0c69f010ef4953c8ce436 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/string.h,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- src/newlib/libc/include/string.h	2011/05/25 18:41:10	1.28
+++ src/newlib/libc/include/string.h	2011/06/10 18:30:38	1.29
@@ -96,6 +96,20 @@
 int     _EXFUN(strtosigno, (const char *__name));
 #endif
 
+#if defined _GNU_SOURCE && defined __GNUC__
+#define strdupa(__s) \
+	(__extension__ ({const char *__in = (__s); \
+			 size_t __len = strlen (__in) + 1; \
+			 char * __out = (char *) __builtin_alloca (__len); \
+			 (char *) memcpy (__out, __in, __len);}))
+#define strndupa(__s, __n) \
+	(__extension__ ({const char *__in = (__s); \
+			 size_t __len = strnlen (__in, (__n)) + 1; \
+			 char *__out = (char *) __builtin_alloca (__len); \
+			 __out[__len-1] = '\0'; \
+			 (char *) memcpy (__out, __in, __len-1);}))
+#endif /* _GNU_SOURCE && __GNUC__ */
+
 /* These function names are used on Windows and perhaps other systems.  */
 #ifndef strcmpi
 #define strcmpi strcasecmp