Change to using void * for character function content parameter
authorJonathan McDowell <noodles@earth.li>
Sat, 23 Apr 2011 22:45:16 +0000 (23:45 +0100)
committerJonathan McDowell <noodles@earth.li>
Sat, 23 Apr 2011 22:45:16 +0000 (23:45 +0100)
  We were passing unsigned char * as the parameter to all of the
  character fetching/putting functions. Use void * instead so that
  we can pass other types of data without needlessly having to cast.

armor.c
armor.h
charfuncs.c
charfuncs.h
keydb_pg.c
parsekey.c
parsekey.h
sendsync.c

diff --git a/armor.c b/armor.c
index a192f77d18d8df0f624f67b2b54e2eac5fbb6a39..397118cb22b7bffae17b963b89d1b7acdc9227f6 100644 (file)
--- a/armor.c
+++ b/armor.c
@@ -77,7 +77,7 @@ struct armor_context {
        int curoctet;
        int count;
        long crc24;
-       int (*putchar_func)(void *ctx, size_t count, unsigned char *c);
+       int (*putchar_func)(void *ctx, size_t count, void *c);
        void *ctx;
 };
 
@@ -184,14 +184,14 @@ static int armor_putchar_int(void *ctx, unsigned char c)
 }
 
 
-static int armor_putchar(void *ctx, size_t count, unsigned char *c)
+static int armor_putchar(void *ctx, size_t count, void *c)
 {
        int i;
 
        log_assert(c != NULL);
 
        for (i = 0; i < count; i++) {
-               armor_putchar_int(ctx, c[i]);
+               armor_putchar_int(ctx, ((char *) c)[i]);
        }
        
        return 0;
@@ -210,7 +210,7 @@ struct dearmor_context {
        int curoctet;
        int count;
        long crc24;
-       int (*getchar_func)(void *ctx, size_t count, unsigned char *c);
+       int (*getchar_func)(void *ctx, size_t count, void *c);
        void *ctx;
 };
 
@@ -291,12 +291,12 @@ static int dearmor_getchar(void *ctx, unsigned char *c)
        return (tmpc == 64);
 }
 
-static int dearmor_getchar_c(void *ctx, size_t count, unsigned char *c)
+static int dearmor_getchar_c(void *ctx, size_t count, void *c)
 {
        int i, rc = 0;
 
        for (i = 0; i < count && rc == 0; i++) {
-               rc = dearmor_getchar(ctx, &c[i]);
+               rc = dearmor_getchar(ctx, &((unsigned char *) c)[i]);
        }
 
        return rc;
@@ -312,7 +312,7 @@ static int dearmor_getchar_c(void *ctx, size_t count, unsigned char *c)
  *     using putchar_func.
  */
 int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
-                                               unsigned char *c),
+                                               void *c),
                                void *ctx,
                                struct openpgp_packet_list *packets)
 {
@@ -352,7 +352,7 @@ int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
  *     packets.
  */
 int dearmor_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
-                                               unsigned char *c),
+                                               void *c),
                                void *ctx,
                                struct openpgp_packet_list **packets)
 {
diff --git a/armor.h b/armor.h
index 85ac6a644b1576509b353c22d8e5eab994d12caa..8f5dc3522b0a3e20f4886475695cb8c123cacac8 100644 (file)
--- a/armor.h
+++ b/armor.h
@@ -21,7 +21,7 @@
  *     using putchar_func.
  */
 int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
-                                               unsigned char *c),
+                                               void *c),
                                void *ctx,
                                struct openpgp_packet_list *packets);
 
@@ -36,7 +36,7 @@ int armor_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
  *     packets.
  */
 int dearmor_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
-                                       unsigned char *c),
+                                       void *c),
                                void *ctx,
                                struct openpgp_packet_list **packets);
 
index 778df1ca477732fac168895fc3094e45af329ae4..fea0a99cf0081218b831794b55dc8db599e31176 100644 (file)
@@ -20,7 +20,7 @@
  *     @count: The number of characters to get from the buffer.
  *     @c: Where to put the characters retrieved.
  */
