Using sys/types.h types in sys/socket.h

Peter Wemm peter at wemm.org
Wed Jan 8 00:46:36 UTC 2014


On Wed, Dec 18, 2013 at 9:20 PM, Bruce Evans <brde at optusnet.com.au> wrote:
> On Wed, 18 Dec 2013, Adrian Chadd wrote:
>
>> Ok, how about this:
>>
>> Index: sys/sys/socket.h
>> ===================================================================
>> --- sys/sys/socket.h    (revision 259475)
>> +++ sys/sys/socket.h    (working copy)
>> @@ -84,6 +84,16 @@
>> #endif
>> #endif
>>
>> +#ifndef _UINT32_T_DECLARED
>> +#define        _UINT32_T_DECLARED
>> +typedef __uint32_t     uint32_t;
>> +#endif
>> +
>> +#ifndef _UINTPTR_T_DECLARED
>> +#define _UINTPTR_T_DECLARED
>> +typedef __uintptr_t    uintptr_t;
>> +#endif
>> +
>> /*
>>  * Types
>>  */
>
>
> This seems to be correct, except the tab after the second #define is
> corrupt.  Actually, all the tabs are corrupt, but the first #define
> apparently started with a tab whose corruption made a larger mess.
>
> imp@ said, in a message that should have been killfiled due to top posting,
> that this should be under __BSD_VISIBLE.  That isn't strictly necessary,
> since POSIX allows names ending with _t, and it isn't very important for
> avoiding pollution since there aren't very many of them.
>
>
>> @@ -577,11 +587,27 @@
>> };
>>
>> /*
>> + * sendfile(2) kqueue information
>> + */
>> +struct sf_hdtr_kq {
>> +       int kq_fd;              /* kq fd to post completion events on */
>> +       int kq_fd;              /* kq fd to post completion events on */
>> +       uint32_t kq_flags;      /* extra flags to pass in */
>> +       void *kq_udata;         /* user data pointer */
>> +       uintptr_t kq_ident;     /* ident (from userland?) */
>> +};

Why can't he leave out the #ifdef/#define/typedefs and just declare it like:
  int kq_fd;
  __uint32_t kq_flags;
  void *kq_udata;
  __uintptr_t kq_ident;?

I know it doesn't look pretty, but surely that's less painful overall than the
#ifndef _UINTPTR_T_DECLARED
#define _UINTPTR_T_DECLARED
typedef __uintptr_t    uintptr_t;
#endif
thing..  We seem to do that elsewhere, eg:
struct stat {
        __dev_t   st_dev;               /* inode's device */
        ino_t     st_ino;               /* inode's number */
...
        fflags_t  st_flags;             /* user defined flags for file */
        __uint32_t st_gen;              /* file generation number */
        __int32_t st_lspare;
...

What's the correct threshold for using the _DECLARED guards vs using
the __ prefixed versions?

-- 
Peter Wemm - peter at wemm.org; peter at FreeBSD.org; peter at yahoo-inc.com; KI6FJV


More information about the freebsd-arch mailing list