[PATCH v3] socket: Add new test for shutdown

Florian Weimer fweimer@redhat.com
Tue Jun 25 08:20:23 GMT 2024


* Sergey Kolosov:

> +/* Open a file and check that shutdown fails with the ENOTSOCK error code.  */
> +void
> +do_test_enotsock (void)
> +{
> +  char *tmp_dir = support_create_temp_directory ("tst-shutdown-");
> +  char *path_to_file = xasprintf ("%s/shutdown.txt", tmp_dir);
> +
> +  /* Open file and check that shutdown will fail with ENOTSOCK.  */
> +  int fd = xopen (path_to_file, O_CREAT | O_RDWR, S_IRWXU);
> +
> +  int result = shutdown (fd, SHUT_RD);
> +  if (result == 0 || errno != ENOTSOCK)
> +    {
> +      FAIL_EXIT1 ("shutdown should fail with ENOTSOCK");
> +    }
> +  xclose (fd);
> +
> +  /* Remove file, temp directory will be removed itself.  */
> +  xunlink (path_to_file);
> +}

You can simplify this by using a pre-existing file such as /dev/null.
Then you can remove “#include <support/temp_file.h>”, too.

Thanks,
Florian



More information about the Libc-alpha mailing list