[pacman-dev] [PATCH 2/2] Fix some warning that cppcheck gave back
Laszlo Papp
djszapi2 at gmail.com
Sun Oct 25 06:33:26 EDT 2009
opendir(path)) == (DIR *)-1 is maybe the result of miss understanding of the man
page, if the opendir wasn't successful it gives back NULL instead of '(DIR *)-1'.
The ambiguity while cycle with EINTR condition was refactored for a do {} while ()
cycle to be easier to read/understand
The 'errno == EINTR' condition examinations were changed for 'pm_errno == EINTR'
in the api, in trans.c and util.c, where the do {} while {} changings happened too.
Signed-off-by: Laszlo Papp <djszapi at archlinux.us>
---
lib/libalpm/trans.c | 5 ++++-
lib/libalpm/util.c | 11 +++++++----
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index aea71db..22ff3fd 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -243,6 +243,7 @@ int SYMEXPORT alpm_trans_interrupt()
int SYMEXPORT alpm_trans_release()
{
pmtrans_t *trans;
+ int fd;
ALPM_LOG_FUNC;
@@ -261,7 +262,9 @@ int SYMEXPORT alpm_trans_release()
/* unlock db */
if(!nolock_flag) {
if(handle->lckfd != -1) {
- while(close(handle->lckfd) == -1 && errno == EINTR);
+ do {
+ fd = close(handle->lckfd);
+ } while(fd == -1 && pm_errno == EINTR);
handle->lckfd = -1;
}
if(_alpm_lckrm()) {
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 1340da9..cf0deed 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -224,8 +224,9 @@ int _alpm_lckmk()
_alpm_makepath(dir);
FREE(dir);
- while((fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000)) == -1
- && errno == EINTR);
+ do {
+ fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000);
+ } while ( fd == -1 && pm_errno == EINTR);
if(fd > 0) {
FILE *f = fdopen(fd, "w");
fprintf(f, "%ld\n", (long)getpid());
@@ -401,7 +402,7 @@ int _alpm_rmrf(const char *path)
}
}
} else {
- if((dirp = opendir(path)) == (DIR *)-1) {
+ if((dirp = opendir(path)) == NULL) {
return(1);
}
for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) {
@@ -522,7 +523,9 @@ int _alpm_run_chroot(const char *root, const char *cmd)
/* this code runs for the parent only (wait on the child) */
pid_t retpid;
int status;
- while((retpid = waitpid(pid, &status, 0)) == -1 && errno == EINTR);
+ do {
+ retpid = waitpid(pid, &status, 0);
+ } while(retpid == -1 && pm_errno == EINTR);
if(retpid == -1) {
_alpm_log(PM_LOG_ERROR, _("call to waitpid failed (%s)\n"),
strerror(errno));
--
1.6.5
More information about the pacman-dev
mailing list