-/* Utility definitions for C code of SXEmacs
+/* Utility definitions for C code of SXEmacs
Copyright (C) 1985-1987, 1992-1995 Free Software Foundation, Inc.
Copyright (C) 1993-1996 Richard Mlynarik.
#ifndef PRINTF_ARGS
# if defined (__GNUC__) && (__GNUC__ >= 2)
# define PRINTF_ARGS(string_index,first_to_check) \
- __attribute__ ((format (printf, string_index, first_to_check)))
+ __attribute__ ((format (printf, string_index, first_to_check)))
# else
# define PRINTF_ARGS(string_index,first_to_check)
# endif /* GNUC */
# if ((__GNUC__ > 2) || (__GNUC__ == 2) && (__GNUC_MINOR__ >= 5))
# define DOESNT_RETURN void
# define DECLARE_DOESNT_RETURN(decl) \
- extern void decl __attribute__ ((noreturn))
+ extern void decl __attribute__ ((noreturn))
# define DECLARE_DOESNT_RETURN_GCC_ATTRIBUTE_SYNTAX_SUCKS(decl,str,idx) \
/* Should be able to state multiple independent __attribute__s, but \
- the losing syntax doesn't work that way, and screws losing cpp */ \
- extern void decl \
- __attribute__ ((noreturn, format (printf, str, idx)))
+ the losing syntax doesn't work that way, and screws losing cpp */ \
+ extern void decl \
+ __attribute__ ((noreturn, format (printf, str, idx)))
# else
# define DOESNT_RETURN void volatile
# define DECLARE_DOESNT_RETURN(decl) extern void volatile decl
# define DECLARE_DOESNT_RETURN_GCC_ATTRIBUTE_SYNTAX_SUCKS(decl,str,idx) \
- extern void volatile decl PRINTF_ARGS(str,idx)
+ extern void volatile decl PRINTF_ARGS(str,idx)
# endif /* GNUC 2.5 */
# else
# define DOESNT_RETURN void
# define DECLARE_DOESNT_RETURN(decl) extern void decl
# define DECLARE_DOESNT_RETURN_GCC_ATTRIBUTE_SYNTAX_SUCKS(decl,str,idx) \
- extern void decl PRINTF_ARGS(str,idx)
+ extern void decl PRINTF_ARGS(str,idx)
# endif /* GNUC */
#endif
# endif /* ERROR_CHECK_MALLOC */
#endif /* BDWGC */
+\f
+/* str funs */
+#define xstrlen strlen
+#define xstrcmp strcmp
+#define xstrncmp strncmp
+#define xstrncat strncat
+
+extern_inline char*
+xstrncpy(char* target, const char*source, size_t len)
+ __attribute__((always_inline));
+extern_inline char*
+xstrncpy(char* target, const char*source, size_t len)
+{
+ *target ='\0';
+ return strncat(target,source,len-1);
+}
+
+#if !defined(FORBID_STRCPY)
+# define xstrcat strcat
+# define xstrcpy strcpy
+# if defined(HAVE_STPCPY)
+# define xstpcpy stpcpy
+# else
+extern_inline char*
+xstpcpy(char *target, const char *source)
+ __attribute__((always_inline));
+extern_inline char*
+xstpcpy(char *target, const char *source)
+{
+ char *p = target;
+ size_t len = xstrlen(source);
+
+ strcpy(target, source);
+ p += len;
+ return p;
+}
+# endif
+#else
+# if defined(strcpy)
+# undef strcpy
+# endif
+# define strcpy no_strcpy
+extern_inline char*
+no_strcpy(char*,const char*)
+ __attribute__((always_inline));
+extern_inline char*
+no_strcpy(char * SXE_UNUSED(target),const char * SXE_UNUSED(source))
+{
+ assert(0);
+ return NULL;
+}
+# if defined(strcat)
+# undef strcat
+# endif
+# define strcat no_strcat
+extern_inline char*
+no_strcat(char*,const char*)
+ __attribute__((always_inline));
+extern_inline char*
+no_strcat(char * SXE_UNUSED(target), const char* SXE_UNUSED(source))
+{
+ assert(0);
+ return NULL;
+}
+# if defined(stpcpy)
+# undef stpcpy
+# endif
+# define stpcpy no_stpcpy
+# define xstpcpy no_stpcpy
+extern_inline char*
+no_stpcpy(char*,const char*)
+ __attribute__((always_inline));
+extern_inline char*
+no_stpcpy(char* SXE_UNUSED(target),const char* SXE_UNUSED(source))
+{
+ assert(0);
+ return NULL;
+}
+#endif
+
+
+#if defined HAVE_STPNCPY
+# define xstpncpy stpncpy
+#else
+extern_inline char*
+xstpncpy(char *target, const char *source, size_t len)
+ __attribute__((always_inline));
+extern_inline char*
+xstpncpy(char *target, const char *source, size_t len)
+{
+ char *p = target;
+ xstrncpy(target, source, len);
+ p += len;
+ return p;
+}
+#endif /* !HAVE_STPNCPY */
+
+#define xmemcmp memcmp
+#define xmemcpy memcpy
+
+
+
+extern_inline size_t
+xmin_size_t(size_t a, size_t b)
+ __attribute__((always_inline));
+extern_inline size_t
+xmin_size_t(size_t a, size_t b)
+{
+ if (a < b) {
+ return a;
+ } else {
+ return b;
+ }
+}
+
#endif