[pacman-dev] [PATCH] create a typedef for enum _alpm_errno_t
Dan McGee
dpmcgee at gmail.com
Mon Nov 14 09:34:17 EST 2011
On Fri, Oct 28, 2011 at 9:03 PM, Jonathan Conder <jonno.conder at gmail.com> wrote:
> This is consistent with the other enums and structs, and should be
> slightly more readable.
>
> Signed-off-by: Jonathan Conder <jonno.conder at gmail.com>
Definitely more readable and consistent. I suppose it makes sense to
change the one inconsistency rather than question whether we should be
doing typedefs at all at this point.
Anyone have objections?
> ---
> README | 2 +-
> lib/libalpm/alpm.c | 4 ++--
> lib/libalpm/alpm.h | 10 +++++-----
> lib/libalpm/error.c | 4 ++--
> lib/libalpm/handle.c | 2 +-
> lib/libalpm/handle.h | 4 ++--
> lib/libalpm/sync.c | 4 ++--
> src/pacman/callback.c | 2 +-
> src/pacman/conf.c | 2 +-
> src/pacman/remove.c | 2 +-
> src/pacman/sync.c | 6 +++---
> src/pacman/util.c | 2 +-
> src/util/cleanupdelta.c | 2 +-
> src/util/pactree.c | 2 +-
> src/util/testdb.c | 2 +-
> src/util/testpkg.c | 2 +-
> 16 files changed, 26 insertions(+), 26 deletions(-)
>
> diff --git a/README b/README
> index 0e5a512..c4199dd 100644
> --- a/README
> +++ b/README
> @@ -389,7 +389,7 @@ API CHANGES BETWEEN 3.5 AND 4.0
> - PM_ prefixes for enum values are now ALPM_
> - pm prefixes for structs and enums are now alpm_
> - alpm_initialize now has parameters: char *root, char *dbpath,
> - _alpm_errno_t *err and returns an alpm_handle_t struct.
> + alpm_errno_t *err and returns an alpm_handle_t struct.
> - alpm_release now takes an alpm_handle_t *.
> - alpm_db_register_sync() now requires a extra parameter of a alpm_siglevel_t.
> - alpm_pkg_load() now requires an extra parameter of an alpm_siglevel_t
> diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
> index 3884334..e957f1a 100644
> --- a/lib/libalpm/alpm.c
> +++ b/lib/libalpm/alpm.c
> @@ -47,9 +47,9 @@
> * @return a context handle on success, NULL on error, err will be set if provided
> */
> alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath,
> - enum _alpm_errno_t *err)
> + alpm_errno_t *err)
> {
> - enum _alpm_errno_t myerr;
> + alpm_errno_t myerr;
> const char *lf = "db.lck";
> size_t lockfilelen;
> alpm_handle_t *myhandle = _alpm_handle_new();
> diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
> index 9fda940..9b2d8a9 100644
> --- a/lib/libalpm/alpm.h
> +++ b/lib/libalpm/alpm.h
> @@ -1115,7 +1115,7 @@ char *alpm_compute_sha256sum(const char *filename);
> /** @addtogroup alpm_api_errors Error Codes
> * @{
> */
> -enum _alpm_errno_t {
> +typedef enum _alpm_errno_t {
> ALPM_ERR_MEMORY = 1,
> ALPM_ERR_SYSTEM,
> ALPM_ERR_BADPERMS,
> @@ -1179,19 +1179,19 @@ enum _alpm_errno_t {
> ALPM_ERR_LIBCURL,
> ALPM_ERR_EXTERNAL_DOWNLOAD,
> ALPM_ERR_GPGME
> -};
> +} alpm_errno_t;
>
> /** Returns the current error code from the handle. */
> -enum _alpm_errno_t alpm_errno(alpm_handle_t *handle);
> +alpm_errno_t alpm_errno(alpm_handle_t *handle);
>
> /** Returns the string corresponding to an error number. */
> -const char *alpm_strerror(enum _alpm_errno_t err);
> +const char *alpm_strerror(alpm_errno_t err);
>
> /* End of alpm_api_errors */
> /** @} */
>
> alpm_handle_t *alpm_initialize(const char *root, const char *dbpath,
> - enum _alpm_errno_t *err);
> + alpm_errno_t *err);
> int alpm_release(alpm_handle_t *handle);
>
> enum alpm_caps {
> diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
> index b3f5681..044dec7 100644
> --- a/lib/libalpm/error.c
> +++ b/lib/libalpm/error.c
> @@ -29,12 +29,12 @@
> #include "alpm.h"
> #include "handle.h"
>
> -enum _alpm_errno_t SYMEXPORT alpm_errno(alpm_handle_t *handle)
> +alpm_errno_t SYMEXPORT alpm_errno(alpm_handle_t *handle)
> {
> return handle->pm_errno;
> }
>
> -const char SYMEXPORT *alpm_strerror(enum _alpm_errno_t err)
> +const char SYMEXPORT *alpm_strerror(alpm_errno_t err)
> {
> switch(err) {
> /* System */
> diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
> index 7402be5..01f5955 100644
> --- a/lib/libalpm/handle.c
> +++ b/lib/libalpm/handle.c
> @@ -339,7 +339,7 @@ static char *canonicalize_path(const char *path) {
> return new_path;
> }
>
> -enum _alpm_errno_t _alpm_set_directory_option(const char *value,
> +alpm_errno_t _alpm_set_directory_option(const char *value,
> char **storage, int must_exist)
> {
> struct stat st;
> diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
> index 8477dca..d568fb4 100644
> --- a/lib/libalpm/handle.h
> +++ b/lib/libalpm/handle.h
> @@ -93,7 +93,7 @@ struct __alpm_handle_t {
> alpm_siglevel_t siglevel; /* Default signature verification level */
>
> /* error code */
> - enum _alpm_errno_t pm_errno;
> + alpm_errno_t pm_errno;
> };
>
> alpm_handle_t *_alpm_handle_new(void);
> @@ -102,7 +102,7 @@ void _alpm_handle_free(alpm_handle_t *handle);
> int _alpm_handle_lock(alpm_handle_t *handle);
> int _alpm_handle_unlock(alpm_handle_t *handle);
>
> -enum _alpm_errno_t _alpm_set_directory_option(const char *value,
> +alpm_errno_t _alpm_set_directory_option(const char *value,
> char **storage, int must_exist);
>
> #endif /* _ALPM_HANDLE_H */
> diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
> index 52049a8..3de5c07 100644
> --- a/lib/libalpm/sync.c
> +++ b/lib/libalpm/sync.c
> @@ -748,7 +748,7 @@ static int apply_deltas(alpm_handle_t *handle)
> * @return 1 if file was removed, 0 otherwise
> */
> static int prompt_to_delete(alpm_handle_t *handle, const char *filepath,
> - enum _alpm_errno_t reason)
> + alpm_errno_t reason)
> {
> int doremove = 0;
> QUESTION(handle, ALPM_QUESTION_CORRUPTED_PKG, (char *)filepath,
> @@ -965,7 +965,7 @@ static int check_validity(alpm_handle_t *handle,
> char *path;
> alpm_siglist_t *siglist;
> alpm_siglevel_t level;
> - enum _alpm_errno_t error;
> + alpm_errno_t error;
> };
> size_t current = 0, current_bytes = 0;
> alpm_list_t *i, *errors = NULL;
> diff --git a/src/pacman/callback.c b/src/pacman/callback.c
> index 6f39013..3fb5465 100644
> --- a/src/pacman/callback.c
> +++ b/src/pacman/callback.c
> @@ -341,7 +341,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2,
> *response = yesno(_(":: File %s is corrupted (%s).\n"
> "Do you want to delete it?"),
> (char *)data1,
> - alpm_strerror(*(enum _alpm_errno_t *)data2));
> + alpm_strerror(*(alpm_errno_t *)data2));
> break;
> case ALPM_QUESTION_IMPORT_KEY:
> {
> diff --git a/src/pacman/conf.c b/src/pacman/conf.c
> index 2d3009e..004922e 100644
> --- a/src/pacman/conf.c
> +++ b/src/pacman/conf.c
> @@ -522,7 +522,7 @@ static int _add_mirror(alpm_db_t *db, char *value)
> static int setup_libalpm(void)
> {
> int ret = 0;
> - enum _alpm_errno_t err;
> + alpm_errno_t err;
> alpm_handle_t *handle;
>
> pm_printf(ALPM_LOG_DEBUG, "setup_libalpm called\n");
> diff --git a/src/pacman/remove.c b/src/pacman/remove.c
> index e63b5c4..425ce45 100644
> --- a/src/pacman/remove.c
> +++ b/src/pacman/remove.c
> @@ -104,7 +104,7 @@ int pacman_remove(alpm_list_t *targets)
>
> /* Step 2: prepare the transaction based on its type, targets and flags */
> if(alpm_trans_prepare(config->handle, &data) == -1) {
> - enum _alpm_errno_t err = alpm_errno(config->handle);
> + alpm_errno_t err = alpm_errno(config->handle);
> pm_printf(ALPM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
> alpm_strerror(err));
> switch(err) {
> diff --git a/src/pacman/sync.c b/src/pacman/sync.c
> index cc70203..1003a42 100644
> --- a/src/pacman/sync.c
> +++ b/src/pacman/sync.c
> @@ -600,7 +600,7 @@ static int process_pkg(alpm_pkg_t *pkg)
> int ret = alpm_add_pkg(config->handle, pkg);
>
> if(ret == -1) {
> - enum _alpm_errno_t err = alpm_errno(config->handle);
> + alpm_errno_t err = alpm_errno(config->handle);
> if(err == ALPM_ERR_TRANS_DUP_TARGET
> || err == ALPM_ERR_PKG_IGNORED) {
> /* just skip duplicate or ignored targets */
> @@ -766,7 +766,7 @@ int sync_prepare_execute(void)
>
> /* Step 2: "compute" the transaction based on targets and flags */
> if(alpm_trans_prepare(config->handle, &data) == -1) {
> - enum _alpm_errno_t err = alpm_errno(config->handle);
> + alpm_errno_t err = alpm_errno(config->handle);
> pm_printf(ALPM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
> alpm_strerror(err));
> switch(err) {
> @@ -835,7 +835,7 @@ int sync_prepare_execute(void)
> }
>
> if(alpm_trans_commit(config->handle, &data) == -1) {
> - enum _alpm_errno_t err = alpm_errno(config->handle);
> + alpm_errno_t err = alpm_errno(config->handle);
> pm_printf(ALPM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
> alpm_strerror(err));
> switch(err) {
> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 42f17ea..c0dcb9f 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -65,7 +65,7 @@ int trans_init(alpm_transflag_t flags, int check_valid)
>
> void trans_init_error(void)
> {
> - enum _alpm_errno_t err = alpm_errno(config->handle);
> + alpm_errno_t err = alpm_errno(config->handle);
> pm_printf(ALPM_LOG_ERROR, _("failed to init transaction (%s)\n"),
> alpm_strerror(err));
> if(err == ALPM_ERR_HANDLE_LOCK) {
> diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
> index 7964609..d6bd0e8 100644
> --- a/src/util/cleanupdelta.c
> +++ b/src/util/cleanupdelta.c
> @@ -94,7 +94,7 @@ static void usage(void) {
> int main(int argc, char *argv[])
> {
> const char *dbpath = DBPATH;
> - enum _alpm_errno_t err;
> + alpm_errno_t err;
> int a = 1;
> alpm_list_t *dbnames = NULL;
>
> diff --git a/src/util/pactree.c b/src/util/pactree.c
> index bb15b1b..f95c5e8 100644
> --- a/src/util/pactree.c
> +++ b/src/util/pactree.c
> @@ -443,7 +443,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, int depth)
> int main(int argc, char *argv[])
> {
> int freelist = 0, ret = 0;
> - enum _alpm_errno_t err;
> + alpm_errno_t err;
> const char *target_name;
> alpm_pkg_t *pkg;
> alpm_list_t *dblist = NULL;
> diff --git a/src/util/testdb.c b/src/util/testdb.c
> index 783d499..b15bbe5 100644
> --- a/src/util/testdb.c
> +++ b/src/util/testdb.c
> @@ -185,7 +185,7 @@ static void usage(void)
> int main(int argc, char *argv[])
> {
> int ret = 0;
> - enum _alpm_errno_t err;
> + alpm_errno_t err;
> const char *dbpath = DBPATH;
> int a = 1;
> alpm_list_t *dbnames = NULL;
> diff --git a/src/util/testpkg.c b/src/util/testpkg.c
> index 90758e1..6385e41 100644
> --- a/src/util/testpkg.c
> +++ b/src/util/testpkg.c
> @@ -41,7 +41,7 @@ int main(int argc, char *argv[])
> {
> int retval = 1; /* default = false */
> alpm_handle_t *handle;
> - enum _alpm_errno_t err;
> + alpm_errno_t err;
> alpm_pkg_t *pkg = NULL;
> const alpm_siglevel_t level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL;
>
> --
> 1.7.7
>
>
>
More information about the pacman-dev
mailing list