less horrible strncpy's
[apps/madmutt.git] / nntp / newsrc.c
index fb5fc1b..ff9df9e 100644 (file)
@@ -15,6 +15,7 @@
 
 #include <lib-lib/mem.h>
 #include <lib-lib/str.h>
+#include <lib-lib/file.h>
 #include <lib-lib/macros.h>
 
 #include "mutt.h"
@@ -218,10 +219,10 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news)
     if (!*cp)
       continue;
     cp[0] = 0;
-    if (!str_cmp (buf, "#:"))
+    if (!m_strcmp(buf, "#:"))
       break;
     sscanf (cp + 1, "%s %d %d", file, &l, &m);
-    if (!str_cmp (buf, "ALL")) {
+    if (!m_strcmp(buf, "ALL")) {
       news->cache = m_strdup(file);
       news->newgroups_time = m;
     }
@@ -264,7 +265,7 @@ const char *nntp_format_str (char *dest, size_t destlen, char op,
 
   switch (op) {
   case 's':
-    strncpy (fn, NewsServer, sizeof (fn) - 1);
+    m_strcpy(fn, sizeof (fn), NewsServer);
     str_tolower (fn);
     snprintf (tmp, sizeof (tmp), "%%%ss", fmt);
     snprintf (dest, destlen, tmp, fn);
@@ -629,7 +630,7 @@ void newsrc_gen_entries (CONTEXT * ctx)
 }
 
 static int mutt_update_list_file (char *filename, char *section,
-                                  char *key, char *line) {
+                                  const char *key, char *line) {
   FILE *ifp;
   FILE *ofp;
   char buf[HUGE_STRING];
@@ -655,8 +656,8 @@ static int mutt_update_list_file (char *filename, char *section,
    * via rename(2); as dirname(2) may modify its argument,
    * temporarily use buf as copy of it
    */
-  strncpy (buf, filename, sizeof (buf));
-  strncpy (tmpfile, basename (filename), sizeof (tmpfile));
+  m_strcpy(buf, sizeof(buf), filename);
+  m_strcpy(tmpfile, sizeof(tmpfile), basename(filename));
   mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile));
   debug_print (1, ("Opening %s\n", tmpfile));
   if (!(ofp = fopen (tmpfile, "w"))) {
@@ -764,7 +765,7 @@ int mutt_newsrc_update (NNTP_SERVER * news)
   }
   /* newrc being fully rewritten */
   if (news->newsrc &&
-      (r = mutt_update_list_file (news->newsrc, NULL, "", buf)) == 0) {
+      (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) {
     struct stat st;
 
     stat (news->newsrc, &st);
@@ -796,8 +797,9 @@ static FILE *mutt_mkname (char *s)
 /* Updates info into .index file: ALL or about selected newsgroup */
 static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data)
 {
-  char buf[LONG_STRING], *key = "ALL";
+  char buf[LONG_STRING];
   char file[_POSIX_PATH_MAX];
+  const char *key = "ALL";
 
   if (!serv || !serv->conn || !serv->conn->account.host)
     return -1;
@@ -1085,7 +1087,7 @@ void nntp_buffy (char* dst, size_t dstlen) {
     NNTP_DATA *data = (NNTP_DATA *) list->data;
     if (data && data->subscribed && data->unread && 
         Context && Context->magic == M_NNTP &&
-        str_cmp (data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
+        m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) {
       list = list->next;
       break;
     }
@@ -1103,7 +1105,7 @@ void nntp_buffy (char* dst, size_t dstlen) {
 
       if (data && data->subscribed && data->unread) {
         if (Context && Context->magic == M_NNTP &&
-            !str_cmp (data->group, ((NNTP_DATA *) Context->data)->group)) {
+            !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) {
           unsigned int i, unread = 0;
 
           for (i = 0; i < Context->msgcount; i++)
@@ -1112,7 +1114,7 @@ void nntp_buffy (char* dst, size_t dstlen) {
           if (!unread)
             continue;
         }
-        strncpy (dst, data->group, dstlen);
+        m_strcpy(dst, dstlen, data->group);
         break;
       }
     }