-int buffer_fetchchar(void *ctx, size_t count, unsigned char *c)
+int buffer_fetchchar(void *ctx, size_t count, void *c)
 {
        struct buffer_ctx *buf = NULL;
        
@@ -42,7 +42,7 @@ int buffer_fetchchar(void *ctx, size_t count, unsigned char *c)
  *     fill it then we double the size of the current buffer and then add the
  *     rest.
  */
-int buffer_putchar(void *ctx, size_t count, unsigned char *c)
+int buffer_putchar(void *ctx, size_t count, void *c)
 {
        struct buffer_ctx *buf = NULL;
        size_t newsize = 0;
@@ -66,7 +66,7 @@ int buffer_putchar(void *ctx, size_t count, unsigned char *c)
 /**
  *     file_fetchchar - Fetches a char from a file.
  */
-int file_fetchchar(void *fd, size_t count, unsigned char *c)
+int file_fetchchar(void *fd, size_t count, void *c)
 {
        return !(read( *(int *) fd, c, count));
 }
@@ -74,7 +74,7 @@ int file_fetchchar(void *fd, size_t count, unsigned char *c)
 /**
  *     file_putchar - Puts a char to a file.
  */
-int file_putchar(void *fd, size_t count, unsigned char *c)
+int file_putchar(void *fd, size_t count, void *c)
 {
        return !(write( *(int *) fd, c, count));
 }
@@ -82,7 +82,7 @@ int file_putchar(void *fd, size_t count, unsigned char *c)
 /**
  *     stdin_getchar - Gets a char from stdin.
  */
-int stdin_getchar(void *ctx, size_t count, unsigned char *c)
+int stdin_getchar(void *ctx, size_t count, void *c)
 {
        return (fread(c, 1, count, stdin) != count);
 }
@@ -90,7 +90,7 @@ int stdin_getchar(void *ctx, size_t count, unsigned char *c)
 /**
  *     stdout_putchar - Puts a char to stdout.
  */
-int stdout_putchar(void *ctx, size_t count, unsigned char *c)
+int stdout_putchar(void *ctx, size_t count, void *c)
 {
        return (fwrite(c, 1, count, stdout) != count);
 }
index ad460e4a9667f246c6198ce603c6cb817ac9199e..b09edf375cf58d33bbb61a06890817c7b992e491 100644 (file)
@@ -29,7 +29,7 @@ struct buffer_ctx {
  *     @count: The number of characters to get from the buffer.
  *     @c: Where to put the characters retrieved.
  */
-int buffer_fetchchar(void *ctx, size_t count, unsigned char *c);
+int buffer_fetchchar(void *ctx, size_t count, void *c);
 
 /**
  *     buffer_putchar - Puts a char to a buffer.
@@ -41,26 +41,26 @@ int buffer_fetchchar(void *ctx, size_t count, unsigned char *c);
  *     fill it then we double the size of the current buffer and then add the
  *     rest.
  */
-int buffer_putchar(void *ctx, size_t count, unsigned char *c);
+int buffer_putchar(void *ctx, size_t count, void *c);
 
 /**
  *     file_fetchchar - Fetches a char from a file.
  */
-int file_fetchchar(void *fd, size_t count, unsigned char *c);
+int file_fetchchar(void *fd, size_t count, void *c);
 
 /**
  *     file_putchar - Puts a char to a file.
  */
-int file_putchar(void *fd, size_t count, unsigned char *c);
+int file_putchar(void *fd, size_t count, void *c);
 
 /**
  *     stdin_getchar - Gets a char from stdin.
  */
-int stdin_getchar(void *ctx, size_t count, unsigned char *c);
+int stdin_getchar(void *ctx, size_t count, void *c);
 
 /**
  *     stdout_putchar - Puts a char to stdout.
  */
-int stdout_putchar(void *ctx, size_t count, unsigned char *c);
+int stdout_putchar(void *ctx, size_t count, void *c);
 
 #endif /* __CHARFUNCS_H__ */
index e71ddee3b71777324d6b0b62a82bc3794403b320..0771317e747ab1c65a22e5ef71ddb2e7a936a903 100644 (file)
@@ -36,7 +36,7 @@ static PGconn *dbconn = NULL;
 /**
  *     keydb_fetchchar - Fetches a char from a file.
  */
-static int keydb_fetchchar(void *fd, size_t count, unsigned char *c)
+static int keydb_fetchchar(void *fd, size_t count, void *c)
 {
        return (!lo_read(dbconn, *(int *) fd, (char *) c, count));
 }
@@ -44,7 +44,7 @@ static int keydb_fetchchar(void *fd, size_t count, unsigned char *c)
 /**
  *     keydb_putchar - Puts a char to a file.
  */
-static int keydb_putchar(void *fd, size_t count, unsigned char *c)
+static int keydb_putchar(void *fd, size_t count, void *c)
 {
        return !(lo_write(dbconn, *(int *) fd, (char *) c, count));
 }
index a0c0311aec1e98fa1fb0294d92562f7055958a62..2d9510697cbe8d893f9ae6c8017f6b419ba8b476 100644 (file)
@@ -168,7 +168,7 @@ int debug_packet(struct openpgp_packet *packet)
  *     ready for parsing as a public key or whatever.
  */
 int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
-                               unsigned char *c),
+                               void *c),
                                void *ctx,
                                struct openpgp_packet_list **packets,
                                int maxnum)
@@ -322,7 +322,7 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
  *     packet stream from a linked list of packets.
  */
 int write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
-                                               unsigned char *c),
+                                               void *c),
                                void *ctx,
                                struct openpgp_packet_list *packets)
 {
index 17784459c54afa6779c396f063812682b277b924..8718d1c910dc9bf9150a8499393d3d3dcc1bcfe9 100644 (file)
@@ -49,7 +49,7 @@ int debug_packet(struct openpgp_packet *packet);
  *     none of the other packets of the key will be read.
  */
 int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
-                               unsigned char *c),
+                               void *c),
                                void *ctx,
                                struct openpgp_packet_list **packets,
                                int maxnum);
@@ -64,7 +64,7 @@ int read_openpgp_stream(int (*getchar_func)(void *ctx, size_t count,
  *     packet stream from a linked list of packets.
  */
 int write_openpgp_stream(int (*putchar_func)(void *ctx, size_t count,
-                                               unsigned char *c),
+                                               void *c),
                                void *ctx,
                                struct openpgp_packet_list *packets);
 
index ffcf70508dd4adf85d3e2c9348593ecf3804f9ba..ace6b0d798099107b375cf0b2a7936911c80a752 100644 (file)
 #include "parsekey.h"
 #include "sendsync.h"
 
-int fd_putchar(void *ctx, size_t count, unsigned char *c)
+int fd_putchar(void *ctx, size_t count, void *c)
 {
        int i;
 
        for (i = 0; i < count; i++) {
-               fputc(c[i], ctx);
+               fputc(((char *) c )[i], ctx);
        }
        return 0;
 }