aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2018-11-16 21:52:10 +0100
committerMattias Andrée <maandree@kth.se>2018-11-16 21:52:10 +0100
commit8bdb03d22b48d1871d364aa24ff9484b687ef84f (patch)
treecf9c75b1d50f8b050c79f862cecd715976868f10
parentAdd mempmove (diff)
downloadlibsimple-8bdb03d22b48d1871d364aa24ff9484b687ef84f.tar.gz
libsimple-8bdb03d22b48d1871d364aa24ff9484b687ef84f.tar.bz2
libsimple-8bdb03d22b48d1871d364aa24ff9484b687ef84f.tar.xz
Add st{r,p}[n]move
Signed-off-by: Mattias Andrée <maandree@kth.se>
-rw-r--r--libsimple/mem.h5
-rw-r--r--libsimple/str.h32
-rw-r--r--libsimple/strn.h39
-rw-r--r--man0/libsimple.h.017
-rw-r--r--man3/libsimple_mempmove.36
-rw-r--r--man3/libsimple_stpmove.374
-rw-r--r--man3/libsimple_stpnmove.379
-rw-r--r--man3/libsimple_strmove.369
-rw-r--r--man3/libsimple_strnmove.371
l---------man3/stpmove.3libsimple1
l---------man3/stpnmove.3libsimple1
l---------man3/strmove.3libsimple1
l---------man3/strnmove.3libsimple1
13 files changed, 391 insertions, 5 deletions
diff --git a/libsimple/mem.h b/libsimple/mem.h
index 370709c..be05b70 100644
--- a/libsimple/mem.h
+++ b/libsimple/mem.h
@@ -370,7 +370,6 @@ static inline int libsimple_memcaseeq(const void *__a, const void *__b, size_t _
* @param n The number of bytes to copy
* @return `&d[n]`
*/
-_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__)))
static inline void *libsimple_mempcpy(void *restrict __d, const void *restrict __s, size_t __n)
{ return &((char *)memcpy(__d, __s, __n))[__n]; }
#ifndef mempcpy
@@ -386,8 +385,7 @@ static inline void *libsimple_mempcpy(void *restrict __d, const void *restrict _
* @param n The number of bytes to move
* @return `&d[n]`
*/
-_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__)))
-static inline void *libsimple_mempmove(void *__d, const void *__s, size_t __n)
+static inline void *libsimple_mempmove(void *__d, const void *__s, size_t __n) /* TODO test */
{ return &((char *)memmove(__d, __s, __n))[__n]; }
#ifndef mempmove
# define mempmove libsimple_mempmove
@@ -402,7 +400,6 @@ static inline void *libsimple_mempmove(void *__d, const void *__s, size_t __n)
* @param n The number of bytes to write to `s`
* @return `&s[n]`
*/
-_LIBSIMPLE_GCC_ONLY(__attribute__((__warn_unused_result__)))
static inline void *libsimple_mempset(void *__s, int __c, size_t __n)
{ return &((char *)memset(__s, __c, __n))[__n]; }
#ifndef mempset
diff --git a/libsimple/str.h b/libsimple/str.h
index 9f782cd..c52b2c8 100644
--- a/libsimple/str.h
+++ b/libsimple/str.h
@@ -375,6 +375,38 @@ static inline int libsimple_inchrcaseset(int __c, const char *__s)
/**
+ * Moves a string within a string
+ *
+ * @param d The location in the string's byte array where the
+ * string should be moved to
+ * @param s The string to move
+ * @return `d`
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
+static inline char *libsimple_strmove(char *__d, const char *__s) /* TODO test */
+{ return memmove(__d, __s, strlen(__s) + 1); }
+#ifndef strmove
+# define strmove libsimple_strmove
+#endif
+
+
+/**
+ * Moves a string within a string
+ *
+ * @param d The location in the string's byte array where the
+ * string should be moved to
+ * @param s The string to move
+ * @return `&d[strlen(s)]` (this byte will be a NUL byte)
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
+static inline char *libsimple_stpmove(char *__d, const char *__s) /* TODO test */
+{ size_t __n = strlen(__s); memmove(__d, __s, __n + 1); return &__d[__n]; }
+#ifndef stpmove
+# define stpmove libsimple_stpmove
+#endif
+
+
+/**
* Check whether a NUL-terminated string is encoded in UTF-8
*
* @param string The string
diff --git a/libsimple/strn.h b/libsimple/strn.h
index cf25a20..28a2917 100644
--- a/libsimple/strn.h
+++ b/libsimple/strn.h
@@ -429,6 +429,45 @@ static inline size_t libsimple_strrncaseeqlen(const char *__a, const char *__b,
/**
+ * Moves a string within a string
+ *
+ * @param d The location in the string's byte array where the
+ * string should be moved to
+ * @param s The string to move
+ * @param n The maximum number of bytes to move
+ * @return `d`
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
+static inline char *libsimple_strnmove(char *__d, const char *__s, size_t __n) /* TODO test */
+{ size_t __len = strnlen(__s, __n); return memmove(__d, __s, __len + (__len < __n)); }
+#ifndef strnmove
+# define strnmove libsimple_strnmove
+#endif
+
+
+/**
+ * Moves a string within a string
+ *
+ * @param d The location in the string's byte array where the
+ * string should be moved to
+ * @param s The string to move
+ * @param n The maximum number of bytes to move
+ * @return `&d[strnlen(s, n)]`
+ */
+_LIBSIMPLE_GCC_ONLY(__attribute__((__nonnull__)))
+static inline char *
+libsimple_stpnmove(char *__d, const char *__s, size_t __n) /* TODO test */
+{
+ size_t __len = strnlen(__s, __n);
+ memmove(__d, __s, __len + (__len < __n));
+ return &__d[__len];
+}
+#ifndef stpnmove
+# define stpnmove libsimple_stpnmove
+#endif
+
+
+/**
* Check whether a string, that may be or may not be NUL-terminated,
* is encoded in UTF-8
*
diff --git a/man0/libsimple.h.0 b/man0/libsimple.h.0
index ff00c4b..a1e1cd4 100644
--- a/man0/libsimple.h.0
+++ b/man0/libsimple.h.0
@@ -1021,6 +1021,23 @@ Check if a string is valid UTF-8.
.RE
.TP
+.BR libsimple_strmove (3),
+.RS 0
+.BR libsimple_strnmove (3),
+.br
+.BR libsimple_stpmove (3),
+.br
+.BR libsimple_stpnmove (3)
+.RE
+.RS
+Versions of
+.BR memmove (3)
+and
+.BR libsimple_mempmove (3)
+that moves an entire string.
+.RE
+
+.TP
.BR libsimple_strnchr (3),
.RS 0
.BR libsimple_strncasechr (3)
diff --git a/man3/libsimple_mempmove.3 b/man3/libsimple_mempmove.3
index d68c6dc..99e09c3 100644
--- a/man3/libsimple_mempmove.3
+++ b/man3/libsimple_mempmove.3
@@ -1,4 +1,4 @@
-.TH LIBSIMPLE_MEMPMOVE 3 2018-10-23 libsimple
+.TH LIBSIMPLE_MEMPMOVE 3 2018-11-16 libsimple
.SH NAME
libsimple_mempmove \- move bytes within an array of bytes
.SH SYNOPSIS
@@ -69,4 +69,8 @@ None.
.SH SEE ALSO
.BR libsimple_mempcpy (3),
.BR libsimple_mempset (3),
+.BR libsimple_strmove (3),
+.BR libsimple_stpmove (3),
+.BR libsimple_strnmove (3),
+.BR libsimple_stpnmove (3),
.BR memmove (3)
diff --git a/man3/libsimple_stpmove.3 b/man3/libsimple_stpmove.3
new file mode 100644
index 0000000..5b28622
--- /dev/null
+++ b/man3/libsimple_stpmove.3
@@ -0,0 +1,74 @@
+.TH LIBSIMPLE_STPMOVE 3 2018-11-16 libsimple
+.SH NAME
+libsimple_stpmove \- move a string within an array of bytes
+.SH SYNOPSIS
+.nf
+#include <libsimple.h>
+
+static inline void *libsimple_stpmove(void *\fIdest\fP, const void *\fIsrc\fP);
+
+#ifndef stpmove
+# define stpmove libsimple_stpmove
+#endif
+.fi
+.PP
+Link with
+.IR \-lsimple .
+.SH DESCRIPTION
+The
+.BR libsimple_stpmove ()
+function copies the string, including the
+NUL byte that terminates it,
+.I src
+into
+.IR dest .
+The arrays may overlap.
+.SH RETURN VALUE
+The
+.BR libsimple_stpmove ()
+function returns the pointer
+.I dest
+with the offset of the length of string
+.I str
+(the address of the copied NUL byte in
+.IR dest ).
+.SH ERRORS
+The
+.BR libsimple_stpmove ()
+function cannot fail.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR libsimple_stpmove ()
+T} Thread safety MT-Safe
+T{
+.BR libsimple_stpmove ()
+T} Async-signal safety AS-Safe
+T{
+.BR libsimple_stpmove ()
+T} Async-cancel safety AC-Safe
+.TE
+.SH EXAMPLES
+None.
+.SH APPLICATION USAGE
+None.
+.SH RATIONALE
+None.
+.SH FUTURE DIRECTIONS
+None.
+.SH NOTES
+None.
+.SH BUGS
+None.
+.SH SEE ALSO
+.BR libsimple_strmove (3),
+.BR libsimple_stpnmove (3),
+.BR libsimple_mempmove (3),
+.BR stpcpy (3),
+.BR memmove (3)
diff --git a/man3/libsimple_stpnmove.3 b/man3/libsimple_stpnmove.3
new file mode 100644
index 0000000..e2ead53
--- /dev/null
+++ b/man3/libsimple_stpnmove.3
@@ -0,0 +1,79 @@
+.TH LIBSIMPLE_STPNMOVE 3 2018-11-16 libsimple
+.SH NAME
+libsimple_stpnmove \- move a string within an array of bytes
+.SH SYNOPSIS
+.nf
+#include <libsimple.h>
+
+static inline void *libsimple_stpnmove(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP);
+
+#ifndef stpnmove
+# define stpnmove libsimple_stpnmove
+#endif
+.fi
+.PP
+Link with
+.IR \-lsimple .
+.SH DESCRIPTION
+The
+.BR libsimple_stpnmove ()
+function copies the first
+.I n
+bytes of the string, including the
+NUL byte that terminates it (if any),
+.I src
+into
+.IR dest .
+The arrays may overlap.
+.SH RETURN VALUE
+The
+.BR libsimple_stpnmove ()
+function returns the pointer
+.I dest
+with the offset of the length of string
+.I str
+(the address of the copied NUL byte in
+.I dest
+or
+.I &dest[n]
+if no NUL byte was copied).
+.SH ERRORS
+The
+.BR libsimple_stpnmove ()
+function cannot fail.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR libsimple_stpnmove ()
+T} Thread safety MT-Safe
+T{
+.BR libsimple_stpnmove ()
+T} Async-signal safety AS-Safe
+T{
+.BR libsimple_stpnmove ()
+T} Async-cancel safety AC-Safe
+.TE
+.SH EXAMPLES
+None.
+.SH APPLICATION USAGE
+None.
+.SH RATIONALE
+None.
+.SH FUTURE DIRECTIONS
+None.
+.SH NOTES
+None.
+.SH BUGS
+None.
+.SH SEE ALSO
+.BR libsimple_strnmove (3),
+.BR libsimple_stpmove (3),
+.BR libsimple_mempmove (3),
+.BR stpncpy (3),
+.BR memmove (3)
diff --git a/man3/libsimple_strmove.3 b/man3/libsimple_strmove.3
new file mode 100644
index 0000000..39c4572
--- /dev/null
+++ b/man3/libsimple_strmove.3
@@ -0,0 +1,69 @@
+.TH LIBSIMPLE_STRMOVE 3 2018-11-16 libsimple
+.SH NAME
+libsimple_strmove \- move a string within an array of bytes
+.SH SYNOPSIS
+.nf
+#include <libsimple.h>
+
+static inline void *libsimple_strmove(void *\fIdest\fP, const void *\fIsrc\fP);
+
+#ifndef strmove
+# define strmove libsimple_strmove
+#endif
+.fi
+.PP
+Link with
+.IR \-lsimple .
+.SH DESCRIPTION
+The
+.BR libsimple_strmove ()
+function copies the string, including the
+NUL byte that terminates it,
+.I src
+into
+.IR dest .
+The arrays may overlap.
+.SH RETURN VALUE
+The
+.BR libsimple_strmove ()
+function returns the pointer
+.IR dest .
+.SH ERRORS
+The
+.BR libsimple_strmove ()
+function cannot fail.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR libsimple_strmove ()
+T} Thread safety MT-Safe
+T{
+.BR libsimple_strmove ()
+T} Async-signal safety AS-Safe
+T{
+.BR libsimple_strmove ()
+T} Async-cancel safety AC-Safe
+.TE
+.SH EXAMPLES
+None.
+.SH APPLICATION USAGE
+None.
+.SH RATIONALE
+None.
+.SH FUTURE DIRECTIONS
+None.
+.SH NOTES
+None.
+.SH BUGS
+None.
+.SH SEE ALSO
+.BR libsimple_stpmove (3),
+.BR libsimple_strnmove (3),
+.BR strcpy (3),
+.BR memmove (3)
diff --git a/man3/libsimple_strnmove.3 b/man3/libsimple_strnmove.3
new file mode 100644
index 0000000..46776be
--- /dev/null
+++ b/man3/libsimple_strnmove.3
@@ -0,0 +1,71 @@
+.TH LIBSIMPLE_STRNMOVE 3 2018-11-16 libsimple
+.SH NAME
+libsimple_strnmove \- move a string within an array of bytes
+.SH SYNOPSIS
+.nf
+#include <libsimple.h>
+
+static inline void *libsimple_strnmove(void *\fIdest\fP, const void *\fIsrc\fP, size_t \fIn\fP);
+
+#ifndef strnmove
+# define strnmove libsimple_strnmove
+#endif
+.fi
+.PP
+Link with
+.IR \-lsimple .
+.SH DESCRIPTION
+The
+.BR libsimple_strnmove ()
+function copies the first
+.I n
+bytes of the string, including the
+NUL byte that terminates it (if any),
+.I src
+into
+.IR dest .
+The arrays may overlap.
+.SH RETURN VALUE
+The
+.BR libsimple_strnmove ()
+function returns the pointer
+.IR dest .
+.SH ERRORS
+The
+.BR libsimple_strnmove ()
+function cannot fail.
+.SH ATTRIBUTES
+For an explanation of the terms used in this section, see
+.BR attributes (7).
+.TS
+allbox;
+lb lb lb
+l l l.
+Interface Attribute Value
+T{
+.BR libsimple_strnmove ()
+T} Thread safety MT-Safe
+T{
+.BR libsimple_strnmove ()
+T} Async-signal safety AS-Safe
+T{
+.BR libsimple_strnmove ()
+T} Async-cancel safety AC-Safe
+.TE
+.SH EXAMPLES
+None.
+.SH APPLICATION USAGE
+None.
+.SH RATIONALE
+None.
+.SH FUTURE DIRECTIONS
+None.
+.SH NOTES
+None.
+.SH BUGS
+None.
+.SH SEE ALSO
+.BR libsimple_stpnmove (3),
+.BR libsimple_strmove (3),
+.BR strncpy (3),
+.BR memmove (3)
diff --git a/man3/stpmove.3libsimple b/man3/stpmove.3libsimple
new file mode 120000
index 0000000..d4e1348
--- /dev/null
+++ b/man3/stpmove.3libsimple
@@ -0,0 +1 @@
+libsimple_stpmove.3 \ No newline at end of file
diff --git a/man3/stpnmove.3libsimple b/man3/stpnmove.3libsimple
new file mode 120000
index 0000000..cb5b24e
--- /dev/null
+++ b/man3/stpnmove.3libsimple
@@ -0,0 +1 @@
+libsimple_stpnmove.3 \ No newline at end of file
diff --git a/man3/strmove.3libsimple b/man3/strmove.3libsimple
new file mode 120000
index 0000000..7bcb3d1
--- /dev/null
+++ b/man3/strmove.3libsimple
@@ -0,0 +1 @@
+libsimple_strmove.3 \ No newline at end of file
diff --git a/man3/strnmove.3libsimple b/man3/strnmove.3libsimple
new file mode 120000
index 0000000..932b082
--- /dev/null
+++ b/man3/strnmove.3libsimple
@@ -0,0 +1 @@
+libsimple_strnmove.3 \ No newline at end of file