Replace PARA_VSNPRINTF by xvasprintf().
[paraslash.git] / crypt_common.c
index 8fac0dc71ed37a7dff633a2891d4ada1a0c0376b..5ad4d43d883b498989412182a54e880aa3ba0766 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2011 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2012 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -7,7 +7,6 @@
 /** \file crypt_common.c Crypto functions independent of openssl/libgcrypt. */
 
 #include <regex.h>
-#include <stdbool.h>
 
 #include "para.h"
 #include "error.h"
@@ -86,7 +85,7 @@ int base64_decode(char const *src, unsigned char *target, size_t targsize)
                        break;
 
                pos = strchr(Base64, ch);
-               if (pos == 0) /* A non-base64 character. */
+               if (pos == NULL) /* A non-base64 character. */
                        return -E_BASE64;
 
                switch (state) {
@@ -338,7 +337,12 @@ int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size)
 
 int sc_send_buffer(struct stream_cipher_context *scc, char *buf)
 {
-       return sc_send_bin_buffer(scc, buf, strlen(buf));
+       size_t len = strlen(buf);
+       int ret = sc_send_bin_buffer(scc, buf, len);
+
+       if (ret < 0 || ret == len)
+               return ret;
+       return -E_SHORT_WRITE;
 }
 
 __printf_2_3 int sc_send_va_buffer(struct stream_cipher_context *scc,
@@ -346,9 +350,12 @@ __printf_2_3 int sc_send_va_buffer(struct stream_cipher_context *scc,
 {
        char *msg;
        int ret;
+       va_list ap;
 
-       PARA_VSPRINTF(fmt, msg);
-       ret = sc_send_buffer(scc, msg);
+       va_start(ap, fmt);
+       ret = xvasprintf(&msg, fmt, ap);
+       va_end(ap);
+       ret = sc_send_bin_buffer(scc, msg, ret);
        free(msg);
        return ret;
 }