Skip to content

Commit 0eeb73f

Browse files
committed
Centralize the definitionof strndupa
1 parent 248524f commit 0eeb73f

3 files changed

Lines changed: 12 additions & 22 deletions

File tree

auparse/auparse.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,17 +1199,6 @@ static int str2event(char *s, au_event_t *e)
11991199
return 0;
12001200
}
12011201

1202-
#ifndef HAVE_STRNDUPA
1203-
#define strndupa(s, n) \
1204-
({ \
1205-
const char *__old = (s); \
1206-
size_t __len = strnlen (__old, (n)); \
1207-
char *__new = (char *) alloca(__len + 1); \
1208-
__new[__len] = '\0'; \
1209-
(char *) memcpy (__new, __old, __len); \
1210-
})
1211-
#endif
1212-
12131202
/* Returns 0 on success and 1 on error */
12141203
static int extract_timestamp(const char *b, au_event_t *e)
12151204
{

common/common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#ifndef AUDIT_COMMON_HEADER
2424
#define AUDIT_COMMON_HEADER
2525

26+
#include "config.h"
2627
#include <limits.h> /* POSIX_HOST_NAME_MAX */
2728
#ifdef HAVE_ATOMIC
2829
#include <stdatomic.h>
@@ -46,6 +47,17 @@
4647
// Used in auditd-event.c and audisp.c to size buffers for formatting
4748
#define FORMAT_BUF_LEN (MAX_AUDIT_MESSAGE_LENGTH + _POSIX_HOST_NAME_MAX)
4849

50+
#ifndef HAVE_STRNDUPA
51+
#define strndupa(s, n) \
52+
({ \
53+
const char *__old = (s); \
54+
size_t __len = strnlen (__old, (n)); \
55+
char *__new = (char *) alloca(__len + 1); \
56+
__new[__len] = '\0'; \
57+
(char *) memcpy (__new, __old, __len); \
58+
})
59+
#endif
60+
4961
AUDIT_HIDDEN_START
5062

5163
char *audit_strsplit_r(char *s, char **savedpp);

src/ausearch-lol.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,6 @@ static int compare_event_time(event *e1, event *e2)
162162
return 0;
163163
}
164164

165-
#ifndef HAVE_STRNDUPA
166-
#define strndupa(s, n) \
167-
({ \
168-
const char *__old = (s); \
169-
size_t __len = strnlen (__old, (n)); \
170-
char *__new = (char *) alloca(__len + 1); \
171-
__new[__len] = '\0'; \
172-
(char *) memcpy (__new, __old, __len); \
173-
})
174-
#endif
175-
176165
/*
177166
* This function will look at the line and pick out pieces of it.
178167
*/

0 commit comments

Comments
 (0)