aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-08-27 23:17:43 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2015-08-27 23:17:43 +0000
commitc2e634dd303a44b11e30ab31e39ffc4eae5467f8 (patch)
treec641095a3245546c28bde043493ea0dfad8f624e
parent46c7bc83ab0324983312f16bd40cc1cdfe11cce6 (diff)
parentadf5c7237da419393462a19c94c102abf7865c78 (diff)
downloadbionic-c2e634dd303a44b11e30ab31e39ffc4eae5467f8.tar.gz
Merge "Fix regoff_t for LP32 and _FILE_OFFSET_BITS=64."
-rw-r--r--libc/include/regex.h5
-rw-r--r--tests/regex_test.cpp10
2 files changed, 13 insertions, 2 deletions
diff --git a/libc/include/regex.h b/libc/include/regex.h
index aec38e334..b06a515b4 100644
--- a/libc/include/regex.h
+++ b/libc/include/regex.h
@@ -42,8 +42,9 @@
#include <sys/cdefs.h>
#include <sys/types.h>
-/* types */
-typedef off_t regoff_t;
+/* POSIX says regoff_t is at least as large as the larger of ptrdiff_t and
+ * ssize_t. BSD uses off_t, but that interacts badly with _FILE_OFFSET_BITS. */
+typedef ssize_t regoff_t;
typedef struct {
int re_magic;
diff --git a/tests/regex_test.cpp b/tests/regex_test.cpp
index d02622190..4a4409ef3 100644
--- a/tests/regex_test.cpp
+++ b/tests/regex_test.cpp
@@ -36,3 +36,13 @@ TEST(regex, smoke) {
regfree(&re);
}
+
+TEST(regex, match_offsets) {
+ regex_t re;
+ regmatch_t matches[1];
+ ASSERT_EQ(0, regcomp(&re, "b", 0));
+ ASSERT_EQ(0, regexec(&re, "abc", 1, matches, 0));
+ ASSERT_EQ(1, matches[0].rm_so);
+ ASSERT_EQ(2, matches[0].rm_eo);
+ regfree(&re);
+}