robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

zeertzjqvim-patch:9.2.0743: string macros silently accept a size of the wrong type (#40470)204774c1e2

master
1.9 KiB64 linesraw
1#pragma once
2
3#include <stdarg.h>  // IWYU pragma: keep
4#include <string.h>
5
6#include "auto/config.h"
7#include "nvim/api/private/defs.h"  // IWYU pragma: keep
8#include "nvim/eval/typval_defs.h"  // IWYU pragma: keep
9#include "nvim/os/os_defs.h"
10#include "nvim/types_defs.h"  // IWYU pragma: keep
11
12// Return the length of a string literal
13#define STRLEN_LITERAL(s) (sizeof(s) - 1)
14
15/// Store a key/value pair
16typedef struct {
17  int key;        ///< the key
18  char *value;    ///< the value string
19  size_t length;  ///< length of the value string
20} keyvalue_T;
21
22#define KEYVALUE_ENTRY(k, v) { (k), (v), STRLEN_LITERAL(v) }
23
24#include "strings.h.generated.h"
25#include "strings.h.inline.generated.h"
26
27/// Append string to string and return pointer to the next byte
28///
29/// Unlike strcat, this one does *not* add NUL byte and returns pointer to the
30/// past of the added string.
31///
32/// @param[out]  dst  String to append to.
33/// @param[in]  src  String to append.
34///
35/// @return pointer to the byte just past the appended byte.
36static inline char *strappend(char *const dst, const char *const src)
37  FUNC_ATTR_ALWAYS_INLINE FUNC_ATTR_NONNULL_ALL
38    FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT
39{
40  const size_t src_len = strlen(src);
41  return (char *)memmove(dst, src, src_len) + src_len;
42}
43
44#ifdef HAVE_STRCASECMP
45# define STRICMP(d, s)      strcasecmp((char *)(d), (char *)(s))
46#else
47# ifdef HAVE_STRICMP
48#  define STRICMP(d, s)     stricmp((char *)(d), (char *)(s))
49# else
50#  define STRICMP(d, s)     vim_stricmp((char *)(d), (char *)(s))
51# endif
52#endif
53
54#ifdef HAVE_STRNCASECMP
55# define STRNICMP(d, s, n)  strncasecmp((char *)(d), (char *)(s), (n))
56#else
57# ifdef HAVE_STRNICMP
58#  define STRNICMP(d, s, n) strnicmp((char *)(d), (char *)(s), (n))
59# else
60#  define STRNICMP(d, s, n) vim_strnicmp((char *)(d), (char *)(s), (n))
61# endif
62#endif
63
64#define kv_printf(v, ...) kv_do_printf(&(v), __VA_ARGS__)