mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
Refactor do/while cycle and multiple while cycles
* It makes the code clearer to read/understand * Cppcheck tool doesn't show this anymore: [./util.c:215]: (error) Resource leak: fd [Dan: don't change the coding style] Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
120cd312e4
commit
be266b4364
@ -261,7 +261,10 @@ int SYMEXPORT alpm_trans_release()
|
|||||||
/* unlock db */
|
/* unlock db */
|
||||||
if(!nolock_flag) {
|
if(!nolock_flag) {
|
||||||
if(handle->lckfd != -1) {
|
if(handle->lckfd != -1) {
|
||||||
while(close(handle->lckfd) == -1 && errno == EINTR);
|
int fd;
|
||||||
|
do {
|
||||||
|
fd = close(handle->lckfd);
|
||||||
|
} while(fd == -1 && errno == EINTR);
|
||||||
handle->lckfd = -1;
|
handle->lckfd = -1;
|
||||||
}
|
}
|
||||||
if(_alpm_lckrm()) {
|
if(_alpm_lckrm()) {
|
||||||
|
@ -212,8 +212,9 @@ int _alpm_lckmk()
|
|||||||
_alpm_makepath(dir);
|
_alpm_makepath(dir);
|
||||||
FREE(dir);
|
FREE(dir);
|
||||||
|
|
||||||
while((fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000)) == -1
|
do {
|
||||||
&& errno == EINTR);
|
fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0000);
|
||||||
|
} while (fd == -1 && errno == EINTR);
|
||||||
if(fd > 0) {
|
if(fd > 0) {
|
||||||
FILE *f = fdopen(fd, "w");
|
FILE *f = fdopen(fd, "w");
|
||||||
fprintf(f, "%ld\n", (long)getpid());
|
fprintf(f, "%ld\n", (long)getpid());
|
||||||
@ -315,7 +316,7 @@ int _alpm_unpack(const char *archive, const char *prefix, alpm_list_t *list, int
|
|||||||
|
|
||||||
st = archive_entry_stat(entry);
|
st = archive_entry_stat(entry);
|
||||||
entryname = archive_entry_pathname(entry);
|
entryname = archive_entry_pathname(entry);
|
||||||
|
|
||||||
if(S_ISREG(st->st_mode)) {
|
if(S_ISREG(st->st_mode)) {
|
||||||
archive_entry_set_perm(entry, 0644);
|
archive_entry_set_perm(entry, 0644);
|
||||||
} else if(S_ISDIR(st->st_mode)) {
|
} else if(S_ISDIR(st->st_mode)) {
|
||||||
@ -511,7 +512,9 @@ int _alpm_run_chroot(const char *root, const char *cmd)
|
|||||||
/* this code runs for the parent only (wait on the child) */
|
/* this code runs for the parent only (wait on the child) */
|
||||||
pid_t retpid;
|
pid_t retpid;
|
||||||
int status;
|
int status;
|
||||||
while((retpid = waitpid(pid, &status, 0)) == -1 && errno == EINTR);
|
do {
|
||||||
|
retpid = waitpid(pid, &status, 0);
|
||||||
|
} while(retpid == -1 && errno == EINTR);
|
||||||
if(retpid == -1) {
|
if(retpid == -1) {
|
||||||
_alpm_log(PM_LOG_ERROR, _("call to waitpid failed (%s)\n"),
|
_alpm_log(PM_LOG_ERROR, _("call to waitpid failed (%s)\n"),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
@ -234,7 +234,9 @@ static void cleanup(int ret) {
|
|||||||
static ssize_t xwrite(int fd, const void *buf, size_t count)
|
static ssize_t xwrite(int fd, const void *buf, size_t count)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
while((ret = write(fd, buf, count)) == -1 && errno == EINTR);
|
do {
|
||||||
|
ret = write(fd, buf, count);
|
||||||
|
} while(ret == -1 && errno == EINTR);
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user