[systemd-devel] [PATCH 3/3] introduce strcaseeq/strncaseeq
Lennart Poettering
lennart at poettering.net
Tue Feb 12 15:56:37 PST 2013
On Tue, 12.02.13 21:47, Thomas Hindoe Paaboel Andersen (phomes at gmail.com) wrote:
I commited the other two (after dropping the S-o-b).
>
> Signed-off-by: Thomas Hindoe Paaboel Andersen <phomes at gmail.com>
> ---
> src/shared/calendarspec.c | 8 ++++----
> src/shared/util.c | 4 ++--
> src/shared/util.h | 2 ++
> src/udev/scsi_id/scsi_id.c | 6 +++---
> 4 files changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c
> index c2eae3f..cc68077 100644
> --- a/src/shared/calendarspec.c
> +++ b/src/shared/calendarspec.c
> @@ -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;
>
> diff --git a/src/shared/util.c b/src/shared/util.c
> index 1b5538c..fa5d243 100644
> --- a/src/shared/util.c
> +++ b/src/shared/util.c
> @@ -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;
> diff --git a/src/shared/util.h b/src/shared/util.h
> index d926b01..1434416 100644
> --- a/src/shared/util.h
> +++ b/src/shared/util.h
> @@ -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);
>
> diff --git a/src/udev/scsi_id/scsi_id.c b/src/udev/scsi_id/scsi_id.c
> index 7765d22..ab7c54c 100644
> --- a/src/udev/scsi_id/scsi_id.c
> +++ b/src/udev/scsi_id/scsi_id.c
> @@ -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();
Lennart
--
Lennart Poettering - Red Hat, Inc.
More information about the systemd-devel
mailing list