tst-sockaddr_un_set.c 2.0 KB

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