Date: Mon, 24 Jun 2013 22:15:36 GMT From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253457 - soc2013/mattbw/backend Message-ID: <201306242215.r5OMFa0x056274@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: mattbw Date: Mon Jun 24 22:15:36 2013 New Revision: 253457 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253457 Log: use strchr instead of rolling our own Modified: soc2013/mattbw/backend/groups.c Modified: soc2013/mattbw/backend/groups.c ============================================================================== --- soc2013/mattbw/backend/groups.c Mon Jun 24 21:33:19 2013 (r253456) +++ soc2013/mattbw/backend/groups.c Mon Jun 24 22:15:36 2013 (r253457) @@ -19,13 +19,15 @@ */ #include <stdlib.h> /* NULL */ -#include <string.h> /* strdup */ +#include <string.h> /* strchr, strdup */ #include "glib.h" /* g_strcmp0 */ #include "pk-backend.h" /* PkGroupEnum, PK_* */ #include "groups.h" /* prototypes */ +const char ORIGIN_SEPARATOR = '/'; + struct group_mapping { const char *dir; PkGroupEnum group; @@ -140,20 +142,19 @@ group_from_origin(const char *origin) { char *dir; - int i; + char *sep; PkGroupEnum group; /* Find the separation between dir and port name */ - for (i = 0; origin[i] != '/' && origin[i] != '\0'; i++); - - /* Is this a valid origin? If not, we want the default group */ - if (origin[i] == '\0') - dir = NULL; - else - dir = strndup(origin, i); + sep = strchr(origin, ORIGIN_SEPARATOR); + /* Is this a valid origin (did it have a separator)? + * If not, we want the default group. + * If so, then the number of chars between the origin start and the + * separator mark the port directory name we want to use. + */ + dir = (sep == NULL ? NULL : strndup(origin, sep - origin)); group = group_from_port_dir(dir); - if (dir) free(dir);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306242215.r5OMFa0x056274>