mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-06 02:20:34 +08:00
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
This commit is contained in:
parent
e68c7b4306
commit
c84b434f46
@ -1,3 +1,12 @@
|
||||
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>
|
||||
|
||||
* s-stchop-vxworks.adb: Add comment.
|
||||
|
@ -225,13 +225,32 @@ package GNAT.Sockets.Thin_Common is
|
||||
|
||||
function Servent_S_Name
|
||||
(E : Servent_Access) return C.Strings.chars_ptr;
|
||||
|
||||
function Servent_S_Aliases
|
||||
(E : Servent_Access) return Chars_Ptr_Pointers.Pointer;
|
||||
|
||||
function Servent_S_Port
|
||||
(E : Servent_Access) return C.int;
|
||||
|
||||
function Servent_S_Proto
|
||||
(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 --
|
||||
------------------
|
||||
@ -347,4 +366,8 @@ private
|
||||
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_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;
|
||||
|
@ -6,7 +6,7 @@
|
||||
-- --
|
||||
-- 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 --
|
||||
-- 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
|
||||
|
||||
Source_Aliases : Chars_Ptr_Array
|
||||
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_Ptr).
|
||||
|
||||
begin
|
||||
Result := -1;
|
||||
Names_Length := C.Strings.Strlen (Source_Servent.S_Name) + 1
|
||||
+ C.Strings.Strlen (Source_Servent.S_Proto) + 1;
|
||||
Names_Length := C.Strings.Strlen (Servent_S_Name (Source_Servent)) + 1 +
|
||||
C.Strings.Strlen (Servent_S_Proto (Source_Servent)) + 1;
|
||||
|
||||
for J in Source_Aliases'Range loop
|
||||
if Source_Aliases (J) /= C.Strings.Null_Ptr then
|
||||
@ -235,6 +236,8 @@ package body GNAT.Sockets.Thin.Task_Safe_NetDB is
|
||||
Names_Index : size_t := Netdb_Data.Names'First;
|
||||
-- Index of first available location in Netdb_Data.Names
|
||||
|
||||
Stored_Name : C.Strings.chars_ptr;
|
||||
|
||||
begin
|
||||
if Netdb_Data'Size / 8 > Target_Buffer_Length then
|
||||
return;
|
||||
@ -243,26 +246,29 @@ package body GNAT.Sockets.Thin.Task_Safe_NetDB is
|
||||
-- Copy service name
|
||||
|
||||
Store_Name
|
||||
(C.Strings.Value (Source_Servent.S_Name),
|
||||
(C.Strings.Value (Servent_S_Name (Source_Servent)),
|
||||
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)
|
||||
|
||||
Target_Servent.S_Aliases :=
|
||||
Netdb_Data.Aliases_List
|
||||
(Netdb_Data.Aliases_List'First)'Unchecked_Access;
|
||||
Servent_Set_S_Aliases
|
||||
(Target_Servent,
|
||||
Netdb_Data.Aliases_List
|
||||
(Netdb_Data.Aliases_List'First)'Unchecked_Access);
|
||||
|
||||
-- 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
|
||||
|
||||
Store_Name
|
||||
(C.Strings.Value (Source_Servent.S_Proto),
|
||||
(C.Strings.Value (Servent_S_Proto (Source_Servent)),
|
||||
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
|
||||
if J = Netdb_Data.Aliases_List'Last then
|
||||
|
@ -91,6 +91,10 @@ extern char * __gnat_servent_s_name (struct servent *);
|
||||
extern char ** __gnat_servent_s_aliases (struct servent *);
|
||||
extern int __gnat_servent_s_port (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)
|
||||
extern int __gnat_inet_pton (int, const char *, void *);
|
||||
#endif
|
||||
@ -535,6 +539,8 @@ __gnat_inet_pton (int af, const char *src, void *dst) {
|
||||
* };
|
||||
*/
|
||||
|
||||
/* Getters */
|
||||
|
||||
char *
|
||||
__gnat_servent_s_name (struct servent * s)
|
||||
{
|
||||
@ -559,6 +565,31 @@ __gnat_servent_s_proto (struct servent * s)
|
||||
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
|
||||
# warning Sockets are not supported on this platform
|
||||
|
Loading…
x
Reference in New Issue
Block a user