Mercurial > hg > octave-lojdl > gnulib-hg
changeset 7785:3246679850d5
Slight readability improvement: use an assert-like macro
in place of literal "abort ()" uses.
* lib/fts.c (fts_assert): Define.
(fts_set_stat_required, cwd_advance_fd, fts_read, fd_ring_check):
Use this macro instead of a bare 'abort'.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Mon, 08 Jan 2007 10:30:47 +0000 |
parents | 97a9a64ee63c |
children | f79f76e0b6f7 |
files | ChangeLog lib/fts.c |
diffstat | 2 files changed, 26 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-01-08 Jim Meyering <jim@meyering.net> + + Slight readability improvement: use an assert-like macro + in place of literal "abort ()" uses. + * lib/fts.c (fts_assert): Define. + (fts_set_stat_required, cwd_advance_fd, fts_read, fd_ring_check): + Use this macro instead of a bare 'abort'. + 2007-01-05 Paul Eggert <eggert@cs.ucla.edu> Don't worry about using IRIX 5.3's wctype.h broken definitions;
--- a/lib/fts.c +++ b/lib/fts.c @@ -1,6 +1,6 @@ /* Traverse a file hierarchy. - Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -138,6 +138,18 @@ # define HAVE_OPENAT_SUPPORT 0 #endif +#ifdef NDEBUG +# define fts_assert(expr) ((void) 0) +#else +# define fts_assert(expr) \ + do \ + { \ + if (!(expr)) \ + abort (); \ + } \ + while (false) +#endif + static FTSENT *fts_alloc (FTS *, const char *, size_t) internal_function; static FTSENT *fts_build (FTS *, int) internal_function; static void fts_lfree (FTSENT *) internal_function; @@ -236,8 +248,7 @@ static void fts_set_stat_required (FTSENT *p, bool required) { - if (p->fts_info != FTS_NSOK) - abort (); + fts_assert (p->fts_info == FTS_NSOK); p->fts_statp->st_size = (required ? FTS_STAT_REQUIRED : FTS_NO_STAT_REQUIRED); @@ -274,8 +285,7 @@ cwd_advance_fd (FTS *sp, int fd, bool chdir_down_one) { int old = sp->fts_cwd_fd; - if (old == fd && old != AT_FDCWD) - abort (); + fts_assert (old != fd || old == AT_FDCWD); if (chdir_down_one) { @@ -739,7 +749,7 @@ case FTS_NO_STAT_REQUIRED: break; default: - abort (); + fts_assert (0); } } @@ -775,8 +785,7 @@ return (sp->fts_cur = NULL); } - if (p->fts_info == FTS_NSOK) - abort (); + fts_assert (p->fts_info != FTS_NSOK); /* NUL terminate the file name. */ sp->fts_path[p->fts_pathlen] = '\0'; @@ -1345,7 +1354,7 @@ error (0, errno, "parent: %s", c2); free (cwd); free (c2); - abort (); + fts_assert (0); } close (cwd_fd); cwd_fd = parent_fd;