[newlib-cygwin] Cygwin: move sun_name_t constructors into fhandler_socket_unix.cc
Corinna Vinschen
corinna@sourceware.org
Mon Mar 5 17:09:00 GMT 2018
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=ae67198d55bf5bab903eb01d049f15d7a35c38ba
commit ae67198d55bf5bab903eb01d049f15d7a35c38ba
Author: Corinna Vinschen <corinna@vinschen.de>
Date: Mon Mar 5 18:08:47 2018 +0100
Cygwin: move sun_name_t constructors into fhandler_socket_unix.cc
They are only used there anyway and it allows to use the AF_UNIX
macro without tweaking header files. While at it, improve
both constructors. The default constructor now creates the name
of an unnamed socket, the constructor taking parameters carefully
checks its input.
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diff:
---
winsup/cygwin/fhandler.h | 14 ++------------
winsup/cygwin/fhandler_socket_unix.cc | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 12 deletions(-)
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index e9a2472..da600f2 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -842,18 +842,8 @@ class sun_name_t
/* Allows 108 bytes sun_path plus trailing NUL */
char _nul[sizeof (struct sockaddr_un) + 1];
};
- sun_name_t ()
- {
- un_len = 0;
- un.sun_family = 0;
- _nul[sizeof (struct sockaddr_un)] = '\0';
- }
- sun_name_t (const struct sockaddr *name, __socklen_t namelen)
- {
- un_len = namelen < (__socklen_t) sizeof un ? namelen : sizeof un;
- memcpy (&un, name, un_len);
- _nul[sizeof (struct sockaddr_un)] = '\0';
- }
+ sun_name_t ();
+ sun_name_t (const struct sockaddr *name, __socklen_t namelen);
void *operator new (size_t) __attribute__ ((nothrow))
{ return cmalloc_abort (HEAP_FHANDLER, sizeof (sun_name_t)); }
diff --git a/winsup/cygwin/fhandler_socket_unix.cc b/winsup/cygwin/fhandler_socket_unix.cc
index 36a3cb3..f93b912 100644
--- a/winsup/cygwin/fhandler_socket_unix.cc
+++ b/winsup/cygwin/fhandler_socket_unix.cc
@@ -69,6 +69,23 @@ GUID __cygwin_socket_guid = {
.Data4 = { 0xba, 0xb3, 0xc5, 0xb1, 0xf9, 0x2c, 0xb8, 0x8c }
};
+sun_name_t::sun_name_t ()
+{
+ un_len = sizeof (sa_family_t);
+ un.sun_family = AF_UNIX;
+ _nul[sizeof (struct sockaddr_un)] = '\0';
+}
+
+sun_name_t::sun_name_t (const struct sockaddr *name, socklen_t namelen)
+{
+ if (namelen < 0)
+ namelen = 0;
+ un_len = namelen < (__socklen_t) sizeof un ? namelen : sizeof un;
+ if (name)
+ memcpy (&un, name, un_len);
+ _nul[sizeof (struct sockaddr_un)] = '\0';
+}
+
HANDLE
fhandler_socket_unix::create_abstract_link (const sun_name_t *sun,
PUNICODE_STRING pipe_name)
More information about the Cygwin-cvs
mailing list