include: remove uv_strlcat() and uv_strlcpy()

It was pointed out that they don't quite work like their BSD namesakes
and they arguably shouldn't have been part of the API anyway.

Fixes #983.
This commit is contained in:
Ben Noordhuis 2013-11-03 03:48:18 +01:00
parent 0520464870
commit 7f44933c43
8 changed files with 4 additions and 155 deletions

View File

@ -193,7 +193,6 @@ test_run_tests_SOURCES = test/blackhole-server.c \
test/test-udp-open.c \
test/test-udp-options.c \
test/test-udp-send-and-recv.c \
test/test-util.c \
test/test-walk-handles.c
test_run_tests_LDADD = libuv.la

View File

@ -158,7 +158,6 @@ test/test-udp-multicast-ttl.c
test/test-udp-open.c
test/test-udp-options.c
test/test-udp-send-and-recv.c
test/test-util.c
test/test-walk-handles.c
"

View File

@ -567,21 +567,6 @@ UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
UV_EXTERN uv_buf_t uv_buf_init(char* base, unsigned int len);
/*
* Utility function. Copies up to `size` characters from `src` to `dst`
* and ensures that `dst` is properly NUL terminated unless `size` is zero.
*/
UV_EXTERN size_t uv_strlcpy(char* dst, const char* src, size_t size);
/*
* Utility function. Appends `src` to `dst` and ensures that `dst` is
* properly NUL terminated unless `size` is zero or `dst` does not
* contain a NUL byte. `size` is the total length of `dst` so at most
* `size - strlen(dst) - 1` characters will be copied from `src`.
*/
UV_EXTERN size_t uv_strlcat(char* dst, const char* src, size_t size);
#define UV_STREAM_FIELDS \
/* number of bytes queued for writing */ \
size_t write_queue_size; \

View File

@ -72,7 +72,8 @@ int uv_pipe_bind(uv_pipe_t* handle, const char* name) {
sockfd = err;
memset(&saddr, 0, sizeof saddr);
uv_strlcpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path));
strncpy(saddr.sun_path, pipe_fname, sizeof(saddr.sun_path) - 1);
saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
saddr.sun_family = AF_UNIX;
if (bind(sockfd, (struct sockaddr*)&saddr, sizeof saddr)) {
@ -167,7 +168,8 @@ void uv_pipe_connect(uv_connect_t* req,
}
memset(&saddr, 0, sizeof saddr);
uv_strlcpy(saddr.sun_path, name, sizeof(saddr.sun_path));
strncpy(saddr.sun_path, name, sizeof(saddr.sun_path) - 1);
saddr.sun_path[sizeof(saddr.sun_path) - 1] = '\0';
saddr.sun_family = AF_UNIX;
do {

View File

@ -66,40 +66,6 @@ size_t uv_req_size(uv_req_type type) {
#undef XX
size_t uv_strlcpy(char* dst, const char* src, size_t size) {
size_t n;
if (size == 0)
return 0;
for (n = 0; n < (size - 1) && *src != '\0'; n++)
*dst++ = *src++;
*dst = '\0';
return n;
}
size_t uv_strlcat(char* dst, const char* src, size_t size) {
size_t n;
if (size == 0)
return 0;
for (n = 0; n < size && *dst != '\0'; n++, dst++);
if (n == size)
return n;
while (n < (size - 1) && *src != '\0')
n++, *dst++ = *src++;
*dst = '\0';
return n;
}
uv_buf_t uv_buf_init(char* base, unsigned int len) {
uv_buf_t buf;

View File

@ -209,8 +209,6 @@ TEST_DECLARE (thread_local_storage)
TEST_DECLARE (thread_mutex)
TEST_DECLARE (thread_rwlock)
TEST_DECLARE (thread_create)
TEST_DECLARE (strlcpy)
TEST_DECLARE (strlcat)
TEST_DECLARE (dlerror)
TEST_DECLARE (poll_duplex)
TEST_DECLARE (poll_unidirectional)
@ -505,8 +503,6 @@ TASK_LIST_START
TEST_ENTRY (thread_mutex)
TEST_ENTRY (thread_rwlock)
TEST_ENTRY (thread_create)
TEST_ENTRY (strlcpy)
TEST_ENTRY (strlcat)
TEST_ENTRY (dlerror)
TEST_ENTRY (ip6_addr_link_local)
#if 0

View File

@ -1,97 +0,0 @@
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#include "uv.h"
#include "task.h"
#include <string.h>
#define memeq(a, b, c) (memcmp((a), (b), (c)) == 0)
TEST_IMPL(strlcpy) {
size_t r;
{
char dst[2] = "A";
r = uv_strlcpy(dst, "", 0);
ASSERT(r == 0);
ASSERT(memeq(dst, "A", 1));
}
{
char dst[2] = "A";
r = uv_strlcpy(dst, "B", 1);
ASSERT(r == 0);
ASSERT(memeq(dst, "", 1));
}
{
char dst[2] = "A";
r = uv_strlcpy(dst, "B", 2);
ASSERT(r == 1);
ASSERT(memeq(dst, "B", 2));
}
{
char dst[3] = "AB";
r = uv_strlcpy(dst, "CD", 3);
ASSERT(r == 2);
ASSERT(memeq(dst, "CD", 3));
}
return 0;
}
TEST_IMPL(strlcat) {
size_t r;
{
char dst[2] = "A";
r = uv_strlcat(dst, "B", 1);
ASSERT(r == 1);
ASSERT(memeq(dst, "A", 2));
}
{
char dst[2] = "A";
r = uv_strlcat(dst, "B", 2);
ASSERT(r == 1);
ASSERT(memeq(dst, "A", 2));
}
{
char dst[3] = "A";
r = uv_strlcat(dst, "B", 3);
ASSERT(r == 2);
ASSERT(memeq(dst, "AB", 3));
}
{
char dst[5] = "AB";
r = uv_strlcat(dst, "CD", 5);
ASSERT(r == 4);
ASSERT(memeq(dst, "ABCD", 5));
}
return 0;
}

1
uv.gyp
View File

@ -297,7 +297,6 @@
'test/runner.h',
'test/test-get-loadavg.c',
'test/task.h',
'test/test-util.c',
'test/test-active.c',
'test/test-async.c',
'test/test-async-null-cb.c',