hr_HR locale: fix collation and expand collation test file
[glibc.git] / support / tst-xreadlink.c
bloba4a22812c14c6453d3d5a70d83772a1da839952f
1 /* Test the xreadlink function.
2 Copyright (C) 2017 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 <http://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <fcntl.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <support/check.h>
25 #include <support/support.h>
26 #include <support/temp_file.h>
27 #include <support/xunistd.h>
29 static int
30 do_test (void)
32 char *dir = support_create_temp_directory ("tst-xreadlink-");
33 char *symlink_name = xasprintf ("%s/symlink", dir);
34 add_temp_file (symlink_name);
36 /* The limit 10000 is arbitrary and simply there to prevent an
37 attempt to exhaust all available disk space. */
38 for (int size = 1; size < 10000; ++size)
40 char *contents = xmalloc (size + 1);
41 for (int i = 0; i < size; ++i)
42 contents[i] = 'a' + (rand () % 26);
43 contents[size] = '\0';
44 if (symlink (contents, symlink_name) != 0)
46 if (errno == ENAMETOOLONG)
48 printf ("info: ENAMETOOLONG failure at %d bytes\n", size);
49 free (contents);
50 break;
52 FAIL_EXIT1 ("symlink (%d bytes): %m", size);
55 char *readlink_result = xreadlink (symlink_name);
56 TEST_VERIFY (strcmp (readlink_result, contents) == 0);
57 free (readlink_result);
58 xunlink (symlink_name);
59 free (contents);
62 /* Create an empty file to suppress the temporary file deletion
63 warning. */
64 xclose (xopen (symlink_name, O_WRONLY | O_CREAT, 0));
66 free (symlink_name);
67 free (dir);
69 return 0;
72 #include <support/test-driver.c>