From: Alejandro Colomar Date: Wed, 4 Dec 2024 12:33:58 +0000 (+0100) Subject: lib/fs/mkstemp/, src/: fmkomstemp(): Move function to separate file X-Git-Tag: 4.18.0-rc1~27 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4b62a2ebeaa4fcfd27421e32496ed37fcf42fd3b;p=thirdparty%2Fshadow.git lib/fs/mkstemp/, src/: fmkomstemp(): Move function to separate file And make it inline. Signed-off-by: Alejandro Colomar --- diff --git a/lib/Makefile.am b/lib/Makefile.am index 55d340397..0cc393104 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -100,6 +100,8 @@ libshadow_la_SOURCES = \ find_new_sub_gids.c \ find_new_sub_uids.c \ fputsx.c \ + fs/mkstemp/fmkomstemp.c \ + fs/mkstemp/fmkomstemp.h \ fs/readlink/areadlink.c \ fs/readlink/areadlink.h \ fs/readlink/readlinknul.c \ diff --git a/lib/fs/mkstemp/fmkomstemp.c b/lib/fs/mkstemp/fmkomstemp.c new file mode 100644 index 000000000..a8b49d6e4 --- /dev/null +++ b/lib/fs/mkstemp/fmkomstemp.c @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#include + +#include "fs/mkstemp/fmkomstemp.h" + +#include +#include + + +extern inline FILE *fmkomstemp(char *template, unsigned int flags, mode_t m); diff --git a/lib/fs/mkstemp/fmkomstemp.h b/lib/fs/mkstemp/fmkomstemp.h new file mode 100644 index 000000000..4770bc92a --- /dev/null +++ b/lib/fs/mkstemp/fmkomstemp.h @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2024, Alejandro Colomar +// SPDX-License-Identifier: BSD-3-Clause + + +#ifndef SHADOW_INCLUDE_LIB_FS_MKSTEMP_FMKOMSTEMP_H_ +#define SHADOW_INCLUDE_LIB_FS_MKSTEMP_FMKOMSTEMP_H_ + + +#include + +#include +#include +#include +#include +#include + + +inline FILE *fmkomstemp(char *template, unsigned int flags, mode_t m); + + +inline FILE * +fmkomstemp(char *template, unsigned int flags, mode_t m) +{ + int fd; + FILE *fp; + + fd = mkostemp(template, flags); + if (fd == -1) + return NULL; + + if (fchmod(fd, m) == -1) + goto fail; + + fp = fdopen(fd, "w"); + if (fp == NULL) + goto fail; + + return fp; +fail: + close(fd); + unlink(template); + return NULL; +} + + +#endif // include guard diff --git a/src/useradd.c b/src/useradd.c index 9180d2429..ed1e0bc56 100644 --- a/src/useradd.c +++ b/src/useradd.c @@ -42,6 +42,7 @@ #include "chkname.h" #include "defines.h" #include "faillog.h" +#include "fs/mkstemp/fmkomstemp.h" #include "getdef.h" #include "groupio.h" #include "nscd.h" @@ -246,8 +247,6 @@ static void create_home (void); static void create_mail (void); static void check_uid_range(int rflg, uid_t user_id); -static FILE *fmkomstemp(char *template, unsigned int flags, mode_t m); - /* * fail_exit - undo as much as possible @@ -2682,28 +2681,3 @@ int main (int argc, char **argv) return E_SUCCESS; } - - -static FILE * -fmkomstemp(char *template, unsigned int flags, mode_t m) -{ - int fd; - FILE *fp; - - fd = mkostemp(template, flags); - if (fd == -1) - return NULL; - - if (fchmod(fd, m) == -1) - goto fail; - - fp = fdopen(fd, "w"); - if (fp == NULL) - goto fail; - - return fp; -fail: - close(fd); - unlink(template); - return NULL; -}