Commit c84b434f by Bob Duff Committed by Arnaud Charlet

socket.c: Add more accessor functions for struct servent (need setters as well as getters).

2009-11-30  Bob Duff  <duff@adacore.com>

	* socket.c: Add more accessor functions for struct servent (need
	setters as well as getters).
	* g-sothco.ads (Servent): Declare interfaces to C setter functions for
	struct servent.
	* g-sttsne-locking.adb (Copy_Service_Entry): Use setter functions for
	struct servent.

From-SVN: r154777
parent e68c7b43
2009-11-30 Bob Duff <duff@adacore.com>
* socket.c: Add more accessor functions for struct servent (need
setters as well as getters).
* g-sothco.ads (Servent): Declare interfaces to C setter functions for
struct servent.
* g-sttsne-locking.adb (Copy_Service_Entry): Use setter functions for
struct servent.
2009-11-30 Robert Dewar <dewar@adacore.com> 2009-11-30 Robert Dewar <dewar@adacore.com>
* s-stchop-vxworks.adb: Add comment. * s-stchop-vxworks.adb: Add comment.
......
...@@ -225,13 +225,32 @@ package GNAT.Sockets.Thin_Common is ...@@ -225,13 +225,32 @@ package GNAT.Sockets.Thin_Common is
function Servent_S_Name function Servent_S_Name
(E : Servent_Access) return C.Strings.chars_ptr; (E : Servent_Access) return C.Strings.chars_ptr;
function Servent_S_Aliases function Servent_S_Aliases
(E : Servent_Access) return Chars_Ptr_Pointers.Pointer; (E : Servent_Access) return Chars_Ptr_Pointers.Pointer;
function Servent_S_Port function Servent_S_Port
(E : Servent_Access) return C.int; (E : Servent_Access) return C.int;
function Servent_S_Proto function Servent_S_Proto
(E : Servent_Access) return C.Strings.chars_ptr; (E : Servent_Access) return C.Strings.chars_ptr;
procedure Servent_Set_S_Name
(E : Servent_Access;
S_Name : C.Strings.chars_ptr);
procedure Servent_Set_S_Aliases
(E : Servent_Access;
S_Aliases : Chars_Ptr_Pointers.Pointer);
procedure Servent_Set_S_Port
(E : Servent_Access;
S_Port : C.int);
procedure Servent_Set_S_Proto
(E : Servent_Access;
S_Proto : C.Strings.chars_ptr);
------------------ ------------------
-- Host entries -- -- Host entries --
------------------ ------------------
...@@ -347,4 +366,8 @@ private ...@@ -347,4 +366,8 @@ private
pragma Import (C, Servent_S_Aliases, "__gnat_servent_s_aliases"); pragma Import (C, Servent_S_Aliases, "__gnat_servent_s_aliases");
pragma Import (C, Servent_S_Port, "__gnat_servent_s_port"); pragma Import (C, Servent_S_Port, "__gnat_servent_s_port");
pragma Import (C, Servent_S_Proto, "__gnat_servent_s_proto"); pragma Import (C, Servent_S_Proto, "__gnat_servent_s_proto");
pragma Import (C, Servent_Set_S_Name, "__gnat_servent_set_s_name");
pragma Import (C, Servent_Set_S_Aliases, "__gnat_servent_set_s_aliases");
pragma Import (C, Servent_Set_S_Port, "__gnat_servent_set_s_port");
pragma Import (C, Servent_Set_S_Proto, "__gnat_servent_set_s_proto");
end GNAT.Sockets.Thin_Common; end GNAT.Sockets.Thin_Common;
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2007, AdaCore -- -- Copyright (C) 2007-2009, AdaCore --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -206,14 +206,15 @@ package body GNAT.Sockets.Thin.Task_Safe_NetDB is ...@@ -206,14 +206,15 @@ package body GNAT.Sockets.Thin.Task_Safe_NetDB is
Source_Aliases : Chars_Ptr_Array Source_Aliases : Chars_Ptr_Array
renames Chars_Ptr_Pointers.Value renames Chars_Ptr_Pointers.Value
(Source_Servent.S_Aliases, Terminator => C.Strings.Null_Ptr); (Servent_S_Aliases (Source_Servent),
Terminator => C.Strings.Null_Ptr);
-- Null-terminated list of aliases (last element of this array is -- Null-terminated list of aliases (last element of this array is
-- Null_Ptr). -- Null_Ptr).
begin begin
Result := -1; Result := -1;
Names_Length := C.Strings.Strlen (Source_Servent.S_Name) + 1 Names_Length := C.Strings.Strlen (Servent_S_Name (Source_Servent)) + 1 +
+ C.Strings.Strlen (Source_Servent.S_Proto) + 1; C.Strings.Strlen (Servent_S_Proto (Source_Servent)) + 1;
for J in Source_Aliases'Range loop for J in Source_Aliases'Range loop
if Source_Aliases (J) /= C.Strings.Null_Ptr then if Source_Aliases (J) /= C.Strings.Null_Ptr then
...@@ -235,6 +236,8 @@ package body GNAT.Sockets.Thin.Task_Safe_NetDB is ...@@ -235,6 +236,8 @@ package body GNAT.Sockets.Thin.Task_Safe_NetDB is
Names_Index : size_t := Netdb_Data.Names'First; Names_Index : size_t := Netdb_Data.Names'First;
-- Index of first available location in Netdb_Data.Names -- Index of first available location in Netdb_Data.Names
Stored_Name : C.Strings.chars_ptr;
begin begin
if Netdb_Data'Size / 8 > Target_Buffer_Length then if Netdb_Data'Size / 8 > Target_Buffer_Length then
return; return;
...@@ -243,26 +246,29 @@ package body GNAT.Sockets.Thin.Task_Safe_NetDB is ...@@ -243,26 +246,29 @@ package body GNAT.Sockets.Thin.Task_Safe_NetDB is
-- Copy service name -- Copy service name
Store_Name Store_Name
(C.Strings.Value (Source_Servent.S_Name), (C.Strings.Value (Servent_S_Name (Source_Servent)),
Netdb_Data.Names, Names_Index, Netdb_Data.Names, Names_Index,
Target_Servent.S_Name); Stored_Name);
Servent_Set_S_Name (Target_Servent, Stored_Name);
-- Copy aliases (null-terminated string pointer array) -- Copy aliases (null-terminated string pointer array)
Target_Servent.S_Aliases := Servent_Set_S_Aliases
Netdb_Data.Aliases_List (Target_Servent,
(Netdb_Data.Aliases_List'First)'Unchecked_Access; Netdb_Data.Aliases_List
(Netdb_Data.Aliases_List'First)'Unchecked_Access);
-- Copy port number -- Copy port number
Target_Servent.S_Port := Source_Servent.S_Port; Servent_Set_S_Port (Target_Servent, Servent_S_Port (Source_Servent));
-- Copy protocol name -- Copy protocol name
Store_Name Store_Name
(C.Strings.Value (Source_Servent.S_Proto), (C.Strings.Value (Servent_S_Proto (Source_Servent)),
Netdb_Data.Names, Names_Index, Netdb_Data.Names, Names_Index,
Target_Servent.S_Proto); Stored_Name);
Servent_Set_S_Proto (Target_Servent, Stored_Name);
for J in Netdb_Data.Aliases_List'Range loop for J in Netdb_Data.Aliases_List'Range loop
if J = Netdb_Data.Aliases_List'Last then if J = Netdb_Data.Aliases_List'Last then
......
...@@ -91,6 +91,10 @@ extern char * __gnat_servent_s_name (struct servent *); ...@@ -91,6 +91,10 @@ extern char * __gnat_servent_s_name (struct servent *);
extern char ** __gnat_servent_s_aliases (struct servent *); extern char ** __gnat_servent_s_aliases (struct servent *);
extern int __gnat_servent_s_port (struct servent *); extern int __gnat_servent_s_port (struct servent *);
extern char * __gnat_servent_s_proto (struct servent *); extern char * __gnat_servent_s_proto (struct servent *);
extern void __gnat_servent_set_s_name (struct servent *, char *);
extern void __gnat_servent_set_s_aliases (struct servent *, char **);
extern void __gnat_servent_set_s_port (struct servent *, int);
extern void __gnat_servent_set_s_proto (struct servent *, char *);
#if defined (__vxworks) || defined (_WIN32) #if defined (__vxworks) || defined (_WIN32)
extern int __gnat_inet_pton (int, const char *, void *); extern int __gnat_inet_pton (int, const char *, void *);
#endif #endif
...@@ -535,6 +539,8 @@ __gnat_inet_pton (int af, const char *src, void *dst) { ...@@ -535,6 +539,8 @@ __gnat_inet_pton (int af, const char *src, void *dst) {
* }; * };
*/ */
/* Getters */
char * char *
__gnat_servent_s_name (struct servent * s) __gnat_servent_s_name (struct servent * s)
{ {
...@@ -559,6 +565,31 @@ __gnat_servent_s_proto (struct servent * s) ...@@ -559,6 +565,31 @@ __gnat_servent_s_proto (struct servent * s)
return s->s_proto; return s->s_proto;
} }
/* Setters */
void
__gnat_servent_set_s_name (struct servent * s, char * s_name)
{
s->s_name = s_name;
}
void
__gnat_servent_set_s_aliases (struct servent * s, char ** s_aliases)
{
s->s_aliases = s_aliases;
}
void
__gnat_servent_set_s_port (struct servent * s, int s_port)
{
s->s_port = s_port;
}
void
__gnat_servent_set_s_proto (struct servent * s, char * s_proto)
{
s->s_proto = s_proto;
}
#else #else
# warning Sockets are not supported on this platform # warning Sockets are not supported on this platform
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment