2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
6 #include <aros/debug.h>
7 #include <proto/exec.h>
13 #include "netdb_util.h"
15 char *CopyString(char *src
, APTR pool
)
18 ULONG l
= strlen(src
) + 1;
20 dst
= AllocVecPooled(pool
, l
);
27 static char **CopyStringArray(char **src
, APTR pool
)
34 D(bug("[CopyStringArray] Counted element: %s\n", src
[l
]));
37 D(bug("[CopyStringArray] %u elements total\n", l
));
39 dst
= AllocVecPooled(pool
, (l
+ 1) * sizeof(char *));
44 for (i
= 0; i
< l
; i
++)
46 dst
[i
] = CopyString(src
[i
], pool
);
47 D(bug("[CopyStringArray] Copied element: %s\n", dst
[i
]));
52 /* NULL-terminate the array */
53 D(bug("[CopyStringArray] Terminator element: %u\n", i
));
60 static void FreeStringArray(char **src
, APTR pool
)
64 for (i
= 0; src
[i
]; i
++)
65 FreeVecPooled(pool
, src
[i
]);
70 struct protoent
*CopyProtoEntry(struct PROTOENT
*wsentry
, APTR pool
)
72 struct protoent
*entry
= AllocPooled(pool
, sizeof(struct protoent
));
74 D(bug("[CopyProtoEntry] Allocated AROS protoent 0x%p\n", entry
));
77 D(bug("[CopyProtoEntry] Original Name: %s, Aliases: 0x%p\n", wsentry
->p_name
, wsentry
->p_aliases
));
78 entry
->p_name
= CopyString(wsentry
->p_name
, pool
);
79 D(bug("[CopyProtoEntry] Copied name: 0x%p (%s)\n", entry
->p_name
, entry
->p_name
));
82 entry
->p_aliases
= CopyStringArray(wsentry
->p_aliases
, pool
);
83 D(bug("[CopyProtoEntry] Copied alias table: 0x%p\n", entry
->p_aliases
));
86 entry
->p_proto
= wsentry
->p_proto
;
92 /* Free the incomplete entry */
93 FreeProtoEntry(entry
, pool
);
99 void FreeProtoEntry(struct protoent
*entry
, APTR pool
)
101 if (entry
->p_aliases
)
102 FreeStringArray(entry
->p_aliases
, pool
);
104 FreeVecPooled(entry
->p_name
, pool
);
106 FreePooled(pool
, entry
, sizeof(struct protoent
));