]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Re-allow direct use of nlist.n_name in <nlist.h>
authorJames Clarke <jrtc27@jrtc27.com>
Sun, 3 Feb 2019 00:11:15 +0000 (00:11 +0000)
committerGuillem Jover <guillem@hadrons.org>
Thu, 8 Aug 2019 01:47:04 +0000 (03:47 +0200)
Commit e8d340de ("Remove a.out support from nlist()") introduced a copy
of the definition of nlist from a.out.h. However, as well as having
n_name inside n_un, on the various BSDs n_name could also be accessed
as a direct member of nlist, and this is made use of by FreeBSD's
usr.bin/netstat/main.c. Thus we should also add the same enclosing
anonymous union.

[guillem@hadrons.org:
 - Add a minimal unit test. ]

Closes: !4
Signed-off-by: Guillem Jover <guillem@hadrons.org>
include/bsd/nlist.h
test/nlist.c

index 8767117c6b457df319c23528bbc0f27157b62ebe..89877ace56acc917420365ca7aacd57a6a3bbce2 100644 (file)
 struct nlist {
        union {
                char *n_name;
-               struct n_list *n_next;
-               long n_strx;
-       } n_un;
+               union {
+                       char *n_name;
+                       struct n_list *n_next;
+                       long n_strx;
+               } n_un;
+       };
        unsigned char n_type;
        char n_other;
        short n_desc;
index c76d9e73f069990c1336ba1928cfb1df69a4adbf..82e24e97f05bf7827c8e8cc8981cace2e9190b7e 100644 (file)
@@ -66,6 +66,8 @@ main(int argc, char **argv)
 
        assert(*data_pub_ptr == 50);
 
+       assert(nl[0].n_name == nl[0].n_un.n_name);
+
        rc = nlist(argv[0], nl);
        assert(rc == 0);