Rename xmalloc_and_zero() to xzalloc().
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 1 May 2013 15:31:33 +0000 (17:31 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 1 May 2013 15:31:33 +0000 (17:31 +0200)
The former name is more or less only used by tinc, the latter is used by other
projects as well, and shorter as well.

16 files changed:
src/conf.c
src/connection.c
src/edge.c
src/fake-getaddrinfo.c
src/hash.c
src/list.c
src/net.c
src/net_socket.c
src/node.c
src/openssl/cipher.c
src/openssl/digest.c
src/splay_tree.c
src/subnet.c
src/tincctl.c
src/top.c
src/xalloc.h

index c4f8abb..71e4509 100644 (file)
@@ -71,7 +71,7 @@ void exit_configuration(splay_tree_t ** config_tree) {
 }
 
 config_t *new_config(void) {
 }
 
 config_t *new_config(void) {
-       return xmalloc_and_zero(sizeof(config_t));
+       return xzalloc(sizeof(config_t));
 }
 
 void free_config(config_t *cfg) {
 }
 
 void free_config(config_t *cfg) {
index 9c45978..496f674 100644 (file)
@@ -48,7 +48,7 @@ void exit_connections(void) {
 }
 
 connection_t *new_connection(void) {
 }
 
 connection_t *new_connection(void) {
-       return xmalloc_and_zero(sizeof(connection_t));
+       return xzalloc(sizeof(connection_t));
 }
 
 void free_connection(connection_t *c) {
 }
 
 void free_connection(connection_t *c) {
index fd03327..b34fdc2 100644 (file)
@@ -70,7 +70,7 @@ void exit_edges(void) {
 /* Creation and deletion of connection elements */
 
 edge_t *new_edge(void) {
 /* Creation and deletion of connection elements */
 
 edge_t *new_edge(void) {
-       return xmalloc_and_zero(sizeof(edge_t));
+       return xzalloc(sizeof(edge_t));
 }
 
 void free_edge(edge_t *e) {
 }
 
 void free_edge(edge_t *e) {
index db50f73..cb821b5 100644 (file)
@@ -48,7 +48,7 @@ void freeaddrinfo(struct addrinfo *ai) {
 static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) {
        struct addrinfo *ai;
 
 static struct addrinfo *malloc_ai(uint16_t port, uint32_t addr) {
        struct addrinfo *ai;
 
-       ai = xmalloc_and_zero(sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
+       ai = xzalloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_in));
 
        ai->ai_addr = (struct sockaddr *)(ai + 1);
        ai->ai_addrlen = sizeof(struct sockaddr_in);
 
        ai->ai_addr = (struct sockaddr *)(ai + 1);
        ai->ai_addrlen = sizeof(struct sockaddr_in);
index 1d203c5..36b510c 100644 (file)
@@ -52,11 +52,11 @@ static uint32_t modulo(uint32_t hash, size_t n) {
 /* (De)allocation */
 
 hash_t *hash_alloc(size_t n, size_t size) {
 /* (De)allocation */
 
 hash_t *hash_alloc(size_t n, size_t size) {
-       hash_t *hash = xmalloc_and_zero(sizeof *hash);
+       hash_t *hash = xzalloc(sizeof *hash);
        hash->n = n;
        hash->size = size;
        hash->n = n;
        hash->size = size;
-       hash->keys = xmalloc_and_zero(hash->n * hash->size);
-       hash->values = xmalloc_and_zero(hash->n * sizeof *hash->values);
+       hash->keys = xzalloc(hash->n * hash->size);
+       hash->values = xzalloc(hash->n * sizeof *hash->values);
        return hash;
 }
 
        return hash;
 }
 
index 2dd414a..e2eeabc 100644 (file)
@@ -26,7 +26,7 @@
 /* (De)constructors */
 
 list_t *list_alloc(list_action_t delete) {
 /* (De)constructors */
 
 list_t *list_alloc(list_action_t delete) {
-       list_t *list = xmalloc_and_zero(sizeof(list_t));
+       list_t *list = xzalloc(sizeof(list_t));
        list->delete = delete;
 
        return list;
        list->delete = delete;
 
        return list;
@@ -37,7 +37,7 @@ void list_free(list_t *list) {
 }
 
 list_node_t *list_alloc_node(void) {
 }
 
 list_node_t *list_alloc_node(void) {
-       return xmalloc_and_zero(sizeof(list_node_t));
+       return xzalloc(sizeof(list_node_t));
 }
 
 void list_free_node(list_t *list, list_node_t *node) {
 }
 
 void list_free_node(list_t *list, list_node_t *node) {
index 1487e81..d2eacf3 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -224,7 +224,7 @@ static void periodic_handler(void *data) {
 
                                if(!found) {
                                        logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
 
                                if(!found) {
                                        logger(DEBUG_CONNECTIONS, LOG_INFO, "Autoconnecting to %s", n->name);
-                                       outgoing_t *outgoing = xmalloc_and_zero(sizeof *outgoing);
+                                       outgoing_t *outgoing = xzalloc(sizeof *outgoing);
                                        outgoing->name = xstrdup(n->name);
                                        list_insert_tail(outgoing_list, outgoing);
                                        setup_outgoing_connection(outgoing);
                                        outgoing->name = xstrdup(n->name);
                                        list_insert_tail(outgoing_list, outgoing);
                                        setup_outgoing_connection(outgoing);
index 5332ed2..1b49aee 100644 (file)
@@ -674,7 +674,7 @@ void try_outgoing_connections(void) {
                }
 
                if(!found) {
                }
 
                if(!found) {
-                       outgoing_t *outgoing = xmalloc_and_zero(sizeof *outgoing);
+                       outgoing_t *outgoing = xzalloc(sizeof *outgoing);
                        outgoing->name = name;
                        list_insert_tail(outgoing_list, outgoing);
                        setup_outgoing_connection(outgoing);
                        outgoing->name = name;
                        list_insert_tail(outgoing_list, outgoing);
                        setup_outgoing_connection(outgoing);
index 2f51744..aab83ca 100644 (file)
@@ -50,9 +50,9 @@ void exit_nodes(void) {
 }
 
 node_t *new_node(void) {
 }
 
 node_t *new_node(void) {
-       node_t *n = xmalloc_and_zero(sizeof *n);
+       node_t *n = xzalloc(sizeof *n);
 
 
-       if(replaywin) n->late = xmalloc_and_zero(replaywin);
+       if(replaywin) n->late = xzalloc(replaywin);
        n->subnet_tree = new_subnet_tree();
        n->edge_tree = new_edge_tree();
        n->mtu = MTU;
        n->subnet_tree = new_subnet_tree();
        n->edge_tree = new_edge_tree();
        n->mtu = MTU;
index 32cb5ce..7f73cb1 100644 (file)
@@ -40,7 +40,7 @@ typedef struct cipher_counter {
 } cipher_counter_t;
 
 static cipher_t *cipher_open(const EVP_CIPHER *evp_cipher) {
 } cipher_counter_t;
 
 static cipher_t *cipher_open(const EVP_CIPHER *evp_cipher) {
-       cipher_t *cipher = xmalloc_and_zero(sizeof *cipher);
+       cipher_t *cipher = xzalloc(sizeof *cipher);
        cipher->cipher = evp_cipher;
        EVP_CIPHER_CTX_init(&cipher->ctx);
 
        cipher->cipher = evp_cipher;
        EVP_CIPHER_CTX_init(&cipher->ctx);
 
@@ -135,7 +135,7 @@ bool cipher_set_counter_key(cipher_t *cipher, void *key) {
        }
 
        if(!cipher->counter)
        }
 
        if(!cipher->counter)
-               cipher->counter = xmalloc_and_zero(sizeof *cipher->counter);
+               cipher->counter = xzalloc(sizeof *cipher->counter);
        else
                cipher->counter->n = 0;
 
        else
                cipher->counter->n = 0;
 
index 9406701..9699d37 100644 (file)
@@ -29,7 +29,7 @@
 #include "../logger.h"
 
 static digest_t *digest_open(const EVP_MD *evp_md, int maclength) {
 #include "../logger.h"
 
 static digest_t *digest_open(const EVP_MD *evp_md, int maclength) {
-       digest_t *digest = xmalloc_and_zero(sizeof *digest);
+       digest_t *digest = xzalloc(sizeof *digest);
        digest->digest = evp_md;
 
        int digestlen = EVP_MD_size(digest->digest);
        digest->digest = evp_md;
 
        int digestlen = EVP_MD_size(digest->digest);
index 54a46f2..6b5b56f 100644 (file)
@@ -238,7 +238,7 @@ static void splay_bottom_up(splay_tree_t *tree, splay_node_t *node) {
 splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) {
        splay_tree_t *tree;
 
 splay_tree_t *splay_alloc_tree(splay_compare_t compare, splay_action_t delete) {
        splay_tree_t *tree;
 
-       tree = xmalloc_and_zero(sizeof(splay_tree_t));
+       tree = xzalloc(sizeof(splay_tree_t));
        tree->compare = compare;
        tree->delete = delete;
 
        tree->compare = compare;
        tree->delete = delete;
 
@@ -250,7 +250,7 @@ void splay_free_tree(splay_tree_t *tree) {
 }
 
 splay_node_t *splay_alloc_node(void) {
 }
 
 splay_node_t *splay_alloc_node(void) {
-       return xmalloc_and_zero(sizeof(splay_node_t));
+       return xzalloc(sizeof(splay_node_t));
 }
 
 void splay_free_node(splay_tree_t *tree, splay_node_t *node) {
 }
 
 void splay_free_node(splay_tree_t *tree, splay_node_t *node) {
index 12ca03c..bf4300e 100644 (file)
@@ -79,7 +79,7 @@ void free_subnet_tree(splay_tree_t *subnet_tree) {
 /* Allocating and freeing space for subnets */
 
 subnet_t *new_subnet(void) {
 /* Allocating and freeing space for subnets */
 
 subnet_t *new_subnet(void) {
-       return xmalloc_and_zero(sizeof(subnet_t));
+       return xzalloc(sizeof(subnet_t));
 }
 
 void free_subnet(subnet_t *subnet) {
 }
 
 void free_subnet(subnet_t *subnet) {
index a8930fe..331299a 100644 (file)
@@ -792,7 +792,7 @@ static int cmd_start(int argc, char *argv[]) {
                c = "tincd";
 
        int nargc = 0;
                c = "tincd";
 
        int nargc = 0;
-       char **nargv = xmalloc_and_zero((optind + argc) * sizeof *nargv);
+       char **nargv = xzalloc((optind + argc) * sizeof *nargv);
 
        nargv[nargc++] = c;
        for(int i = 1; i < optind; i++)
 
        nargv[nargc++] = c;
        for(int i = 1; i < optind; i++)
index 703391c..b1ab40c 100644 (file)
--- a/src/top.c
+++ b/src/top.c
@@ -108,7 +108,7 @@ static void update(int fd) {
                                found = ns;
                                break;
                        } else {
                                found = ns;
                                break;
                        } else {
-                               found = xmalloc_and_zero(sizeof *found);
+                               found = xzalloc(sizeof *found);
                                found->name = xstrdup(name);
                                list_insert_before(&node_list, node, found);
                                changed = true;
                                found->name = xstrdup(name);
                                list_insert_before(&node_list, node, found);
                                changed = true;
@@ -117,7 +117,7 @@ static void update(int fd) {
                }
 
                if(!found) {
                }
 
                if(!found) {
-                       found = xmalloc_and_zero(sizeof *found);
+                       found = xzalloc(sizeof *found);
                        found->name = xstrdup(name);
                        list_insert_tail(&node_list, found);
                        changed = true;
                        found->name = xstrdup(name);
                        list_insert_tail(&node_list, found);
                        changed = true;
index 42d0d95..397f7b0 100644 (file)
@@ -1,7 +1,7 @@
 /*
    xalloc.h -- malloc and related fuctions with out of memory checking
    Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
 /*
    xalloc.h -- malloc and related fuctions with out of memory checking
    Copyright (C) 1990, 91, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
-   Copyright (C) 2011 Guus Sliepen <guus@tinc-vpn.org>
+   Copyright (C) 2011-2013 Guus Sliepen <guus@tinc-vpn.org>
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ static inline void *xmalloc(size_t n) {
        return p;
 }
 
        return p;
 }
 
-static inline void *xmalloc_and_zero(size_t n) {
+static inline void *xzalloc(size_t n) {
        void *p = calloc(1, n);
        if(!p)
                abort();
        void *p = calloc(1, n);
        if(!p)
                abort();