]> git.puffer.fish Git - matthieu/frr.git/commitdiff
First small part of lib cleanup. Mainly "constification" of arguments and
authorhasso <hasso>
Mon, 4 Oct 2004 19:10:31 +0000 (19:10 +0000)
committerhasso <hasso>
Mon, 4 Oct 2004 19:10:31 +0000 (19:10 +0000)
adding FIXME's.

lib/ChangeLog
lib/log.c
lib/log.h
lib/memory.c
lib/memory.h
lib/network.c
lib/network.h
lib/prefix.c
lib/prefix.h

index 3049b95ab76b5aaf8467a28d87d872a3ddebb715..eec006c953e9b73c2070d326b65d13d8e1520e98 100644 (file)
@@ -1,3 +1,12 @@
+2004-10-04 Hasso Tepper <hasso at quagga.net>
+
+       * memory.c, memory.h: Make char * argument of strdup functions const.
+       * prefix.c, prefix.h: Make many arguments const. Reorder stuff in
+         header.
+       * log.h: Make log message const in struct message.
+       * log.c: Fix some indenting.
+       * network.c, network.h: Make second argument of writen() const.
+
 2004-10-03  Hasso Tepper  <hasso at quagga.net>
 
        * command.h: Introduce SERVICE_NODE for "service <...>" commands.
