bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2002-2018 Dovecot authors, see the included COPYING file */
538303a216166f3526c0ae9658c9978275cfa100Timo Sirainen /* use secs + usecs to guarantee uniqueness within this process. */
7ef3553585e556f35d5919589cfdc1de3329e4bbTimo Sirainen if (timeval_cmp(&ioloop_timeval, &last_tv) > 0)
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainenbool maildir_filename_get_size(const char *fname, char type, uoff_t *size_r)
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen if (*fname == ',' && fname[1] == type && fname[2] == '=') {
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen/* a char* hash function from ASU -- from glib */
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainenunsigned int maildir_filename_base_hash(const char *s)
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen unsigned int g, h = 0;
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen while (*s != MAILDIR_INFO_SEP && *s != '\0') {
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen h = (h << 4) + *s;
23bdbb7b1831785c6ba6df190f6369da882d2b9dTimo Sirainen if ((g = h & 0xf0000000UL) != 0) {
e8bdf1be00aec45d0c6dd72ad9c8be02a3dfc778Timo Sirainen h = h ^ (g >> 24);
678d0463849ba777106eb7875f27db07a5d8e3dfTimo Sirainenint maildir_filename_base_cmp(const char *fname1, const char *fname2)
eac60b7aef3924a611656b184412be1e80b2ed5bTimo Sirainen while (*fname1 == *fname2 && *fname1 != MAILDIR_INFO_SEP &&
eac60b7aef3924a611656b184412be1e80b2ed5bTimo Sirainen if ((*fname1 == '\0' || *fname1 == MAILDIR_INFO_SEP) &&
eac60b7aef3924a611656b184412be1e80b2ed5bTimo Sirainen (*fname2 == '\0' || *fname2 == MAILDIR_INFO_SEP))
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainenstatic bool maildir_fname_get_usecs(const char *fname, int *usecs_r)
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainen /* Assume we already read the timestamp. Next up is
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainen ".<uniqueness>.<host>". Find usecs inside the uniqueness. */
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainen while (*fname != '\0' && *fname != '.' && *fname != MAILDIR_INFO_SEP) {
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainenint maildir_filename_sort_cmp(const char *fname1, const char *fname2)
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainen /* sort primarily by the timestamp in file name */
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainen for (s1 = fname1; *s1 >= '0' && *s1 <= '9'; s1++)
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainen for (s2 = fname2; *s2 >= '0' && *s2 <= '9'; s2++)
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainen /* sort secondarily by microseconds, if they exist */
65d89650662f7f1681a3431c585bfc9721a85149Timo Sirainen /* fallback to comparing the base file name */