mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-08-05 13:27:09 +02:00
202 lines
5.5 KiB
Diff
202 lines
5.5 KiB
Diff
Source: https://github.com/troglobit/inadyn/commit/b9edfbfb94b3582cf32dfc04e0dd867ecef2ba92
|
|
|
|
Compilation will fail with GCC-14 due -Wimplicit-function-declaration as error
|
|
https://github.com/troglobit/inadyn/issues/488
|
|
|
|
---
|
|
|
|
Refactor mkpath() to drop all uses of strdupa()
|
|
Fixes #488
|
|
|
|
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
|
|
|
|
--- inadyn-2.12.0-origin/include/Makefile.am
|
|
+++ inadyn-2.12.0/include/Makefile.am
|
|
@@ -5,4 +5,4 @@
|
|
jsmn.h json.h log.h \
|
|
md5.h os.h plugin.h \
|
|
queue.h sha1.h ssl.h \
|
|
- strdupa.h tcp.h
|
|
+ tcp.h
|
|
--- inadyn-2.12.0-origin/include/compat.h
|
|
+++ inadyn-2.12.0/include/compat.h
|
|
@@ -29,14 +29,14 @@
|
|
#include <unistd.h>
|
|
#include <sys/param.h> /* MAX(), isset(), setbit(), TRUE, FALSE, et consortes. :-) */
|
|
#include <sys/types.h>
|
|
-#include "strdupa.h"
|
|
|
|
/* From The Practice of Programming, by Kernighan and Pike */
|
|
#ifndef NELEMS
|
|
#define NELEMS(array) (sizeof(array) / sizeof(array[0]))
|
|
#endif
|
|
|
|
-int mkpath (char *dir, mode_t mode);
|
|
+int mkpath (const char *dir, mode_t mode);
|
|
+int makepath (const char *dir);
|
|
|
|
#ifndef pidfile
|
|
int pidfile (const char *basename);
|
|
--- inadyn-2.12.0-origin/include/strdupa.h
|
|
+++ /dev/null
|
|
@@ -1,52 +0,0 @@
|
|
-/* ==========================================================================
|
|
- * strdupa.h - Re-implementation of glibc strdupa.
|
|
- * --------------------------------------------------------------------------
|
|
- * Copyright (c) 2009 William Ahern
|
|
- *
|
|
- * Permission is hereby granted, free of charge, to any person obtaining a
|
|
- * copy of this software and associated documentation files (the
|
|
- * "Software"), to deal in the Software without restriction, including
|
|
- * without limitation the rights to use, copy, modify, merge, publish,
|
|
- * distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
- * persons to whom the Software is furnished to do so, subject to the
|
|
- * following conditions:
|
|
- *
|
|
- * The above copyright notice and this permission notice shall be included
|
|
- * in all copies or substantial portions of the Software.
|
|
- *
|
|
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
- * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
- * ==========================================================================
|
|
- */
|
|
-#ifndef LITE_STRDUPA_H
|
|
-#define LITE_STRDUPA_H
|
|
-
|
|
-#if !defined(HAVE_STRDUPA)
|
|
-#if defined(strdupa)
|
|
-#define HAVE_STRDUPA 1
|
|
-#endif
|
|
-#endif
|
|
-
|
|
-#if !HAVE_STRDUPA
|
|
-#if defined(__GNUC__)
|
|
-#include <stddef.h> /* size_t */
|
|
-#include <string.h> /* memcpy(3) strlen(3) */
|
|
-
|
|
-#define strdupa(src) (__extension__ ({ \
|
|
- size_t len_ = strlen(src); \
|
|
- char *dst_ = __builtin_alloca(len_ + 1); \
|
|
- dst_[len_] = '\0'; \
|
|
- (char *)memcpy(dst_, src, len_); \
|
|
-}))
|
|
-
|
|
-#else /* If not GCC, e.g. Clang */
|
|
-#error strdupa() may use an unsupported GNU C API, please forward any fix to maintainer, cheers!
|
|
-#endif /* __GNUC__ */
|
|
-#endif /* !HAVE_STRDUPA */
|
|
-
|
|
-#endif /* LITE_STRDUPA_H */
|
|
--- inadyn-2.12.0-origin/src/makepath.c
|
|
+++ inadyn-2.12.0/src/makepath.c
|
|
@@ -1,6 +1,6 @@
|
|
/* mkpath() -- Create all components leading up to a given directory
|
|
*
|
|
- * Copyright (c) 2013-2021 Joachim Wiberg <troglobit@gmail.com>
|
|
+ * Copyright (c) 2013-2024 Joachim Wiberg <troglobit@gmail.com>
|
|
*
|
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,11 +16,35 @@
|
|
*/
|
|
|
|
#include <errno.h>
|
|
-#include <libgen.h>
|
|
-#include <sys/stat.h>
|
|
-#include <sys/types.h>
|
|
+#include <string.h> /* strdup(), strrchr() */
|
|
+#include <stdlib.h> /* free() */
|
|
+#include <sys/stat.h> /* mkdir() */
|
|
+
|
|
#include "compat.h"
|
|
|
|
+/* Recursively create directories */
|
|
+static int _mkpath(char *dir, mode_t mode)
|
|
+{
|
|
+ char *slash;
|
|
+
|
|
+ if (!mkdir(dir, mode) || errno == EEXIST)
|
|
+ return 0;
|
|
+
|
|
+ if (errno != ENOENT)
|
|
+ return -1;
|
|
+
|
|
+ slash = strrchr(dir, '/');
|
|
+ if (!slash)
|
|
+ return -1;
|
|
+
|
|
+ *slash = 0;
|
|
+ if (_mkpath(dir, mode) == -1)
|
|
+ return -1;
|
|
+
|
|
+ *slash = '/';
|
|
+ return mkdir(dir, mode);
|
|
+}
|
|
+
|
|
/**
|
|
* mkpath - Like makepath() but takes a mode_t argument
|
|
* @dir: Directory to created, relative or absolute
|
|
@@ -29,21 +53,24 @@
|
|
* Returns:
|
|
* POSIX OK(0) on success, otherwise -1 with @errno set.
|
|
*/
|
|
-int mkpath(char *dir, mode_t mode)
|
|
+int mkpath(const char *dir, mode_t mode)
|
|
{
|
|
- struct stat sb;
|
|
+ char *_dir;
|
|
+ int rc;
|
|
|
|
if (!dir) {
|
|
errno = EINVAL;
|
|
return 1;
|
|
}
|
|
|
|
- if (!stat(dir, &sb))
|
|
- return 0;
|
|
+ _dir = strdup(dir);
|
|
+ if (!_dir)
|
|
+ return -1;
|
|
|
|
- mkpath(dirname(strdupa(dir)), mode);
|
|
+ rc = _mkpath(_dir, mode);
|
|
+ free(_dir);
|
|
|
|
- return mkdir(dir, mode);
|
|
+ return rc;
|
|
}
|
|
|
|
/**
|
|
@@ -56,14 +83,7 @@
|
|
* fails allocating temporary memory. For other error codes see the
|
|
* mkdir() syscall description.
|
|
*/
|
|
-int makepath(char *dir)
|
|
+int makepath(const char *dir)
|
|
{
|
|
return mkpath(dir, 0777);
|
|
}
|
|
-
|
|
-/**
|
|
- * Local Variables:
|
|
- * indent-tabs-mode: t
|
|
- * c-file-style: "linux"
|
|
- * End:
|
|
- */
|
|
--- inadyn-2.12.0-origin/src/os.c
|
|
+++ inadyn-2.12.0/src/os.c
|
|
@@ -266,7 +266,7 @@
|
|
}
|
|
}
|
|
|
|
- pidfile_dir = dirname(strdupa(pidfn));
|
|
+ pidfile_dir = dirname(pidfn);
|
|
if (access(pidfile_dir, F_OK)) {
|
|
if (mkpath(pidfile_dir, 0755) && errno != EEXIST)
|
|
logit(LOG_ERR, "No write permission to %s, aborting.", pidfile_dir);
|