1 /* Test the __sockaddr_un_set function.
2 Copyright (C) 2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 /* Re-compile the function because the version in libc is not
21 #include "sockaddr_un_set.c"
23 #include <support/check.h>
28 struct sockaddr_un sun
;
30 memset (&sun
, 0xcc, sizeof (sun
));
31 __sockaddr_un_set (&sun
, "");
32 TEST_COMPARE (sun
.sun_family
, AF_UNIX
);
33 TEST_COMPARE (__sockaddr_un_set (&sun
, ""), 0);
35 memset (&sun
, 0xcc, sizeof (sun
));
36 TEST_COMPARE (__sockaddr_un_set (&sun
, "/example"), 0);
37 TEST_COMPARE_STRING (sun
.sun_path
, "/example");
40 char pathname
[108]; /* Length of sun_path (ABI constant). */
41 memset (pathname
, 'x', sizeof (pathname
));
42 pathname
[sizeof (pathname
) - 1] = '\0';
43 memset (&sun
, 0xcc, sizeof (sun
));
44 TEST_COMPARE (__sockaddr_un_set (&sun
, pathname
), 0);
45 TEST_COMPARE (sun
.sun_family
, AF_UNIX
);
46 TEST_COMPARE_STRING (sun
.sun_path
, pathname
);
51 memset (pathname
, 'x', sizeof (pathname
));
52 pathname
[sizeof (pathname
) - 1] = '\0';
53 memset (&sun
, 0xcc, sizeof (sun
));
55 TEST_COMPARE (__sockaddr_un_set (&sun
, pathname
), -1);
56 TEST_COMPARE (errno
, EINVAL
);
62 #include <support/test-driver.c>