projects
/
pspp-builds.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ac199d2
)
pool: New function pool_strdup0.
author
Ben Pfaff
<blp@gnu.org>
Tue, 5 May 2009 14:03:02 +0000
(07:03 -0700)
committer
Ben Pfaff
<blp@gnu.org>
Sun, 7 Jun 2009 04:11:03 +0000
(21:11 -0700)
This function is the pool analogue of xmemdup0, except that it is only
appropriate for use with strings.
src/libpspp/pool.c
patch
|
blob
|
history
src/libpspp/pool.h
patch
|
blob
|
history
diff --git
a/src/libpspp/pool.c
b/src/libpspp/pool.c
index 88d3535df140e6648f025de4076be66bc466ce06..dbdd71b6cbbf250fbb91248e6c8cc820da13e4f0 100644
(file)
--- a/
src/libpspp/pool.c
+++ b/
src/libpspp/pool.c
@@
-364,6
+364,19
@@
pool_strdup (struct pool *pool, const char *string)
return pool_clone_unaligned (pool, string, strlen (string) + 1);
}
return pool_clone_unaligned (pool, string, strlen (string) + 1);
}
+/* Duplicates the SIZE bytes of STRING, plus a trailing 0 byte,
+ and returns a pointer to the duplicate. For use only with
+ strings, because the returned pointere may not be aligned
+ properly for other types. */
+char *
+pool_strdup0 (struct pool *pool, const char *string, size_t size)
+{
+ char *new_string = pool_alloc_unaligned (pool, size + 1);
+ memcpy (new_string, string, size);
+ new_string[size] = '\0';
+ return new_string;
+}
+
/* Formats FORMAT with the given ARGS in memory allocated from
POOL and returns the formatted string. */
char *
/* Formats FORMAT with the given ARGS in memory allocated from
POOL and returns the formatted string. */
char *
diff --git
a/src/libpspp/pool.h
b/src/libpspp/pool.h
index e6c885e48b3686583d76ecd1413b810ed5fa48ae..fc24b2f9e6ff0ae38221a2ac7f9d3bba60aa8fbf 100644
(file)
--- a/
src/libpspp/pool.h
+++ b/
src/libpspp/pool.h
@@
-62,6
+62,7
@@
void *pool_clone (struct pool *, const void *, size_t) MALLOC_LIKE;
void *pool_alloc_unaligned (struct pool *, size_t) MALLOC_LIKE;
void *pool_clone_unaligned (struct pool *, const void *, size_t) MALLOC_LIKE;
char *pool_strdup (struct pool *, const char *) MALLOC_LIKE;
void *pool_alloc_unaligned (struct pool *, size_t) MALLOC_LIKE;
void *pool_clone_unaligned (struct pool *, const void *, size_t) MALLOC_LIKE;
char *pool_strdup (struct pool *, const char *) MALLOC_LIKE;
+char *pool_strdup0 (struct pool *, const char *, size_t) MALLOC_LIKE;
char *pool_vasprintf (struct pool *, const char *, va_list)
MALLOC_LIKE PRINTF_FORMAT (2, 0);
char *pool_asprintf (struct pool *, const char *, ...)
char *pool_vasprintf (struct pool *, const char *, va_list)
MALLOC_LIKE PRINTF_FORMAT (2, 0);
char *pool_asprintf (struct pool *, const char *, ...)