From 1a048dc5e2c463f2eaf1b8975983185fee080b37 Mon Sep 17 00:00:00 2001 From: Ruediger Meier Date: Mon, 29 Feb 2016 12:49:13 +0100 Subject: [PATCH] lib: move fopen_at() to fileutils.h, remove at.h Signed-off-by: Ruediger Meier --- include/Makemodule.am | 1 - include/at.h | 22 ---------------------- include/fileutils.h | 10 ++++++++++ lib/Makemodule.am | 3 +-- lib/at.c | 24 ------------------------ lib/procutils.c | 2 +- libmount/src/tab_parse.c | 2 +- 7 files changed, 13 insertions(+), 51 deletions(-) delete mode 100644 include/at.h delete mode 100644 lib/at.c diff --git a/include/Makemodule.am b/include/Makemodule.am index 0a41a9433..5cdf29a5b 100644 --- a/include/Makemodule.am +++ b/include/Makemodule.am @@ -1,7 +1,6 @@ dist_noinst_HEADERS += \ include/all-io.h \ - include/at.h \ include/bitops.h \ include/blkdev.h \ include/canonicalize.h \ diff --git a/include/at.h b/include/at.h deleted file mode 100644 index a1c6a8b66..000000000 --- a/include/at.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * wrappers for "at" functions. - * - * Copyright (C) 2010 Karel Zak - * - * This file may be redistributed under the terms of the - * GNU Lesser General Public License. - */ -#ifndef UTIL_LINUX_AT_H -#define UTIL_LINUX_AT_H - -#include -#include -#include -#include - -#include "c.h" - -extern FILE *fopen_at(int dir, const char *filename, - int flags, const char *mode); - -#endif /* UTIL_LINUX_AT_H */ diff --git a/include/fileutils.h b/include/fileutils.h index 79dd01237..1cc007c76 100644 --- a/include/fileutils.h +++ b/include/fileutils.h @@ -28,6 +28,16 @@ static inline FILE *xfmkstemp(char **tmpname, const char *dir, const char *prefi return ret; } +static inline FILE *fopen_at(int dir, const char *filename, + int flags, const char *mode) +{ + int fd = openat(dir, filename, flags); + if (fd < 0) + return NULL; + + return fdopen(fd, mode); +} + static inline int is_same_inode(const int fd, const struct stat *st) { struct stat f; diff --git a/lib/Makemodule.am b/lib/Makemodule.am index 25e1ba04e..81504b9a6 100644 --- a/lib/Makemodule.am +++ b/lib/Makemodule.am @@ -2,7 +2,6 @@ noinst_LTLIBRARIES += libcommon.la libcommon_la_CFLAGS = $(AM_CFLAGS) libcommon_la_SOURCES = \ - lib/at.c \ lib/blkdev.c \ lib/canonicalize.c \ lib/crc32.c \ @@ -100,7 +99,7 @@ test_colors_LDADD = $(LDADD) $(TINFO_LIBS) test_randutils_SOURCES = lib/randutils.c test_randutils_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM -test_procutils_SOURCES = lib/procutils.c lib/at.c +test_procutils_SOURCES = lib/procutils.c test_procutils_CFLAGS = $(AM_CFLAGS) -DTEST_PROGRAM if LINUX diff --git a/lib/at.c b/lib/at.c deleted file mode 100644 index e32a8f5d3..000000000 --- a/lib/at.c +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Portable xxxat() functions. - * - * No copyright is claimed. This code is in the public domain; do with - * it what you wish. - * - * Written by Karel Zak - */ -#include -#include - -#include "at.h" -#include "c.h" - -FILE *fopen_at(int dir, const char *filename, int flags, - const char *mode) -{ - int fd = openat(dir, filename, flags); - - if (fd < 0) - return NULL; - - return fdopen(fd, mode); -} diff --git a/lib/procutils.c b/lib/procutils.c index 6f016345a..16d1897b4 100644 --- a/lib/procutils.c +++ b/lib/procutils.c @@ -24,7 +24,7 @@ #include #include "procutils.h" -#include "at.h" +#include "fileutils.h" #include "all-io.h" #include "c.h" diff --git a/libmount/src/tab_parse.c b/libmount/src/tab_parse.c index 9536ebe6b..cee700816 100644 --- a/libmount/src/tab_parse.c +++ b/libmount/src/tab_parse.c @@ -17,7 +17,7 @@ #include #include -#include "at.h" +#include "fileutils.h" #include "mangle.h" #include "mountP.h" #include "pathnames.h"