Comments on new resolv.c additions
Denys Vlasenko
vda.linux at googlemail.com
Sat Sep 10 01:03:41 UTC 2011
commit 7f74de5d4d6d10baafab4b37bb3d472f5c5f0e8c
Author: Daniel Mack <zonque at gmail.com>
Date: Wed Jul 13 00:30:54 2011 +0200
inet/resolv: add res_ninit and res_nclose
Some reordering of existing functions was necessary in order to provide
this functionality.
Signed-off-by: Daniel Mack <zonque at gmail.com>
...
...
-void res_close(void)
+static void
+__res_iclose(res_state statp, int free_addr)
{
__UCLIBC_MUTEX_LOCK(__resolv_lock);
__close_nameservers();
@@ -3552,6 +3566,26 @@ void res_close(void)
memset(&_res, 0, sizeof(_res));
__UCLIBC_MUTEX_UNLOCK(__resolv_lock);
}
Obviously, neither statp nor free_addr parameters are used. Why are they there?
+void
+res_nclose(res_state statp)
+{
+ __res_iclose(statp, 1);
+}
+
+#ifdef __UCLIBC_HAS_BSD_RES_CLOSE__
+void res_close(void)
+{
+ __res_iclose(&_res, 0);
+}
and since __res_iclose() ignores its parameters,
these two functions are essentially the same. Is it intended?
If yes, can we just alias their names?
commit 5f6fe1fca1e60923503dd391a60b2ad5b9aead31
Author: Daniel Mack <zonque at gmail.com>
Date: Wed Jul 13 00:30:52 2011 +0200
inet/resolv: add ns_initparse, ns_parserr, ns_skiprr and ns_msg_getflag
There are build 'ifdef L_ns_parse'.
Signed-off-by: Daniel Mack <zonque at gmail.com>
...
...
-extern struct _ns_flagdata _ns_flagdata[];
+extern const struct _ns_flagdata _ns_flagdata[];
This table is used exactly in one place. You can make it static
(and smaller).
commit e5153a77782bf7042f50b97959536f3f181bad99
Author: Daniel Mack <zonque at gmail.com>
Date: Wed Jul 13 00:30:49 2011 +0200
inet/resolv: add ns_name_pton, ns_name_pack and ns_name_compress
These are built '#ifdef L_ns_name'
Signed-off-by: Daniel Mack <zonque at gmail.com>
...
...
+static const char digitvalue[256] = {
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*16*/
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*32*/
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*48*/
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /*64*/
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*80*/
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*96*/
+ -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*112*/
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*128*/
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+ -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /*256*/
+};
...
...
+ if (!isxdigit(c&0xff))
+ return (EINVAL);
+ value <<= 4;
+ value += digitvalue[(int)c];
Eek... there are much more compact ways to convert hex to binary.
+ if ((bitlen = *(lp + 1)) == 0)
It's not necessary to cram as much as possible into one line.
The assignment can well be done as a separate statement, and code
will be easier to read. gcc will generate the same code anyway.
--
vda
More information about the uClibc
mailing list