summaryrefslogtreecommitdiffstats
path: root/maildir/maildirgetquota.c
blob: 1c541f815d4713b4317e58e768905b78539c0e7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
** Copyright 1998 - 2000 Double Precision, Inc.
** See COPYING for distribution information.
*/

#include	"maildirgetquota.h"
#include	"maildirmisc.h"
#if	HAVE_UNISTD_H
#include	<unistd.h>
#endif
#include	<stdlib.h>
#include	<string.h>
#include	<fcntl.h>
#include	<sys/types.h>
#include	<sys/stat.h>

int	maildir_getquota(const char *dir, char buf[QUOTABUFSIZE])
{
char	*p;
struct	stat	stat_buf;
int	n;
int	l;

	p=(char *)malloc(strlen(dir)+sizeof("/maildirfolder"));
	if (!p)	return (-1);

	strcat(strcpy(p, dir), "/maildirfolder");
	if (stat(p, &stat_buf) == 0)
	{
		strcat(strcpy(p, dir), "/..");
		n=maildir_getquota(p, buf);
		free(p);
		return (n);
	}

	strcat(strcpy(p, dir), "/maildirsize");
	n=maildir_safeopen(p, O_RDONLY, 0);
	free(p);
	if (n < 0)	return (n);
	if ((l=read(n, buf, QUOTABUFSIZE-1)) < 0)
	{
		close(n);
		return (-1);
	}
	close(n);
	for (n=0; n<l; n++)
		if (buf[n] == '\n')	break;
	buf[n]=0;
	return (0);
}