Replace lots of snprintf's with new function `make_path'.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@4802 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1998-04-23 19:16:07 +00:00
parent 7122973429
commit ebdbe45a50

View File

@@ -40,6 +40,13 @@
#include <dirent.h>
RCSID("$Id$");
static void
make_path(POP *p, MsgInfoList *mp, int new, char *buf, size_t len)
{
snprintf(buf, len, "%s/%s%s%s", p->drop_name,
new ? "new" : "cur", mp ? "/" : "", mp ? "" : mp->name);
}
static int
scan_file(POP *p, MsgInfoList *mp)
{
@@ -48,10 +55,7 @@ scan_file(POP *p, MsgInfoList *mp)
char buf[1024];
int eoh = 0;
snprintf(path, sizeof(path), "%s/%s/%s",
p->drop_name,
(mp->flags & NEW_FLAG) ? "new" : "old",
mp->name);
make_path(p, mp, mp->flags & NEW_FLAG, path, sizeof(path));
f = fopen(path, "r");
if(f == NULL) {
@@ -88,7 +92,7 @@ scan_dir(POP *p, int new)
int n_mp = p->msg_count;
int e;
snprintf(tmp, sizeof(tmp), "%s/%s", p->drop_name, new ? "new" : "old");
make_path(p, NULL, new, tmp, sizeof(tmp));
mkdir(tmp, 0700);
dir = opendir(tmp);
while((dent = readdir(dir)) != NULL) {
@@ -148,9 +152,8 @@ pop_maildir_update(POP *p)
int i;
char tmp1[MAXDROPLEN], tmp2[MAXDROPLEN];
for(i = 0; i < p->msg_count; i++) {
snprintf(tmp1, sizeof(tmp1), "%s/%s/%s", p->drop_name,
(p->mlp[i].flags & NEW_FLAG) ? "new" : "old",
p->mlp[i].name);
make_path(p, &p->mlp[i], p->mlp[i].flags & NEW_FLAG,
tmp1, sizeof(tmp1));
if(p->mlp[i].flags & DEL_FLAG) {
#ifdef DEBUG
if(p->debug)
@@ -166,8 +169,7 @@ pop_maildir_update(POP *p)
}
} else if((p->mlp[i].flags & NEW_FLAG) &&
(p->mlp[i].flags & RETR_FLAG)) {
snprintf(tmp2, sizeof(tmp2), "%s/old/%s", p->drop_name,
p->mlp[i].name);
make_path(p, &p->mlp[i], 0, tmp2, sizeof(tmp2));
#ifdef DEBUG
if(p->debug)
pop_log(p, POP_DEBUG, "Linking `%s' to `%s'", tmp1, tmp2);
@@ -209,8 +211,7 @@ int
pop_maildir_open(POP *p, MsgInfoList *mp)
{
char tmp[MAXDROPLEN];
snprintf(tmp, sizeof(tmp), "%s/%s/%s", p->drop_name,
(mp->flags & NEW_FLAG) ? "new" : "old", mp->name);
make_path(p, mp, mp->flags & NEW_FLAG, tmp, sizeof(tmp);
if(p->drop)
fclose(p->drop);
p->drop = fopen(tmp, "r");