mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-08-02 07:23:41 +02:00
gio: use reentrant getservbyname_r() if available
This commit is contained in:
committed by
Philip Withnall
parent
8aa889dbf1
commit
f738c7f3db
@@ -23,6 +23,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "gnetworking.h"
|
||||
#include "gnetworkingprivate.h"
|
||||
|
||||
/**
|
||||
* SECTION:gnetworking
|
||||
@@ -76,3 +77,26 @@ g_networking_init (void)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
gboolean
|
||||
g_getservbyname_ntohs (const char *name, const char *proto, guint16 *out_port)
|
||||
{
|
||||
struct servent *result;
|
||||
|
||||
#ifdef HAVE_GETSERVBYNAME_R
|
||||
struct servent result_buf;
|
||||
char buf[2048];
|
||||
int r;
|
||||
|
||||
r = getservbyname_r (name, proto, &result_buf, buf, sizeof (buf), &result);
|
||||
if (r != 0 || result != &result_buf)
|
||||
result = NULL;
|
||||
#else
|
||||
result = getservbyname (name, proto);
|
||||
#endif
|
||||
|
||||
if (!result)
|
||||
return FALSE;
|
||||
*out_port = g_ntohs (result->s_port);
|
||||
return TRUE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user