From owner-svn-soc-all@FreeBSD.ORG Mon Jun 24 22:15:36 2013 Return-Path: Delivered-To: svn-soc-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 61B47699 for ; Mon, 24 Jun 2013 22:15:36 +0000 (UTC) (envelope-from mattbw@FreeBSD.org) Received: from socsvn.freebsd.org (socsvn.freebsd.org [IPv6:2001:1900:2254:206a::50:2]) by mx1.freebsd.org (Postfix) with ESMTP id 53C511259 for ; Mon, 24 Jun 2013 22:15:36 +0000 (UTC) Received: from socsvn.freebsd.org ([127.0.1.124]) by socsvn.freebsd.org (8.14.7/8.14.7) with ESMTP id r5OMFahB056276 for ; Mon, 24 Jun 2013 22:15:36 GMT (envelope-from mattbw@FreeBSD.org) Received: (from www@localhost) by socsvn.freebsd.org (8.14.7/8.14.6/Submit) id r5OMFa0x056274 for svn-soc-all@FreeBSD.org; Mon, 24 Jun 2013 22:15:36 GMT (envelope-from mattbw@FreeBSD.org) Date: Mon, 24 Jun 2013 22:15:36 GMT Message-Id: <201306242215.r5OMFa0x056274@socsvn.freebsd.org> X-Authentication-Warning: socsvn.freebsd.org: www set sender to mattbw@FreeBSD.org using -f From: mattbw@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r253457 - soc2013/mattbw/backend MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-soc-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the entire Summer of Code repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jun 2013 22:15:36 -0000 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 /* NULL */ -#include /* strdup */ +#include /* 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);