]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/fs/mkstemp/, src/: fmkomstemp(): Move function to separate file
authorAlejandro Colomar <alx@kernel.org>
Wed, 4 Dec 2024 12:33:58 +0000 (13:33 +0100)
committerSerge Hallyn <serge@hallyn.com>
Tue, 3 Jun 2025 14:49:44 +0000 (09:49 -0500)
And make it inline.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/fs/mkstemp/fmkomstemp.c [new file with mode: 0644]
lib/fs/mkstemp/fmkomstemp.h [new file with mode: 0644]
src/useradd.c

index 55d340397bdbcd1e66c17104d5ef6668df58e6db..0cc39310481774d49e8adcdbeab67335bf4c3861 100644 (file)
@@ -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 (file)
index 0000000..a8b49d6
--- /dev/null
@@ -0,0 +1,13 @@
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include "fs/mkstemp/fmkomstemp.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+
+
+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 (file)
index 0000000..4770bc9
--- /dev/null
@@ -0,0 +1,46 @@
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_FS_MKSTEMP_FMKOMSTEMP_H_
+#define SHADOW_INCLUDE_LIB_FS_MKSTEMP_FMKOMSTEMP_H_
+
+
+#include <config.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+
+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
index 9180d242922280469524f57843000a21c4083449..ed1e0bc566f5563f978ae58214851d0bc5a3eb54 100644 (file)
@@ -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;
-}