From: Guillem Jover Date: Thu, 20 Mar 2008 04:14:06 +0000 (+0200) Subject: Move duplicate cleanup close functions to lib/cleanup.c X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3e919df71f0e67366cc8d40dc8bad953394a5d6e;p=dpkg Move duplicate cleanup close functions to lib/cleanup.c --- diff --git a/ChangeLog b/ChangeLog index b9776792..51d972fc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-03-20 Ian Jackson , + Guillem Jover + + * src/query.c (cu_closepipe, cu_closefile, cu_closefd): Remove + duplicated functions. + * src/help.c (cu_closepipe, cu_closefile, cu_closedir) + (cu_closefd): Move function definitions to ... + * lib/cleanup.c: ... here. New file. + * src/main.h (cu_closefile, cu_closepipe, cu_closedir) + (cu_closefd): Move prototypes to ... + * lib/dpkg.h: ... here. + * lib/Makefile.am (libdpkg_a_SOURCES): Add 'cleanup.c'. + 2008-03-20 Ian Jackson * lib/dpkg-db.h (modstatdb_checkpoint): New prototype. diff --git a/lib/Makefile.am b/lib/Makefile.am index 2c34bb23..ab34a3fa 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -15,6 +15,7 @@ libdpkg_a_SOURCES = \ dpkg-def.h \ dpkg.h \ dpkg-db.h \ + cleanup.c \ compat.c \ compression.c \ database.c \ diff --git a/lib/cleanup.c b/lib/cleanup.c new file mode 100644 index 00000000..4337062f --- /dev/null +++ b/lib/cleanup.c @@ -0,0 +1,59 @@ +/* + * libdpkg - Debian packaging suite library routines + * cleanup.c - cleanup functions, used when we need to unwind + * + * Copyright (C) 1995 Ian Jackson + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2, + * or (at your option) any later version. + * + * This is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with dpkg; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include + +void +cu_closepipe(int argc, void **argv) +{ + int *p1 = (int *)argv[0]; + + close(p1[0]); + close(p1[1]); +} + +void +cu_closefile(int argc, void **argv) +{ + FILE *f = (FILE *)(argv[0]); + + fclose(f); +} + +void +cu_closedir(int argc, void **argv) +{ + DIR *d = (DIR *)(argv[0]); + + closedir(d); +} + +void +cu_closefd(int argc, void **argv) +{ + int ip = *(int *)argv[0]; + + close(ip); +} + diff --git a/lib/dpkg.h b/lib/dpkg.h index 7e2e4283..17b8f28b 100644 --- a/lib/dpkg.h +++ b/lib/dpkg.h @@ -207,6 +207,13 @@ void badusage(const char *fmt, ...) NONRETURNING PRINTFFORMAT(1, 2); void werr(const char *what) NONRETURNING; void warningf(const char *fmt, ...) PRINTFFORMAT(1, 2); +/*** cleanup.c ***/ + +void cu_closefile(int argc, void **argv); +void cu_closepipe(int argc, void **argv); +void cu_closedir(int argc, void **argv); +void cu_closefd(int argc, void **argv); + /*** from mlib.c ***/ void setcloexec(int fd, const char* fn); diff --git a/src/help.c b/src/help.c index 78e3b29f..5103ecb8 100644 --- a/src/help.c +++ b/src/help.c @@ -121,26 +121,6 @@ void ensure_package_clientdata(struct pkginfo *pkg) { pkg->clientdata->files = NULL; } -void cu_closepipe(int argc, void **argv) { - int *p1= (int*)argv[0]; - close(p1[0]); close(p1[1]); -} - -void cu_closefile(int argc, void **argv) { - FILE *f= (FILE*)(argv[0]); - fclose(f); -} - -void cu_closedir(int argc, void **argv) { - DIR *d= (DIR*)(argv[0]); - closedir(d); -} - -void cu_closefd(int argc, void **argv) { - int ip= *(int*)argv[0]; - close(ip); -} - int ignore_depends(struct pkginfo *pkg) { struct packageinlist *id; for (id= ignoredependss; id; id= id->next) diff --git a/src/main.h b/src/main.h index 15a8303a..59cc9f85 100644 --- a/src/main.h +++ b/src/main.h @@ -173,11 +173,6 @@ int skip_due_to_hold(struct pkginfo *pkg); /* from help.c */ -void cu_closefile(int argc, void **argv); -void cu_closepipe(int argc, void **argv); -void cu_closedir(int argc, void **argv); -void cu_closefd(int argc, void **argv); - struct stat; int ignore_depends(struct pkginfo *pkg); diff --git a/src/query.c b/src/query.c index 2e524cfb..91b9111e 100644 --- a/src/query.c +++ b/src/query.c @@ -66,21 +66,6 @@ const char *pkgadminfile(struct pkginfo *pkg, const char *whichfile) { return vb.buf; } -void cu_closepipe(int argc, void **argv) { - int *p1= (int*)argv[0]; - close(p1[0]); close(p1[1]); -} - -void cu_closefile(int argc, void **argv) { - FILE *f= (FILE*)(argv[0]); - fclose(f); -} - -void cu_closefd(int argc, void **argv) { - int ip= *(int*)argv; - close(ip); -} - int pkglistqsortcmp(const void *a, const void *b) { const struct pkginfo *pa= *(const struct pkginfo**)a; const struct pkginfo *pb= *(const struct pkginfo**)b;