summaryrefslogtreecommitdiffstats
path: root/maildirgetquota.c
diff options
context:
space:
mode:
Diffstat (limited to 'maildirgetquota.c')
-rw-r--r--maildirgetquota.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/maildirgetquota.c b/maildirgetquota.c
new file mode 100644
index 0000000..1c541f8
--- /dev/null
+++ b/maildirgetquota.c
@@ -0,0 +1,50 @@
1/*
2** Copyright 1998 - 2000 Double Precision, Inc.
3** See COPYING for distribution information.
4*/
5
6#include "maildirgetquota.h"
7#include "maildirmisc.h"
8#if HAVE_UNISTD_H
9#include <unistd.h>
10#endif
11#include <stdlib.h>
12#include <string.h>
13#include <fcntl.h>
14#include <sys/types.h>
15#include <sys/stat.h>
16
17int maildir_getquota(const char *dir, char buf[QUOTABUFSIZE])
18{
19char *p;
20struct stat stat_buf;
21int n;
22int l;
23
24 p=(char *)malloc(strlen(dir)+sizeof("/maildirfolder"));
25 if (!p) return (-1);
26
27 strcat(strcpy(p, dir), "/maildirfolder");
28 if (stat(p, &stat_buf) == 0)
29 {
30 strcat(strcpy(p, dir), "/..");
31 n=maildir_getquota(p, buf);
32 free(p);
33 return (n);
34 }
35
36 strcat(strcpy(p, dir), "/maildirsize");
37 n=maildir_safeopen(p, O_RDONLY, 0);
38 free(p);
39 if (n < 0) return (n);
40 if ((l=read(n, buf, QUOTABUFSIZE-1)) < 0)
41 {
42 close(n);
43 return (-1);
44 }
45 close(n);
46 for (n=0; n<l; n++)
47 if (buf[n] == '\n') break;
48 buf[n]=0;
49 return (0);
50}