]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - resolv/base64.c
Consistency about byte vs character in string.texi
[thirdparty/glibc.git] / resolv / base64.c
index 98983e0a9326db1189f517e90086a9584e853165..fedc086b0c1b28a0efef45475511ead895e10c8b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996 by Internet Software Consortium.
+ * Copyright (c) 1996-1999 by Internet Software Consortium.
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -43,6 +43,7 @@
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/socket.h>
+
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <arpa/nameser.h>
 #include <ctype.h>
 #include <resolv.h>
 #include <stdio.h>
-
-#if defined(BSD) && (BSD >= 199103) && defined(AF_INET6)
-# include <stdlib.h>
-# include <string.h>
-#else
-# include "../conf/portability.h"
-#endif
+#include <stdlib.h>
+#include <string.h>
 
 #define Assert(Cond) if (!(Cond)) abort()
 
@@ -127,17 +123,12 @@ static const char Pad64 = '=';
           characters followed by one "=" padding character.
    */
 
-ssize_t
-b64_ntop(src, srclength, target, targsize)
-       u_char const *src;
-       size_t srclength;
-       char *target;
-       size_t targsize;
-{
+int
+b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) {
        size_t datalength = 0;
        u_char input[3];
        u_char output[4];
-       int i;
+       size_t i;
 
        while (2 < srclength) {
                input[0] = *src++;
@@ -191,6 +182,7 @@ b64_ntop(src, srclength, target, targsize)
        target[datalength] = '\0';      /* Returned value doesn't count \0. */
        return (datalength);
 }
+libresolv_hidden_def (b64_ntop)
 
 /* skips all whitespace anywhere.
    converts characters, four at a time, starting at (or after)
@@ -198,11 +190,8 @@ b64_ntop(src, srclength, target, targsize)
    it returns the number of data bytes stored at the target, or -1 on error.
  */
 
-ssize_t
-b64_pton(src, target, targsize)
-       char const *src;
-       u_char *target;
-       size_t targsize;
+int
+b64_pton (char const *src, u_char *target, size_t targsize)
 {
        int tarindex, state, ch;
        char *pos;
@@ -224,7 +213,7 @@ b64_pton(src, target, targsize)
                switch (state) {
                case 0:
                        if (target) {
-                               if (tarindex >= targsize)
+                               if ((size_t)tarindex >= targsize)
                                        return (-1);
                                target[tarindex] = (pos - Base64) << 2;
                        }
@@ -232,7 +221,7 @@ b64_pton(src, target, targsize)
                        break;
                case 1:
                        if (target) {
-                               if (tarindex + 1 >= targsize)
+                               if ((size_t)tarindex + 1 >= targsize)
                                        return (-1);
                                target[tarindex]   |=  (pos - Base64) >> 4;
                                target[tarindex+1]  = ((pos - Base64) & 0x0f)
@@ -243,7 +232,7 @@ b64_pton(src, target, targsize)
                        break;
                case 2:
                        if (target) {
-                               if (tarindex + 1 >= targsize)
+                               if ((size_t)tarindex + 1 >= targsize)
                                        return (-1);
                                target[tarindex]   |=  (pos - Base64) >> 2;
                                target[tarindex+1]  = ((pos - Base64) & 0x03)
@@ -254,7 +243,7 @@ b64_pton(src, target, targsize)
                        break;
                case 3:
                        if (target) {
-                               if (tarindex >= targsize)
+                               if ((size_t)tarindex >= targsize)
                                        return (-1);
                                target[tarindex] |= (pos - Base64);
                        }
@@ -280,7 +269,7 @@ b64_pton(src, target, targsize)
 
                case 2:         /* Valid, means one byte of info */
                        /* Skip any number of spaces. */
-                       for (NULL; ch != '\0'; ch = *src++)
+                       for ((void)NULL; ch != '\0'; ch = *src++)
                                if (!isspace(ch))
                                        break;
                        /* Make sure there is another trailing = sign. */
@@ -295,7 +284,7 @@ b64_pton(src, target, targsize)
                         * We know this char is an =.  Is there anything but
                         * whitespace after it?
                         */
-                       for (NULL; ch != '\0'; ch = *src++)
+                       for ((void)NULL; ch != '\0'; ch = *src++)
                                if (!isspace(ch))
                                        return (-1);