4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-28 03:27:46 +08:00

Cygwin: AF_UNIX: convert AF_UNIX_PKT helpers to inline functions

Add AF_UNIX_PKT_DATA_END and AF_UNIX_PKT_DATA_APPEND
This commit is contained in:
Corinna Vinschen 2019-02-09 19:55:17 +01:00 committed by Ken Brown
parent 973af68fff
commit 0eaa7b8144

View File

@ -106,31 +106,63 @@ class af_unix_pkt_hdr_t
}
};
#define AF_UNIX_PKT_OFFSETOF_NAME(phdr) \
(sizeof (af_unix_pkt_hdr_t))
#define AF_UNIX_PKT_OFFSETOF_CMSG(phdr) \
(sizeof (af_unix_pkt_hdr_t) + (phdr)->name_len)
#define AF_UNIX_PKT_OFFSETOF_DATA(phdr) \
({ \
af_unix_pkt_hdr_t *_p = phdr; \
sizeof (af_unix_pkt_hdr_t) + (_p)->name_len + (_p)->cmsg_len; \
})
#define AF_UNIX_PKT_NAME(phdr) \
({ \
af_unix_pkt_hdr_t *_p = phdr; \
(struct sockaddr_un *)(((PBYTE)(_p)) \
+ AF_UNIX_PKT_OFFSETOF_NAME (_p)); \
})
#define AF_UNIX_PKT_CMSG(phdr) \
({ \
af_unix_pkt_hdr_t *_p = phdr; \
(struct cmsghdr *)(((PBYTE)(_p)) + AF_UNIX_PKT_OFFSETOF_CMSG (_p)); \
})
#define AF_UNIX_PKT_DATA(phdr) \
({ \
af_unix_pkt_hdr_t _p = phdr; \
(void *)(((PBYTE)(_p)) + AF_UNIX_PKT_OFFSETOF_DATA (_p)); \
})
#define MAX_AF_UN_PKT_LEN UINT16_MAX
static inline ptrdiff_t
AF_UNIX_PKT_OFFSETOF_NAME (af_unix_pkt_hdr_t *phdr)
{
return sizeof (af_unix_pkt_hdr_t);
}
static inline ptrdiff_t
AF_UNIX_PKT_OFFSETOF_CMSG (af_unix_pkt_hdr_t *phdr)
{
return AF_UNIX_PKT_OFFSETOF_NAME (phdr) + phdr->name_len;
}
static inline ptrdiff_t
AF_UNIX_PKT_OFFSETOF_DATA (af_unix_pkt_hdr_t *phdr)
{
return AF_UNIX_PKT_OFFSETOF_CMSG (phdr) + phdr->cmsg_len;
}
static inline struct sockaddr_un *
AF_UNIX_PKT_NAME (af_unix_pkt_hdr_t *phdr)
{
return (struct sockaddr_un *)
((PBYTE)(phdr) + AF_UNIX_PKT_OFFSETOF_NAME (phdr));
}
static inline struct cmsghdr *
AF_UNIX_PKT_CMSG (af_unix_pkt_hdr_t *phdr)
{
return (struct cmsghdr *)
((PBYTE)(phdr) + AF_UNIX_PKT_OFFSETOF_CMSG (phdr));
}
static inline void *
AF_UNIX_PKT_DATA (af_unix_pkt_hdr_t *phdr)
{
return (void *) ((PBYTE)(phdr) + AF_UNIX_PKT_OFFSETOF_DATA (phdr));
}
static inline void *
AF_UNIX_PKT_DATA_END (af_unix_pkt_hdr_t *phdr)
{
return (void *) ((PBYTE)(phdr) + AF_UNIX_PKT_OFFSETOF_DATA (phdr)
+ (phdr)->data_len);
}
inline bool
AF_UNIX_PKT_DATA_APPEND (af_unix_pkt_hdr_t *phdr, void *data, uint16_t dlen)
{
if ((uint32_t) phdr->pckt_len + (uint32_t) dlen > MAX_AF_UN_PKT_LEN)
return false;
memcpy (AF_UNIX_PKT_DATA_END (phdr), data, dlen);
phdr->pckt_len += dlen;
phdr->data_len += dlen;
return true;
}
/* Some error conditions on pipes have multiple status codes, unfortunately. */
#define STATUS_PIPE_NO_INSTANCE_AVAILABLE(status) \
@ -139,9 +171,10 @@ class af_unix_pkt_hdr_t
|| _s == STATUS_PIPE_NOT_AVAILABLE \
|| _s == STATUS_PIPE_BUSY; })
#define STATUS_PIPE_IS_CLOSING(status) \
#define STATUS_PIPE_IS_CLOSED(status) \
({ NTSTATUS _s = (status); \
_s == STATUS_PIPE_CLOSING \
|| _s == STATUS_PIPE_BROKEN \
|| _s == STATUS_PIPE_EMPTY; })
#define STATUS_PIPE_INVALID(status) \