| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-march=rv64gcv -mabi=lp64d -O2" } */ |
| 3 |
|
| 4 |
#include <string.h> |
| 5 |
|
| 6 |
/* Return the number of DNS hierarchy levels in the name. */ |
| 7 |
int |
| 8 |
test (const char *name) { |
| 9 |
int i, len, count; |
| 10 |
|
| 11 |
len = strlen(name); |
| 12 |
for (i = 0, count = 0; i < len; i++) { |
| 13 |
/* XXX need to check for \. or use named's nlabels(). */ |
| 14 |
if (name[i] == '.') |
| 15 |
count++; |
| 16 |
} |
| 17 |
|
| 18 |
/* don't count initial wildcard */ |
| 19 |
if (name[0] == '*') |
| 20 |
if (count) |
| 21 |
count--; |
| 22 |
|
| 23 |
/* don't count the null label for root. */ |
| 24 |
/* if terminating '.' not found, must adjust */ |
| 25 |
/* count to include last label */ |
| 26 |
if (len > 0 && name[len-1] != '.') |
| 27 |
count++; |
| 28 |
return (count); |
| 29 |
} |