aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2020-10-09 11:46:35 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2020-10-09 11:46:35 +0100
commitcca0d7f15b7197095cd587420d31b187620c3093 (patch)
treef46335b950abbf7a35641f327efca49dedd0a688
parent07141f919dc8582460f984ed1d2fb73e05f82ef3 (diff)
downloadpseudo-cca0d7f15b7197095cd587420d31b187620c3093.tar.gz
pseudo-cca0d7f15b7197095cd587420d31b187620c3093.tar.bz2
pseudo-cca0d7f15b7197095cd587420d31b187620c3093.zip
ports/linux: Add mksotemp64 wrapper
Similar to mkstemp64 when oflags=0, therefore move the wrapper and call from mkstemp64. Note that some glibc versions would have one but not the other so ensure fall back to the real function is correct on those versions. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--ports/linux/guts/mkostemp64.c53
-rw-r--r--ports/linux/guts/mkstemp64.c37
-rw-r--r--ports/linux/wrapfuncs.in1
3 files changed, 56 insertions, 35 deletions
diff --git a/ports/linux/guts/mkostemp64.c b/ports/linux/guts/mkostemp64.c
new file mode 100644
index 0000000..502211b
--- /dev/null
+++ b/ports/linux/guts/mkostemp64.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2010 Wind River Systems; see
+ * guts/COPYRIGHT for information.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * static int
+ * wrap_mkstemp64(char *template, int oflags) {
+ * int rc = -1;
+ */
+ struct stat64 buf;
+ int save_errno;
+ size_t len;
+ char *tmp_template;
+
+ if (!template) {
+ errno = EFAULT;
+ return 0;
+ }
+
+ len = strlen(template);
+ tmp_template = PSEUDO_ROOT_PATH(AT_FDCWD, template, AT_SYMLINK_NOFOLLOW);
+
+ if (!tmp_template) {
+ errno = ENOENT;
+ return -1;
+ }
+
+ /* mkstemp64 wrapper uses this code and mkostemp64 not present in some glibc versions */
+ if (oflags == 0)
+ rc = real_mkstemp64(tmp_template);
+ else
+ rc = real_mkostemp64(tmp_template, oflags);
+
+ if (rc != -1) {
+ save_errno = errno;
+
+ if (real___fxstat64(_STAT_VER, rc, &buf) != -1) {
+ real_fchmod(rc, PSEUDO_FS_MODE(0600, 0));
+ pseudo_client_op(OP_CREAT, 0, -1, -1, tmp_template, &buf);
+ pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, &buf);
+ } else {
+ pseudo_debug(PDBGF_CONSISTENCY, "mkstemp (fd %d) succeeded, but fstat failed (%s).\n",
+ rc, strerror(errno));
+ pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, 0);
+ }
+ errno = save_errno;
+ }
+ /* mkstemp only changes the XXXXXX at the end. */
+ memcpy(template + len - 6, tmp_template + strlen(tmp_template) - 6, 6);
+/* return rc;
+ * }
+ */
diff --git a/ports/linux/guts/mkstemp64.c b/ports/linux/guts/mkstemp64.c
index aa7bb58..487f256 100644
--- a/ports/linux/guts/mkstemp64.c
+++ b/ports/linux/guts/mkstemp64.c
@@ -8,42 +8,9 @@
* wrap_mkstemp64(char *template) {
* int rc = -1;
*/
- struct stat64 buf;
- int save_errno;
- size_t len;
- char *tmp_template;
+ /* mkstemp64() is just like mkostemp64() with no flags */
+ rc = wrap_mkostemp64(template, 0);
- if (!template) {
- errno = EFAULT;
- return 0;
- }
-
- len = strlen(template);
- tmp_template = PSEUDO_ROOT_PATH(AT_FDCWD, template, AT_SYMLINK_NOFOLLOW);
-
- if (!tmp_template) {
- errno = ENOENT;
- return -1;
- }
-
- rc = real_mkstemp64(tmp_template);
-
- if (rc != -1) {
- save_errno = errno;
-
- if (real___fxstat64(_STAT_VER, rc, &buf) != -1) {
- real_fchmod(rc, PSEUDO_FS_MODE(0600, 0));
- pseudo_client_op(OP_CREAT, 0, -1, -1, tmp_template, &buf);
- pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, &buf);
- } else {
- pseudo_debug(PDBGF_CONSISTENCY, "mkstemp (fd %d) succeeded, but fstat failed (%s).\n",
- rc, strerror(errno));
- pseudo_client_op(OP_OPEN, PSA_READ | PSA_WRITE, rc, -1, tmp_template, 0);
- }
- errno = save_errno;
- }
- /* mkstemp only changes the XXXXXX at the end. */
- memcpy(template + len - 6, tmp_template + strlen(tmp_template) - 6, 6);
/* return rc;
* }
*/
diff --git a/ports/linux/wrapfuncs.in b/ports/linux/wrapfuncs.in
index 5cc6791..8bc476d 100644
--- a/ports/linux/wrapfuncs.in
+++ b/ports/linux/wrapfuncs.in
@@ -36,6 +36,7 @@ int ftw64(const char *path, int (*fn)(const char *, const struct stat64 *, int),
int glob64(const char *pattern, int flags, int (*errfunc)(const char *, int), glob64_t *pglob);
int scandir64(const char *path, struct dirent64 ***namelist, int (*filter)(const struct dirent64 *), int (*compar)());
int truncate64(const char *path, off64_t length);
+int mkostemp64(char *template, int oflags); /* flags=AT_SYMLINK_NOFOLLOW */
int mkstemp64(char *template); /* flags=AT_SYMLINK_NOFOLLOW */
int getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups);
int setgroups(size_t size, const gid_t *list);