#include <relocatable.h>
#include "minmax.h"
#include "xalloc.h"
+#include "xmemdup0.h"
#include "xsize.h"
\f
/* Reverses the order of NBYTES bytes at address P, thus converting
}
}
-/* Finds the last NEEDLE of length NEEDLE_LEN in a HAYSTACK of length
- HAYSTACK_LEN. Returns a pointer to the needle found. */
-char *
-buf_find_reverse (const char *haystack, size_t haystack_len,
- const char *needle, size_t needle_len)
-{
- int i;
- for (i = haystack_len - needle_len; i >= 0; i--)
- if (!memcmp (needle, &haystack[i], needle_len))
- return (char *) &haystack[i];
- return 0;
-}
-
/* Compares the SIZE bytes in A to those in B, disregarding case,
and returns a strcmp()-type result. */
int
return true;
}
-/* Formats FORMAT into DST, as with sprintf(), and returns the
- address of the terminating null written to DST. */
-char *
-spprintf (char *dst, const char *format, ...)
-{
- va_list args;
- int count;
-
- va_start (args, format);
- count = vsprintf (dst, format, args);
- va_end (args);
-
- return dst + count;
-}
-
/* Sets the SIZE bytes starting at BLOCK to C,
and returns the byte following BLOCK. */
void *
\f
/* Substrings. */
-/* Returns an empty substring. */
-struct substring
-ss_empty (void)
-{
- struct substring ss;
- ss.string = NULL;
- ss.length = 0;
- return ss;
-}
-
-/* Returns a substring whose contents are the given C-style
- string CSTR. */
-struct substring
-ss_cstr (const char *cstr)
-{
- return ss_buffer (cstr, strlen (cstr));
-}
-
-/* Returns a substring whose contents are the CNT characters in
- BUFFER. */
-struct substring
-ss_buffer (const char *buffer, size_t cnt)
-{
- struct substring ss;
- ss.string = (char *) buffer;
- ss.length = cnt;
- return ss;
-}
-
/* Returns a substring whose contents are the CNT characters
starting at the (0-based) position START in SS. */
struct substring
return ss;
}
-/* Makes a malloc()'d copy of the contents of OLD
+/* Makes a malloc()'d, null-terminated copy of the contents of OLD
and stores it in NEW. */
void
ss_alloc_substring (struct substring *new, struct substring old)
{
- new->string = xmalloc (old.length);
+ new->string = xmemdup0 (old.string, old.length);
new->length = old.length;
- memcpy (new->string, old.string, old.length);
}
/* Allocates room for a CNT-character string in NEW. */
{
ds_clear (st);
ds_put_cstr (st, rel);
- free ((char *) rel);
+ /* The documentation for relocate says that casting away const
+ and then freeing is appropriate ... */
+ free (CONST_CAST (char *, rel));
}
}