index 5f6b32f5507c36fa48e7732c4e5a25a53bbf77e8..2090b91ec7ee21c5dded1d2191942665794484ec 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -113,7 +113,8 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list *args)
   if (zl->flags & ZLOG_FILE)
     {
       time_print (zl->fp);
-      if (zl->record_priority) fprintf (zl->fp, "%s: ", zlog_priority[priority]);
+      if (zl->record_priority)
+       fprintf (zl->fp, "%s: ", zlog_priority[priority]);
       fprintf (zl->fp, "%s: ", zlog_proto_names[zl->protocol]);
       vfprintf (zl->fp, format, args[ZLOG_FILE_INDEX]);
       fprintf (zl->fp, "\n");
@@ -124,7 +125,8 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list *args)
   if (zl->flags & ZLOG_STDOUT)
     {
       time_print (stdout);
-      if (zl->record_priority) fprintf (stdout, "%s: ", zlog_priority[priority]);
+      if (zl->record_priority)
+       fprintf (stdout, "%s: ", zlog_priority[priority]);
       fprintf (stdout, "%s: ", zlog_proto_names[zl->protocol]);
       vfprintf (stdout, format, args[ZLOG_STDOUT_INDEX]);
       fprintf (stdout, "\n");
@@ -135,7 +137,8 @@ vzlog (struct zlog *zl, int priority, const char *format, va_list *args)
   if (zl->flags & ZLOG_STDERR)
     {
       time_print (stderr);
-      if (zl->record_priority) fprintf (stderr, "%s: ", zlog_priority[priority]);
+      if (zl->record_priority)
+       fprintf (stderr, "%s: ", zlog_priority[priority]);
       fprintf (stderr, "%s: ", zlog_proto_names[zl->protocol]);
       vfprintf (stderr, format, args[ZLOG_STDERR_INDEX]);
       fprintf (stderr, "\n");
@@ -484,7 +487,7 @@ lookup (struct message *mes, int key)
 }
 
 /* Very old hacky version of message lookup function.  Still partly
-   used in bgpd and ospfd. */
+   used in bgpd and ospfd. FIXME Seems that it's not used any more. */
 char *
 mes_lookup (struct message *meslist, int max, int index)
 {
index 8948ea00bff26b81aa1b486cb5584d99d29fc2d0..defe06417f18ab0ac8e367ac077853b741a4037c 100644 (file)
--- a/lib/log.h
+++ b/lib/log.h
@@ -71,7 +71,7 @@ struct zlog
 struct message
 {
   int key;
-  char *str;
+  const char *str;
 };
 
 /* Default logging strucutre. */
index faf3f266ebdb73fc219c8ecc1511d71eca5e6c27..8b311aeacd8fab736db14d9778c961c771d608e9 100644 (file)
@@ -101,7 +101,7 @@ zfree (int type, void *ptr)
 
 /* String duplication. */
 char *
-zstrdup (int type, char *str)
+zstrdup (int type, const char *str)
 {
   void *dup;
 
@@ -115,7 +115,7 @@ zstrdup (int type, char *str)
 #ifdef MEMORY_LOG
 struct 
 {
-  char *name;
+  const char *name;
   unsigned long alloc;
   unsigned long t_malloc;
   unsigned long c_malloc;
@@ -187,7 +187,7 @@ mtype_zfree (const char *file, int line, int type, void *ptr)
 }
 
 char *
-mtype_zstrdup (const char *file, int line, int type, char *str)
+mtype_zstrdup (const char *file, int line, int type, const char *str)
 {
   char *memory;
 
@@ -230,7 +230,7 @@ alloc_dec (int type)
 struct memory_list
 {
   int index;
-  char *format;
+  const char *format;
 };
 
 struct memory_list memory_list_lib[] =
index 40081fe0754563d3dcb3ca9ed940c8179356beb1..c2d595a47967f267b1894f9ea63df56fd8ea2523 100644 (file)
@@ -236,7 +236,7 @@ void *zmalloc (int type, size_t size);
 void *zcalloc (int type, size_t size);
 void *zrealloc (int type, void *ptr, size_t size);
 void  zfree (int type, void *ptr);
-char *zstrdup (int type, char *str);
+char *zstrdup (int type, const char *str);
 
 void *mtype_zmalloc (const char *file,
                     int line,
@@ -263,7 +263,7 @@ void mtype_zfree (const char *file,
 char *mtype_zstrdup (const char *file,
                     int line,
                     int type,
-                    char *str);
+                    const char *str);
 void memory_init ();
 
 #endif /* _ZEBRA_MEMORY_H */
index d105db48d31bd179a3578b67b83e1624e54c8be4..e1f733cf21484bc204b7dd4427e59da128193567 100644 (file)
@@ -50,7 +50,7 @@ readn (int fd, u_char *ptr, int nbytes)
 
 /* Write nbytes from ptr to fd. */
 int
-writen(int fd, u_char *ptr, int nbytes)
+writen(int fd, const u_char *ptr, int nbytes)
 {
   int nleft;
   int nwritten;
index 0544361fe82127a248d3d99367f881546b0ab605..f0a7d4df64325bb3432daf1b5898f0f4519d2278 100644 (file)
@@ -24,6 +24,6 @@
 #define _ZEBRA_NETWORK_H
 
 int readn (int, u_char *, int);
-int writen (int, u_char *, int);
+int writen (int, const u_char *, int);
 
 #endif /* _ZEBRA_NETWORK_H */
index 5a3e71bfed44e0bf796f8e3ea6634b1f1332f390..d9751e3ff48cfffde7721c5e36d8e308da32d1b6 100644 (file)
@@ -66,7 +66,7 @@ family2afi (int family)
 
 /* If n includes p prefix then return 1 else return 0. */
 int
-prefix_match (struct prefix *n, struct prefix *p)
+prefix_match (const struct prefix *n, const struct prefix *p)
 {
   int offset;
   int shift;
@@ -94,7 +94,7 @@ prefix_match (struct prefix *n, struct prefix *p)
 
 /* Copy prefix from src to dest. */
 void
-prefix_copy (struct prefix *dest, struct prefix *src)
+prefix_copy (struct prefix *dest, const struct prefix *src)
 {
   dest->family = src->family;
   dest->prefixlen = src->prefixlen;
@@ -127,7 +127,7 @@ prefix_copy (struct prefix *dest, struct prefix *src)
  * as '==' (which is different from prefix_cmp).
  */
 int
-prefix_same (struct prefix *p1, struct prefix *p2)
+prefix_same (const struct prefix *p1, const struct prefix *p2)
 {
   if (p1->family == p2->family && p1->prefixlen == p2->prefixlen)
     {
@@ -154,7 +154,7 @@ prefix_same (struct prefix *p1, struct prefix *p2)
  * from prefix_same).
  */
 int
-prefix_cmp (struct prefix *p1, struct prefix *p2)
+prefix_cmp (const struct prefix *p1, const struct prefix *p2)
 {
   int offset;
   int shift;
@@ -181,8 +181,8 @@ prefix_cmp (struct prefix *p1, struct prefix *p2)
 }
 
 /* Return prefix family type string. */
-char *
-prefix_family_str (struct prefix *p)
+const char *
+prefix_family_str (const struct prefix *p)
 {
   if (p->family == AF_INET)
     return "inet";
@@ -213,7 +213,7 @@ prefix_ipv4_free (struct prefix_ipv4 *p)
 
 /* When string format is invalid return 0. */
 int
-str2prefix_ipv4 (char *str, struct prefix_ipv4 *p)
+str2prefix_ipv4 (const char *str, struct prefix_ipv4 *p)
 {
   int ret;
   int plen;
@@ -335,7 +335,7 @@ apply_mask_ipv4 (struct prefix_ipv4 *p)
 
 /* If prefix is 0.0.0.0/0 then return 1 else return 0. */
 int
-prefix_ipv4_any (struct prefix_ipv4 *p)
+prefix_ipv4_any (const struct prefix_ipv4 *p)
 {
   return (p->prefix.s_addr == 0 && p->prefixlen == 0);
 }
@@ -362,7 +362,7 @@ prefix_ipv6_free (struct prefix_ipv6 *p)
 
 /* If given string is valid return pin6 else return NULL */
 int
-str2prefix_ipv6 (char *str, struct prefix_ipv6 *p)
+str2prefix_ipv6 (const char *str, struct prefix_ipv6 *p)
 {
   char *pnt;
   char *cp;
@@ -399,7 +399,8 @@ str2prefix_ipv6 (char *str, struct prefix_ipv6 *p)
   return ret;
 }
 
-/* Convert struct in6_addr netmask into integer. */
+/* Convert struct in6_addr netmask into integer.
+ * FIXME return u_char as ip_maskleni() does. */
 int
 ip6_masklen (struct in6_addr netmask)
 {
@@ -470,7 +471,7 @@ apply_mask_ipv6 (struct prefix_ipv6 *p)
 }
 
 void
-str2in6_addr (char *str, struct in6_addr *addr)
+str2in6_addr (const char *str, struct in6_addr *addr)
 {
   int i;
   unsigned int x;
@@ -503,10 +504,11 @@ apply_mask (struct prefix *p)
   return;
 }
 
-/* Utility function of convert between struct prefix <=> union sockunion */
+/* Utility function of convert between struct prefix <=> union sockunion.
+ * FIXME This function isn't used anywhere. */
 struct prefix *
-sockunion2prefix (union sockunion *dest,
-                 union sockunion *mask)
+sockunion2prefix (const union sockunion *dest,
+                 const union sockunion *mask)
 {
   if (dest->sa.sa_family == AF_INET)
     {
@@ -533,9 +535,9 @@ sockunion2prefix (union sockunion *dest,
   return NULL;
 }
 
-/* Utility function of convert between struct prefix <=> union sockunion */
+/* Utility function of convert between struct prefix <=> union sockunion. */
 struct prefix *
-sockunion2hostprefix (union sockunion *su)
+sockunion2hostprefix (const union sockunion *su)
 {
   if (su->sa.sa_family == AF_INET)
     {
@@ -563,7 +565,7 @@ sockunion2hostprefix (union sockunion *su)
 }
 
 int
-prefix_blen (struct prefix *p)
+prefix_blen (const struct prefix *p)
 {
   switch (p->family) 
     {
@@ -581,7 +583,7 @@ prefix_blen (struct prefix *p)
 
 /* Generic function for conversion string to struct prefix. */
 int
-str2prefix (char *str, struct prefix *p)
+str2prefix (const char *str, struct prefix *p)
 {
   int ret;
 
@@ -601,7 +603,7 @@ str2prefix (char *str, struct prefix *p)
 }
 
 int
-prefix2str (struct prefix *p, char *str, int size)
+prefix2str (const struct prefix *p, char *str, int size)
 {
   char buf[BUFSIZ];
 
@@ -627,9 +629,10 @@ prefix_free (struct prefix *p)
 }
 
 /* Utility function.  Check the string only contains digit
-   character. */
+ * character.
+ * FIXME str.[c|h] would be better place for this function. */
 int
-all_digit (char *str)
+all_digit (const char *str)
 {
   for (; *str != '\0'; str++)
     if (!isdigit ((int) *str))
@@ -668,7 +671,8 @@ void apply_classful_mask_ipv4 (struct prefix_ipv4 *p)
    ex.) "1.1.0.0" "255.255.0.0" => "1.1.0.0/16"
    ex.) "1.0.0.0" NULL => "1.0.0.0/8"                   */
 int
-netmask_str2prefix_str (char *net_str, char *mask_str, char *prefix_str)
+netmask_str2prefix_str (const char *net_str, const char *mask_str,
+                       char *prefix_str)
 {
   struct in_addr network;
   struct in_addr mask;
index 5884640a441c4e5c86481fa4f71f599c1b967dea..e4f17ab02ab048763b8f19409b62fabdd0cb0f87 100644 (file)
@@ -128,43 +128,45 @@ struct prefix_rd
 int afi2family (int);
 int family2afi (int);
 
-int prefix2str (struct prefix *, char *, int);
-int str2prefix (char *, struct prefix *);
 struct prefix *prefix_new ();
-void prefix_free (struct prefix *p);
+void prefix_free (struct prefix *);
+const char *prefix_family_str (const struct prefix *);
+int prefix_blen (const struct prefix *);
+int str2prefix (const char *, struct prefix *);
+int prefix2str (const struct prefix *, char *, int);
+int prefix_match (const struct prefix *, const struct prefix *);
+int prefix_same (const struct prefix *, const struct prefix *);
+int prefix_cmp (const struct prefix *, const struct prefix *);
+void prefix_copy (struct prefix *dest, const struct prefix *src);
+void apply_mask (struct prefix *);
+
+struct prefix *sockunion2prefix ();
+struct prefix *sockunion2hostprefix ();
 
 struct prefix_ipv4 *prefix_ipv4_new ();
-void prefix_ipv4_free ();
-int str2prefix_ipv4 (char *, struct prefix_ipv4 *);
+void prefix_ipv4_free (struct prefix_ipv4 *);
+int str2prefix_ipv4 (const char *, struct prefix_ipv4 *);
 void apply_mask_ipv4 (struct prefix_ipv4 *);
-int prefix_blen (struct prefix *);
-u_char ip_masklen (struct in_addr);
-int prefix_ipv4_any (struct prefix_ipv4 *);
-void masklen2ip (int, struct in_addr *);
+
+int prefix_ipv4_any (const struct prefix_ipv4 *);
 void apply_classful_mask_ipv4 (struct prefix_ipv4 *);
 
-char *prefix_family_str (struct prefix *p);
-struct prefix *sockunion2prefix ();
-struct prefix *sockunion2hostprefix ();
+u_char ip_masklen (struct in_addr);
+void masklen2ip (int, struct in_addr *);
+int netmask_str2prefix_str (const char *, const char *, char *);
 
 #ifdef HAVE_IPV6
 struct prefix_ipv6 *prefix_ipv6_new ();
-void prefix_ipv6_free ();
-struct prefix *str2routev6 (char *);
-int str2prefix_ipv6 (char *str, struct prefix_ipv6 *p);
-void apply_mask_ipv6 (struct prefix_ipv6 *p);
-void str2in6_addr (char *str, struct in6_addr *addr);
-void masklen2ip6 (int masklen, struct in6_addr *netmask);
-int ip6_masklen (struct in6_addr netmask);
-#endif /* HAVE_IPV6 */
+void prefix_ipv6_free (struct prefix_ipv6 *);
+int str2prefix_ipv6 (const char *, struct prefix_ipv6 *);
+void apply_mask_ipv6 (struct prefix_ipv6 *);
 
-void apply_mask (struct prefix *);
-int prefix_match (struct prefix *n, struct prefix *p);
-int prefix_same (struct prefix *, struct prefix *);
-int prefix_cmp (struct prefix *, struct prefix *);
-void prefix_copy (struct prefix *, struct prefix *);
+int ip6_masklen (struct in6_addr);
+void masklen2ip6 (int, struct in6_addr *);
+
+void str2in6_addr (const char *, struct in6_addr *);
+#endif /* HAVE_IPV6 */
 
-int all_digit (char *);
-int netmask_str2prefix_str (char *, char *, char *);
+int all_digit (const char *);
 
 #endif /* _ZEBRA_PREFIX_H */