utent->ut_type = USER_PROCESS;
utent->ut_pid = main_pid;
- STRNCPY(utent->ut_line, line);
+ strncpy_a(utent->ut_line, line);
if ( (NULL != ut)
&& ('\0' != ut->ut_id[0])) {
- STRNCPY(utent->ut_id, ut->ut_id);
+ strncpy_a(utent->ut_id, ut->ut_id);
} else {
- STRNCPY(utent->ut_id, strnul(line) - MIN(strlen(line), countof(utent->ut_id)));
+ strncpy_a(utent->ut_id, strnul(line) - MIN(strlen(line), countof(utent->ut_id)));
}
#if defined(HAVE_STRUCT_UTMPX_UT_NAME)
- STRNCPY(utent->ut_name, name);
+ strncpy_a(utent->ut_name, name);
#endif
- STRNCPY(utent->ut_user, name);
+ strncpy_a(utent->ut_user, name);
if (NULL != hostname) {
struct addrinfo *info = NULL;
#if defined(HAVE_STRUCT_UTMPX_UT_HOST)
- STRNCPY(utent->ut_host, hostname);
+ strncpy_a(utent->ut_host, hostname);
#endif
#if defined(HAVE_STRUCT_UTMPX_UT_SYSLEN)
utent->ut_syslen = MIN (strlen (hostname),
#include "string/strcpy/strncpy.h"
-static void test_STRNCPY_trunc(void **state);
-static void test_STRNCPY_fit(void **state);
-static void test_STRNCPY_pad(void **state);
+static void test_strncpy_a_trunc(void **state);
+static void test_strncpy_a_fit(void **state);
+static void test_strncpy_a_pad(void **state);
int
main(void)
{
const struct CMUnitTest tests[] = {
- cmocka_unit_test(test_STRNCPY_trunc),
- cmocka_unit_test(test_STRNCPY_fit),
- cmocka_unit_test(test_STRNCPY_pad),
+ cmocka_unit_test(test_strncpy_a_trunc),
+ cmocka_unit_test(test_strncpy_a_fit),
+ cmocka_unit_test(test_strncpy_a_pad),
};
return cmocka_run_group_tests(tests, NULL, NULL);
static void
-test_STRNCPY_trunc(void **state)
+test_strncpy_a_trunc(void **state)
{
char buf[3];
char src1[4] = {'f', 'o', 'o', 'o'};
char res1[3] = {'f', 'o', 'o'};
- assert_true(memcmp(res1, STRNCPY(buf, src1), sizeof(buf)) == 0);
+ assert_true(memcmp(res1, strncpy_a(buf, src1), sizeof(buf)) == 0);
char src2[5] = "barb";
char res2[3] = {'b', 'a', 'r'};
- assert_true(memcmp(res2, STRNCPY(buf, src2), sizeof(buf)) == 0);
+ assert_true(memcmp(res2, strncpy_a(buf, src2), sizeof(buf)) == 0);
}
static void
-test_STRNCPY_fit(void **state)
+test_strncpy_a_fit(void **state)
{
char buf[3];
char src1[3] = {'b', 'a', 'z'};
char res1[3] = {'b', 'a', 'z'};
- assert_true(memcmp(res1, STRNCPY(buf, src1), sizeof(buf)) == 0);
+ assert_true(memcmp(res1, strncpy_a(buf, src1), sizeof(buf)) == 0);
char src2[4] = "qwe";
char res2[3] = {'q', 'w', 'e'};
- assert_true(memcmp(res2, STRNCPY(buf, src2), sizeof(buf)) == 0);
+ assert_true(memcmp(res2, strncpy_a(buf, src2), sizeof(buf)) == 0);
}
static void
-test_STRNCPY_pad(void **state)
+test_strncpy_a_pad(void **state)
{
char buf[3];
char src1[3] = "as";
char res1[3] = {'a', 's', 0};
- assert_true(memcmp(res1, STRNCPY(buf, src1), sizeof(buf)) == 0);
+ assert_true(memcmp(res1, strncpy_a(buf, src1), sizeof(buf)) == 0);
char src2[3] = "";
char res2[3] = {0, 0, 0};
- assert_true(memcmp(res2, STRNCPY(buf, src2), sizeof(buf)) == 0);
+ assert_true(memcmp(res2, strncpy_a(buf, src2), sizeof(buf)) == 0);
char src3[3] = {'a', 0, 'b'};
char res3[3] = {'a', 0, 0};
- assert_true(memcmp(res3, STRNCPY(buf, src3), sizeof(buf)) == 0);
+ assert_true(memcmp(res3, strncpy_a(buf, src3), sizeof(buf)) == 0);
}