FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 03-09-2012, 07:26 PM
Dan McGee
 
Default Prefer fputs/fputc over fprintf when writing local database

Using fputs should be faster as no format string parsing is required. It
also prevents silly errors related to unescaped '%' signs, and removes
the need to double them up in a lot of places.

Signed-off-by: Dan McGee <dan@archlinux.org>
---
lib/libalpm/be_local.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 55d949f..9090c81 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -759,7 +759,8 @@ static void write_deps(FILE *fp, const char *header, alpm_list_t *deplist)
fputc('
', fp);
for(lp = deplist; lp; lp = lp->next) {
char *depstring = alpm_dep_compute_string(lp->data);
- fprintf(fp, "%s
", depstring);
+ fputs(depstring, fp);
+ fputc('
', fp);
free(depstring);
}
fputc('
', fp);
@@ -802,9 +803,10 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
if(info->groups) {
fputs("%GROUPS%
", fp);
for(lp = info->groups; lp; lp = lp->next) {
- fprintf(fp, "%s
", (char *)lp->data);
+ fputs(lp->data, fp);
+ fputc('
', fp);
}
- fprintf(fp, "
");
+ fputc('
', fp);
}
if(info->url) {
fprintf(fp, "%%URL%%
"
@@ -813,9 +815,10 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
if(info->licenses) {
fputs("%LICENSE%
", fp);
for(lp = info->licenses; lp; lp = lp->next) {
- fprintf(fp, "%s
", (char *)lp->data);
+ fputs(lp->data, fp);
+ fputc('
', fp);
}
- fprintf(fp, "
");
+ fputc('
', fp);
}
if(info->arch) {
fprintf(fp, "%%ARCH%%
"
@@ -856,7 +859,7 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
if(info->validation & ALPM_PKG_VALIDATION_SIGNATURE) {
fputs("pgp
", fp);
}
- fprintf(fp, "
");
+ fputc('
', fp);
}

write_deps(fp, "%REPLACES%", info->replaces);
@@ -885,20 +888,21 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
free(path);
if(info->files.count) {
size_t i;
- fprintf(fp, "%%FILES%%
");
+ fputs("%FILES%
", fp);
for(i = 0; i < info->files.count; i++) {
const alpm_file_t *file = info->files.files + i;
- fprintf(fp, "%s
", file->name);
+ fputs(file->name, fp);
+ fputc('
', fp);
}
- fprintf(fp, "
");
+ fputc('
', fp);
}
if(info->backup) {
- fprintf(fp, "%%BACKUP%%
");
+ fputs("%BACKUP%
", fp);
for(lp = info->backup; lp; lp = lp->next) {
const alpm_backup_t *backup = lp->data;
fprintf(fp, "%s %s
", backup->name, backup->hash);
}
- fprintf(fp, "
");
+ fputc('
', fp);
}
fclose(fp);
fp = NULL;
--
1.7.9.3
 

Thread Tools




All times are GMT. The time now is 07:55 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org