ports/linux: Add mksotemp64 wrapper
PATCH 1/1 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 <[email protected]>
--- ports/linux/guts/mkostemp64.c | 53 +++++++++++++++++++++++++++++++++++ ports/linux/guts/mkstemp64.c | 37 ++---------------------- ports/linux/wrapfuncs.in | 1 + 3 files changed, 56 insertions(+), 35 deletions(-) create mode 100644 ports/linux/guts/mkostemp64.c
ports/linux/guts/mkostemp64.c new file +53 -0
@@ -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; +* } +*/
ports/linux/guts/mkstemp64.c +2 -35
@@ -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; * } */
ports/linux/wrapfuncs.in +1 -0
@@ -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);
Signature · 1 line
2.25.1