muimaster.library: remove weird check that causes halt when application has to rememb...
[AROS.git] / arch / all-mingw32 / bsdsocket / netdb_util.c
blob3f5d6a6491905a4fcfa2d38a48cd78e85f3b979d
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <aros/debug.h>
7 #include <proto/exec.h>
9 #include <netdb.h>
10 #include <string.h>
12 #include "winsock2.h"
13 #include "netdb_util.h"
15 char *CopyString(char *src, APTR pool)
17 char *dst;
18 ULONG l = strlen(src) + 1;
20 dst = AllocVecPooled(pool, l);
21 if (dst)
22 CopyMem(src, dst, l);
24 return dst;
27 static char **CopyStringArray(char **src, APTR pool)
29 char **dst;
30 ULONG l = 0;
32 while (src[l])
34 D(bug("[CopyStringArray] Counted element: %s\n", src[l]));
35 l++;
37 D(bug("[CopyStringArray] %u elements total\n", l));
39 dst = AllocVecPooled(pool, (l + 1) * sizeof(char *));
40 if (dst)
42 ULONG i;
44 for (i = 0; i < l; i++)
46 dst[i] = CopyString(src[i], pool);
47 D(bug("[CopyStringArray] Copied element: %s\n", dst[i]));
48 if (!dst[i])
49 break;
52 /* NULL-terminate the array */
53 D(bug("[CopyStringArray] Terminator element: %u\n", i));
54 dst[i] = NULL;
57 return dst;
60 static void FreeStringArray(char **src, APTR pool)
62 ULONG i;
64 for (i = 0; src[i]; i++)
65 FreeVecPooled(pool, src[i]);
67 FreeVec(src);
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));
75 if (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));
80 if (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));
84 if (entry->p_aliases)
86 entry->p_proto = wsentry->p_proto;
88 return entry;
92 /* Free the incomplete entry */
93 FreeProtoEntry(entry, pool);
96 return NULL;
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));