Make sys/user.h safe for multiple includes

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Make sys/user.h safe for multiple includes

Christian Ludwig
Hi,

I was playing around in the arch code of OpenBSD/i386 lately, and again
and again found that sys/user.h was not safe against multiple inclusions
from the same source file. Is that for a reason? One of my header files
needs to include sys/user.h, which creates a huge mess.

The following patch might fix this, although I think I might be on the
wrong track here.

--- a/sys/sys/user.h
+++ b/sys/sys/user.h
@@ -32,6 +32,9 @@
  *     @(#)user.h      8.2 (Berkeley) 9/23/93
  */
 
+#ifndef _SYS_USER_H_
+#define _SYS_USER_H_
+
 #include <machine/pcb.h>
 #ifndef _KERNEL
 /* stuff that *used* to be included by user.h, or is now needed */
@@ -58,3 +61,5 @@ struct        user {
 
        struct  pstats u_stats;         /* p_stats points here (use it!) */
 };
+
+#endif /* _SYS_USER_H_ */

Regards.


  - Christian

--
God is real... unless declared an integer.

Reply | Threaded
Open this post in threaded view
|

Re: Make sys/user.h safe for multiple includes

Philip Guenther-2
On Mon, Dec 20, 2010 at 4:06 PM, Christian Ludwig
<[hidden email]> wrote:
> I was playing around in the arch code of OpenBSD/i386 lately, and again
> and again found that sys/user.h was not safe against multiple inclusions
> from the same source file. Is that for a reason? One of my header files
> needs to include sys/user.h, which creates a huge mess.

You have a header that needs the full struct user definition and can't
make do with a forward declaration of it?

(Note that the struct user definition is the _only_ correct reason to
#include <sys/user.h>)

This has been handled so far by simply including sys/user.h in each
file that needs the header.  For example, machine/freebsd_machdep.h
would seem to need the struct user definition for its offsetof usage,
but instead the one .c file that uses that header pulls it in.


Philip Guenther