Back to index

courier  0.68.2
maildirgetquota.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2000 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #include      "maildirgetquota.h"
00007 #include      "maildirmisc.h"
00008 #if    HAVE_UNISTD_H
00009 #include      <unistd.h>
00010 #endif
00011 #include      <stdlib.h>
00012 #include      <string.h>
00013 #include      <fcntl.h>
00014 #include      <sys/types.h>
00015 #include      <sys/stat.h>
00016 
00017 int    maildir_getquota(const char *dir, char buf[QUOTABUFSIZE])
00018 {
00019 char   *p;
00020 struct stat   stat_buf;
00021 int    n;
00022 int    l;
00023 
00024        p=(char *)malloc(strlen(dir)+sizeof("/maildirfolder"));
00025        if (!p)       return (-1);
00026 
00027        strcat(strcpy(p, dir), "/maildirfolder");
00028        if (stat(p, &stat_buf) == 0)
00029        {
00030               strcat(strcpy(p, dir), "/..");
00031               n=maildir_getquota(p, buf);
00032               free(p);
00033               return (n);
00034        }
00035 
00036        strcat(strcpy(p, dir), "/maildirsize");
00037        n=maildir_safeopen(p, O_RDONLY, 0);
00038        free(p);
00039        if (n < 0)    return (n);
00040        if ((l=read(n, buf, QUOTABUFSIZE-1)) < 0)
00041        {
00042               close(n);
00043               return (-1);
00044        }
00045        close(n);
00046        for (n=0; n<l; n++)
00047               if (buf[n] == '\n')  break;
00048        buf[n]=0;
00049        return (0);
00050 }