]> git.ipfire.org Git - thirdparty/glibc.git/blame - posix/tst-regex.c
Add missing libc_hidden_weak/def calls
[thirdparty/glibc.git] / posix / tst-regex.c
CommitLineData
bfff8b1b 1/* Copyright (C) 2001-2017 Free Software Foundation, Inc.
d8f00d46
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
d8f00d46
UD
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
d8f00d46 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
d8f00d46 17
d8f00d46
UD
18#include <assert.h>
19#include <errno.h>
20#include <error.h>
21#include <fcntl.h>
bb3f4825 22#include <getopt.h>
d8f00d46
UD
23#include <iconv.h>
24#include <locale.h>
25#include <mcheck.h>
ceaa9889 26#include <stdint.h>
d8f00d46
UD
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
30#include <time.h>
31#include <unistd.h>
32#include <sys/stat.h>
33#include <sys/types.h>
34#include <regex.h>
35
36
bf7c04cd 37#if defined _POSIX_CPUTIME && _POSIX_CPUTIME >= 0
d8f00d46
UD
38static clockid_t cl;
39static int use_clock;
40#endif
73111f03
UD
41static iconv_t cd;
42static char *mem;
43static char *umem;
44static size_t memlen;
3c0fb574 45static size_t umemlen;
bb3f4825 46static int timing;
d8f00d46 47
3c0fb574 48static int test_expr (const char *expr, int expected, int expectedicase);
73111f03 49static int run_test (const char *expr, const char *mem, size_t memlen,
3c0fb574
UD
50 int icase, int expected);
51static int run_test_backwards (const char *expr, const char *mem,
52 size_t memlen, int icase, int expected);
d8f00d46
UD
53
54
7166d23f
UD
55static int
56do_test (void)
d8f00d46
UD
57{
58 const char *file;
d8f00d46
UD
59 int fd;
60 struct stat st;
d8f00d46
UD
61 int result;
62 char *inmem;
63 char *outmem;
64 size_t inlen;
65 size_t outlen;
d8f00d46
UD
66
67 mtrace ();
68
69 /* Make the content of the file available in memory. */
b3008279 70 file = "../ChangeLog.old/ChangeLog.8";
d8f00d46
UD
71 fd = open (file, O_RDONLY);
72 if (fd == -1)
73 error (EXIT_FAILURE, errno, "cannot open %s", basename (file));
74
75 if (fstat (fd, &st) != 0)
76 error (EXIT_FAILURE, errno, "cannot stat %s", basename (file));
77 memlen = st.st_size;
78
79 mem = (char *) malloc (memlen + 1);
80 if (mem == NULL)
81 error (EXIT_FAILURE, errno, "while allocating buffer");
82
3c0fb574 83 if ((size_t) read (fd, mem, memlen) != memlen)
d8f00d46
UD
84 error (EXIT_FAILURE, 0, "cannot read entire file");
85 mem[memlen] = '\0';
86
87 close (fd);
88
2f07975d 89 /* We have to convert a few things from Latin-1 to UTF-8. */
d8f00d46
UD
90 cd = iconv_open ("UTF-8", "ISO-8859-1");
91 if (cd == (iconv_t) -1)
92 error (EXIT_FAILURE, errno, "cannot get conversion descriptor");
93
2f07975d
UD
94 /* For the second test we have to convert the file content to UTF-8.
95 Since the text is mostly ASCII it should be enough to allocate
96 twice as much memory for the UTF-8 text than for the Latin-1
97 text. */
98 umem = (char *) calloc (2, memlen);
99 if (umem == NULL)
100 error (EXIT_FAILURE, errno, "while allocating buffer");
101
d8f00d46
UD
102 inmem = mem;
103 inlen = memlen;
104 outmem = umem;
2f07975d 105 outlen = 2 * memlen - 1;
d8f00d46 106 iconv (cd, &inmem, &inlen, &outmem, &outlen);
3c0fb574 107 umemlen = outmem - umem;
d8f00d46
UD
108 if (inlen != 0)
109 error (EXIT_FAILURE, errno, "cannot convert buffer");
110
bf7c04cd
UD
111#if defined _POSIX_CPUTIME && _POSIX_CPUTIME >= 0
112# if _POSIX_CPUTIME == 0
113 if (sysconf (_SC_CPUTIME) < 0)
114 use_clock = 0;
115 else
116# endif
117 /* See whether we can use the CPU clock. */
118 use_clock = clock_getcpuclockid (0, &cl) == 0;
73111f03
UD
119#endif
120
2f07975d
UD
121#ifdef DEBUG
122 re_set_syntax (RE_DEBUG);
123#endif
124
73111f03
UD
125 /* Run the actual tests. All tests are run in a single-byte and a
126 multi-byte locale. */
3c0fb574
UD
127