[16/25] libeu: Move the implementation of pwrite_retry, write_retry and pread_retry from header to source

Message ID 20221020182603.815-17-luoyonggang@gmail.com
State New
Headers
Series Patches for building with mingw/gcc msvc/clang-cl |

Commit Message

Yonggang Luo Oct. 20, 2022, 6:25 p.m. UTC
  Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 lib/Makefile.am |  2 +-
 lib/system.c    | 87 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/system.h    | 59 ++++-----------------------------
 3 files changed, 94 insertions(+), 54 deletions(-)
 create mode 100644 lib/system.c
  

Patch

diff --git a/lib/Makefile.am b/lib/Makefile.am
index 42ddf5ae..7a50085b 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -35,7 +35,7 @@  noinst_LIBRARIES = libeu.a
 
 libeu_a_SOURCES = xasprintf.c xstrdup.c xstrndup.c xmalloc.c next_prime.c \
 		  crc32.c crc32_file.c \
-		  color.c error.c printversion.c
+		  color.c error.c printversion.c system.c
 
 noinst_HEADERS = fixedsizehash.h libeu.h system.h dynamicsizehash.h list.h \
 		 eu-config.h color.h printversion.h bpf.h \
diff --git a/lib/system.c b/lib/system.c
new file mode 100644
index 00000000..0fd28968
--- /dev/null
+++ b/lib/system.c
@@ -0,0 +1,87 @@ 
+/* Definitions for system functions.
+   Copyright (C) 2006-2011 Red Hat, Inc.
+   Copyright (C) 2022 Mark J. Wielaard <mark@klomp.org>
+   Copyright (C) 2022 Yonggang Luo <luoyonggang@gmail.com>
+   This file is part of elfutils.
+
+   This file is free software; you can redistribute it and/or modify
+   it under the terms of either
+
+     * the GNU Lesser General Public License as published by the Free
+       Software Foundation; either version 3 of the License, or (at
+       your option) any later version
+
+   or
+
+     * the GNU General Public License as published by the Free
+       Software Foundation; either version 2 of the License, or (at
+       your option) any later version
+
+   or both in parallel, as here.
+
+   elfutils is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received copies of the GNU General Public License and
+   the GNU Lesser General Public License along with this program.  If
+   not, see <http://www.gnu.org/licenses/>.  */
+
+#include "system.h"
+
+ssize_t
+pwrite_retry(int fd, const void *buf, size_t len, off_t off)
+{
+  ssize_t recvd = 0;
+
+  do
+    {
+      ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, ((char *)buf) + recvd, len - recvd,
+          off + recvd));
+      if (ret <= 0)
+        return ret < 0 ? ret : recvd;
+
+      recvd += ret;
+    }
+  while ((size_t) recvd < len);
+
+  return recvd;
+}
+
+ssize_t
+write_retry(int fd, const void *buf, size_t len)
+{
+  ssize_t recvd = 0;
+
+  do
+    {
+      ssize_t ret = TEMP_FAILURE_RETRY (write (fd, ((char *)buf) + recvd, len - recvd));
+      if (ret <= 0)
+        return ret < 0 ? ret : recvd;
+
+      recvd += ret;
+    }
+  while ((size_t) recvd < len);
+
+  return recvd;
+}
+
+ssize_t
+pread_retry(int fd, void *buf, size_t len, off_t off)
+{
+  ssize_t recvd = 0;
+
+  do
+    {
+      ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, ((char *)buf) + recvd, len - recvd,
+          off + recvd));
+      if (ret <= 0)
+        return ret < 0 ? ret : recvd;
+
+      recvd += ret;
+    }
+  while ((size_t) recvd < len);
+
+  return recvd;
+}
diff --git a/lib/system.h b/lib/system.h
index 264781c2..05b2d8f9 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -145,61 +145,14 @@  startswith (const char *str, const char *prefix)
 #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)/* 0666 */
 #endif
 
-static inline ssize_t __attribute__ ((unused))
-pwrite_retry (int fd, const void *buf, size_t len, off_t off)
-{
-  ssize_t recvd = 0;
-
-  do
-    {
-      ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, ((char *)buf) + recvd, len - recvd,
-						off + recvd));
-      if (ret <= 0)
-	return ret < 0 ? ret : recvd;
+ssize_t
+pwrite_retry (int fd, const void *buf, size_t len, off_t off);
 
-      recvd += ret;
-    }
-  while ((size_t) recvd < len);
-
-  return recvd;
-}
+ssize_t
+write_retry (int fd, const void *buf, size_t len);
 
-static inline ssize_t __attribute__ ((unused))
-write_retry (int fd, const void *buf, size_t len)
-{
-  ssize_t recvd = 0;
-
-  do
-    {
-      ssize_t ret = TEMP_FAILURE_RETRY (write (fd, ((char *)buf) + recvd, len - recvd));
-      if (ret <= 0)
-	return ret < 0 ? ret : recvd;
-
-      recvd += ret;
-    }
-  while ((size_t) recvd < len);
-
-  return recvd;
-}
-
-static inline ssize_t __attribute__ ((unused))
-pread_retry (int fd, void *buf, size_t len, off_t off)
-{
-  ssize_t recvd = 0;
-
-  do
-    {
-      ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, ((char *)buf) + recvd, len - recvd,
-					       off + recvd));
-      if (ret <= 0)
-	return ret < 0 ? ret : recvd;
-
-      recvd += ret;
-    }
-  while ((size_t) recvd < len);
-
-  return recvd;
-}
+ssize_t
+pread_retry (int fd, void *buf, size_t len, off_t off);
 
 /* The demangler from libstdc++.  */
 extern char *__cxa_demangle (const char *mangled_name, char *output_buffer,