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