[pacman-dev] [PATCH 4/9] Add a helper method for retrieving the DB signature path

Dan McGee dpmcgee at gmail.com
Thu Jun 9 15:00:00 EDT 2011


On Wed, Jun 8, 2011 at 6:27 AM, Allan McRae <allan at archlinux.org> wrote:
> On 08/06/11 17:51, Dan McGee wrote:
>>
>> Note that is a bit different than the normal _alpm_db_path() method; the
>> caller is expected to free the result.
>>
>> Signed-off-by: Dan McGee<dan at archlinux.org>
>> ---
>>  lib/libalpm/db.c |   14 ++++++++++++++
>>  lib/libalpm/db.h |    1 +
>>  2 files changed, 15 insertions(+), 0 deletions(-)
>>
>> diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
>> index b2f3762..f26eaae 100644
>> --- a/lib/libalpm/db.c
>> +++ b/lib/libalpm/db.c
>> @@ -378,6 +378,20 @@ int _alpm_db_version(pmdb_t *db)
>>        return db->ops->version(db);
>>  }
>>
>> +char *_alpm_db_sig_path(pmdb_t *db)
>> +{
>> +       char *sigpath;
>> +       size_t len;
>> +       const char *dbfile = _alpm_db_path(db);
>> +       if(!db || !dbfile) {
>> +               return NULL;
>> +       }
>> +       len = strlen(dbfile) + strlen(".sig") + 1;
>
> Note that most other places we just do "+ 5" rather than the strlen(".sig").
>  Not that it matters given it will be optimised out...
Yeah, at least here clarity won the battle for me of how to write it.
I'm fine with doing it the strlen(static string) way as far as coding
standards goes. It doesn't look like there are all that many of these
anyway.

-Dan

$ git grep 'len =.*+.*[0-9]*[02-9];' | cat
lib/libalpm/add.c:			size_t backup_len = strlen(oldbackup) + 34;
lib/libalpm/add.c:			size_t backup_len = strlen(oldbackup) + 34;
lib/libalpm/be_local.c:	len = strlen(dbpath) + strlen(info->name) +
strlen(info->version) + 3;
lib/libalpm/be_sync.c:	size_t len = strlen(dbpath) + 6;
lib/libalpm/be_sync.c:		len = strlen(server) + strlen(db->treename) + 9;
lib/libalpm/dload.c:		len = strlen(url) + 5;
lib/libalpm/signing.c:		size_t len = strlen(path) + 5;
lib/libalpm/sync.c:				len = strlen(cachedir) + strlen(d->from) + 2;
lib/libalpm/sync.c:			len = strlen(cachedir) + strlen(d->to) + 2;
lib/libalpm/sync.c:					len = strlen(server_url) + strlen(filename) + 2;
lib/libalpm/trans.c:			size_t len = strlen(pkgname) + strlen(pkgver) +
strlen(pkgarch) + 3;
src/pacman/callback.c:	len = strlen(opr) + ((pkgname) ?
strlen(pkgname) : 0) + 2;
src/pacman/conf.c:	size_t len = strlen(path) + strlen(filename) + 6;


More information about the pacman-dev mailing list