summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2021-04-19 14:33:36 +0200
committerMark Wielaard <mark@klomp.org>2021-05-12 11:56:57 +0200
commitadc201f81902f3015a841869756ed4b9b811fe33 (patch)
tree735ab647b6e749f7bbbd1cd88256f89c2de266a9 /lib
parent857546d176a36d2b5dc18b81dcafa3fb8ec0123d (diff)
downloadelfutils-adc201f81902f3015a841869756ed4b9b811fe33.tar.gz
Come up with startswith function.
New function in system.h that returns true if a string has a given prefix, false otherwise. Use it in place of strncmp. Signed-off-by: Martin Liška <mliska@suse.cz>
Diffstat (limited to 'lib')
-rw-r--r--lib/ChangeLog7
-rw-r--r--lib/system.h15
2 files changed, 19 insertions, 3 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 371e2133..dd3ebcab 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,3 +1,10 @@
+2021-04-19 Martin Liska <mliska@suse.cz>
+
+ * system.h (startswith): New function.
+ (pwrite_retry): Cast to char *.
+ (write_retry): Likewise.
+ (pread_retry): Likewise.
+
2021-02-05 Mark Wielaard <mark@klomp.org>
* printversion.c (print_version): Update copyright year.
diff --git a/lib/system.h b/lib/system.h
index 1c478e1c..cdf18ed7 100644
--- a/lib/system.h
+++ b/lib/system.h
@@ -37,6 +37,7 @@
#include <endian.h>
#include <byteswap.h>
#include <unistd.h>
+#include <string.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
# define LE32(n) (n)
@@ -69,6 +70,14 @@
((void *) ((char *) memcpy (dest, src, n) + (size_t) n))
#endif
+/* Return TRUE if the start of STR matches PREFIX, FALSE otherwise. */
+
+static inline int
+startswith (const char *str, const char *prefix)
+{
+ return strncmp (str, prefix, strlen (prefix)) == 0;
+}
+
/* A special gettext function we use if the strings are too short. */
#define sgettext(Str) \
({ const char *__res = strrchr (_(Str), '|'); \
@@ -104,7 +113,7 @@ pwrite_retry (int fd, const void *buf, size_t len, off_t off)
do
{
- ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, buf + recvd, len - recvd,
+ ssize_t ret = TEMP_FAILURE_RETRY (pwrite (fd, ((char *)buf) + recvd, len - recvd,
off + recvd));
if (ret <= 0)
return ret < 0 ? ret : recvd;
@@ -123,7 +132,7 @@ write_retry (int fd, const void *buf, size_t len)
do
{
- ssize_t ret = TEMP_FAILURE_RETRY (write (fd, buf + recvd, len - recvd));
+ ssize_t ret = TEMP_FAILURE_RETRY (write (fd, ((char *)buf) + recvd, len - recvd));
if (ret <= 0)
return ret < 0 ? ret : recvd;
@@ -141,7 +150,7 @@ pread_retry (int fd, void *buf, size_t len, off_t off)
do
{
- ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, buf + recvd, len - recvd,
+ ssize_t ret = TEMP_FAILURE_RETRY (pread (fd, ((char *)buf) + recvd, len - recvd,
off + recvd));
if (ret <= 0)
return ret < 0 ? ret : recvd;