chiark / gitweb /
util: introduce strcaseeq/strncaseeq
authorThomas Hindoe Paaboel Andersen <phomes@gmail.com>
Tue, 12 Feb 2013 20:47:37 +0000 (21:47 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Feb 2013 23:56:13 +0000 (00:56 +0100)
src/shared/calendarspec.c
src/shared/util.c
src/shared/util.h
src/udev/scsi_id/scsi_id.c

index c2eae3f139cd542241d4cdd978db390fd0be21c4..cc680779b52dd3e113fbb9ebf776b307050ae43b 100644 (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;
 
index 8dceb820516fe4ac83dc4b2f4afc3ad26e4ef0d8..aa0532a2be71e1f27888b4da94fe1240187c7069 100644 (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;
index cd13457528c14d2727483b1497e673adc404c9db..3ad90ddce416814f337c17a8321ee1b9d33bd3c4 100644 (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);
 
index d664787fd9c8846e237fb4563056eae2a04eecd3..dcf03eefac6faa06298959b4e9cb07802b00a9f6 100644 (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();