X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;ds=sidebyside;f=sbr%2Ffolder_read.c;h=f642ed39b02f24213088964ec64ee776022e9b91;hb=e87123959d15f3b190494dffdd8bce335c137874;hp=0d0129320158fcf21c808c466bb7c79a0fa8bc74;hpb=1691e80890e5d8ba258c51c214a3e91880e1db2b;p=mmh diff --git a/sbr/folder_read.c b/sbr/folder_read.c index 0d01293..f642ed3 100644 --- a/sbr/folder_read.c +++ b/sbr/folder_read.c @@ -2,10 +2,13 @@ /* * folder_read.c -- initialize folder structure and read folder * - * $Id$ + * This code is Copyright (c) 2002, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. */ #include +#include /* We allocate the `mi' array 1024 elements at a time */ #define NUMMSGS 1024 @@ -40,8 +43,7 @@ folder_read (char *name) } /* Allocate the main structure for folder information */ - if (!(mp = (struct msgs *) malloc ((size_t) sizeof(*mp)))) - adios (NULL, "unable to allocate folder storage"); + mp = (struct msgs *) mh_xmalloc ((size_t) sizeof(*mp)); clear_folder_flags (mp); mp->foldpath = name; @@ -53,30 +55,26 @@ folder_read (char *name) mp->numsel = 0; mp->nummsg = 0; - if (access (name, W_OK) == -1 || st.st_uid != getuid()) + if (access (name, W_OK) == -1) set_readonly (mp); - prefix_len = strlen(BACKUP_PREFIX); + prefix_len = strlen(backup_prefix); /* * Allocate a temporary place to record the * name of the messages in this folder. */ len = NUMMSGS; - if (!(mi = (int *) malloc ((size_t) (len * sizeof(*mi))))) - adios (NULL, "unable to allocate storage"); + mi = (int *) mh_xmalloc ((size_t) (len * sizeof(*mi))); while ((dp = readdir (dd))) { - if ((msgnum = m_atoi (dp->d_name))) { + if ((msgnum = m_atoi (dp->d_name)) && msgnum > 0) { /* * Check if we need to allocate more * temporary elements for message names. */ if (mp->nummsg >= len) { len += NUMMSGS; - if (!(mi = (int *) realloc (mi, - (size_t) (len * sizeof(*mi))))) { - adios (NULL, "unable to allocate storage"); - } + mi = (int *) mh_xrealloc (mi, (size_t) (len * sizeof(*mi))); } /* Check if this is the first message we've seen */ @@ -108,11 +106,11 @@ folder_read (char *name) default: /* skip any files beginning with backup prefix */ - if (!strncmp (dp->d_name, BACKUP_PREFIX, prefix_len)) + if (!strncmp (dp->d_name, backup_prefix, prefix_len)) continue; - /* skip the LINK file */ - if (!strcmp (dp->d_name, LINK)) + /* skip the altmsg link file */ + if (!strcmp (dp->d_name, altmsglink)) continue; /* indicate that there are other files in folder */ @@ -134,8 +132,7 @@ folder_read (char *name) /* * Allocate space for status of each message. */ - if (!(mp->msgstats = malloc (MSGSTATSIZE(mp, mp->lowoff, mp->hghoff)))) - adios (NULL, "unable to allocate storage for msgstats"); + mp->msgstats = mh_xmalloc (MSGSTATSIZE(mp, mp->lowoff, mp->hghoff)); /* * Clear all the flag bits for all the message