1 /* $NetBSD: mail_scan_dir.c,v 1.1.1.1 2009/06/23 10:08:47 tron Exp $ */ 2 3 /*++ 4 /* NAME 5 /* mail_scan_dir 3 6 /* SUMMARY 7 /* mail queue directory scanning support 8 /* SYNOPSIS 9 /* #include <mail_scan_dir.h> 10 /* 11 /* char *mail_scan_dir_next(scan) 12 /* SCAN_DIR *scan; 13 /* DESCRIPTION 14 /* The \fBmail_scan_dir_next\fR() routine is a wrapper around 15 /* scan_dir_next() that understands the structure of a Postfix 16 /* mail queue. The result is a queue ID or a null pointer. 17 /* SEE ALSO 18 /* scan_dir(3) directory scanner 19 /* LICENSE 20 /* .ad 21 /* .fi 22 /* The Secure Mailer license must be distributed with this software. 23 /* AUTHOR(S) 24 /* Wietse Venema 25 /* IBM T.J. Watson Research 26 /* P.O. Box 704 27 /* Yorktown Heights, NY 10598, USA 28 /*--*/ 29 30 /* System library. */ 31 32 #include <sys_defs.h> 33 #include <string.h> 34 35 /* Utility library. */ 36 37 #include <scan_dir.h> 38 39 /* Global library. */ 40 41 #include <mail_scan_dir.h> 42 43 /* mail_scan_dir_next - return next queue file */ 44 45 char *mail_scan_dir_next(SCAN_DIR *scan) 46 { 47 char *name; 48 49 /* 50 * Exploit the fact that mail queue subdirectories have one-letter names, 51 * so we don't have to stat() every file in sight. This is a win because 52 * many dirent implementations do not return file type information. 53 */ 54 for (;;) { 55 if ((name = scan_dir_next(scan)) == 0) { 56 if (scan_dir_pop(scan) == 0) 57 return (0); 58 } else if (strlen(name) == 1) { 59 scan_dir_push(scan, name); 60 } else { 61 return (name); 62 } 63 } 64 } 65