diff options
author | Alan Modra <amodra@gmail.com> | 2021-11-14 18:07:50 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2021-11-14 18:07:50 +1030 |
commit | b431e7a3fe8bcd47e38e5b5a6720272861449ed5 (patch) | |
tree | f8259b49a397158eb38cc46b79c4d262d2a0fa05 /libbacktrace/btest.c | |
parent | 9d6a1a6496016c07afa8ce3f4b55f4acf64d4b25 (diff) | |
download | gdb-b431e7a3fe8bcd47e38e5b5a6720272861449ed5.zip gdb-b431e7a3fe8bcd47e38e5b5a6720272861449ed5.tar.gz gdb-b431e7a3fe8bcd47e38e5b5a6720272861449ed5.tar.bz2 |
sync libbacktrace from gcc
Diffstat (limited to 'libbacktrace/btest.c')
-rw-r--r-- | libbacktrace/btest.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/libbacktrace/btest.c b/libbacktrace/btest.c index 9f9c03b..7ef6d32 100644 --- a/libbacktrace/btest.c +++ b/libbacktrace/btest.c @@ -38,6 +38,7 @@ POSSIBILITY OF SUCH DAMAGE. */ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <sys/stat.h> #include "filenames.h" @@ -458,16 +459,29 @@ test5 (void) return failures; } +#define MIN_DESCRIPTOR 3 +#define MAX_DESCRIPTOR 10 + +static int fstat_status[MAX_DESCRIPTOR]; + +/* Check files that are available. */ + +static void +check_available_files (void) +{ + struct stat s; + for (unsigned i = MIN_DESCRIPTOR; i < MAX_DESCRIPTOR; i++) + fstat_status[i] = fstat (i, &s); +} + /* Check that are no files left open. */ static void check_open_files (void) { - int i; - - for (i = 3; i < 10; i++) + for (unsigned i = MIN_DESCRIPTOR; i < MAX_DESCRIPTOR; i++) { - if (close (i) == 0) + if (fstat_status[i] != 0 && close (i) == 0) { fprintf (stderr, "ERROR: descriptor %d still open after tests complete\n", @@ -482,6 +496,8 @@ check_open_files (void) int main (int argc ATTRIBUTE_UNUSED, char **argv) { + check_available_files (); + state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS, error_callback_create, NULL); |