#984839 nntp.c: Use strchr() instead of index(); add feature_test_macros

Package:
src:nn
Source:
nn
Submitter:
Bjarni Ingi Gislason
Date:
2021-03-09 00:15:03 UTC
Severity:
normal
Tags:
#984839#5
Date:
2021-03-09 00:11:21 UTC
From:
To:
Dear Maintainer,
"strchr(3)".

  Add the header file <string.h> for "strchr(3)".

  Add a prototype for "get_group_line()".

  Move the prototype for "server_port()" from the function
"find_server()" to the prototype section at top of the file.

  Use "strchr()" instead of "index()", see "man 3 index".

Signed-off-by: Bjarni Ingi Gislason <bjarniig@rhi.hi.is>
---
 nntp.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/nntp.c b/nntp.c
index 43093b8..54785e8 100644
--- a/nntp.c
+++ b/nntp.c
@@ -13,10 +13,23 @@
  * any mistakes are mine :-)  ++Kim
  */

+/* feature_test_macros(7) for "fdopen()" and "mkstemp()" */
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 200809L
+#endif
+
+/* feature_test_macros(7) for strchr(3) */
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
+
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <string.h>
 #include <sys/param.h>
 #include <ctype.h>
 #include "config.h"
@@ -80,6 +93,7 @@ static int      reconnect_server(int);
 static int      connect_server(void);
 static void     debug_msg(char *prefix, char *str);
 static void     find_server(void);
+int		get_group_line(const char *, char *, size_t);
 static int      get_server_line(char *string, int size);
 static int      get_server(char *string, int size);
 static int      get_socket(void);
@@ -88,6 +102,7 @@ static int      copy_text(register FILE * fp);
 static struct cache *search_cache(article_number art, group_header * gh);
 static struct cache *new_cache_slot(void);
 static void     clean_cache(void);
+void		server_port(char *);
 static void     set_domain(void);
 static void     nntp_doauth(void);

@@ -210,7 +225,7 @@ find_server(void)
     char           *cp, *name;
     char            buf[BUFSIZ];
     FILE           *fp;
-    void server_port(char *);
+

     /*
      * This feature cannot normally be enabled, because the database and the
@@ -896,7 +911,7 @@ set_domain(void)
     strncpy(domain, DOMAIN, MAXHOSTNAMELEN);
 #else
     strcpy(domain, host_name);
-    cp = index(domain, '.');
+    cp = strchr(domain, '.');
     if (cp == NULL) {
 	strcat(domain, ".");
 	strncat(domain, DOMAIN, MAXHOSTNAMELEN - sizeof(host_name) - 1);
@@ -907,7 +922,7 @@ set_domain(void)

     domain[0] = '\0';

-    cp = index(host_name, '.');
+    cp = strchr(host_name, '.');
     if (cp == NULL) {
 	FILE           *resolv;

@@ -1683,8 +1698,8 @@ valid_header(register char *h)
      * just check for initial letter, colon, and space to make sure we
      * discard only invalid headers
      */
-    colon = index(h, ':');
-    space = index(h, ' ');
+    colon = strchr(h, ':');
+    space = strchr(h, ' ');
     if (isalpha(h[0]) && colon && space == colon + 1)
 	return (1);