util: introduce strcaseeq/strncaseeq

This commit is contained in:
Thomas Hindoe Paaboel Andersen 2013-02-12 21:47:37 +01:00 committed by Lennart Poettering
parent 641906e936
commit b43d1d01ea
4 changed files with 11 additions and 9 deletions

View File

@ -653,7 +653,7 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
if (!c)
return -ENOMEM;
if (strcasecmp(p, "hourly") == 0) {
if (strcaseeq(p, "hourly")) {
r = const_chain(0, &c->minute);
if (r < 0)
goto fail;
@ -661,7 +661,7 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
if (r < 0)
goto fail;
} else if (strcasecmp(p, "daily") == 0) {
} else if (strcaseeq(p, "daily")) {
r = const_chain(0, &c->hour);
if (r < 0)
goto fail;
@ -672,7 +672,7 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
if (r < 0)
goto fail;
} else if (strcasecmp(p, "monthly") == 0) {
} else if (strcaseeq(p, "monthly")) {
r = const_chain(1, &c->day);
if (r < 0)
goto fail;
@ -686,7 +686,7 @@ int calendar_spec_from_string(const char *p, CalendarSpec **spec) {
if (r < 0)
goto fail;
} else if (strcasecmp(p, "weekly") == 0) {
} else if (strcaseeq(p, "weekly")) {
c->weekdays_bits = 1;

View File

@ -218,9 +218,9 @@ void close_many(const int fds[], unsigned n_fd) {
int parse_boolean(const char *v) {
assert(v);
if (streq(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || !strcasecmp(v, "on"))
if (streq(v, "1") || v[0] == 'y' || v[0] == 'Y' || v[0] == 't' || v[0] == 'T' || strcaseeq(v, "on"))
return 1;
else if (streq(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || !strcasecmp(v, "off"))
else if (streq(v, "0") || v[0] == 'n' || v[0] == 'N' || v[0] == 'f' || v[0] == 'F' || strcaseeq(v, "off"))
return 0;
return -EINVAL;

View File

@ -65,6 +65,8 @@ size_t page_size(void);
#define streq(a,b) (strcmp((a),(b)) == 0)
#define strneq(a, b, n) (strncmp((a), (b), (n)) == 0)
#define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
#define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
bool streq_ptr(const char *a, const char *b);

View File

@ -227,7 +227,7 @@ static int get_file_options(struct udev *udev,
continue;
str1 = strsep(&buf, "=");
if (str1 && strcasecmp(str1, "VENDOR") == 0) {
if (str1 && strcaseeq(str1, "VENDOR")) {
str1 = get_value(&buf);
if (!str1) {
retval = log_oom();
@ -236,7 +236,7 @@ static int get_file_options(struct udev *udev,
vendor_in = str1;
str1 = strsep(&buf, "=");
if (str1 && strcasecmp(str1, "MODEL") == 0) {
if (str1 && strcaseeq(str1, "MODEL")) {
str1 = get_value(&buf);
if (!str1) {
retval = log_oom();
@ -247,7 +247,7 @@ static int get_file_options(struct udev *udev,
}
}
if (str1 && strcasecmp(str1, "OPTIONS") == 0) {
if (str1 && strcaseeq(str1, "OPTIONS")) {
str1 = get_value(&buf);
if (!str1) {
retval = log_oom();