Back to index

courier  0.68.2
mybuf.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 2000 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #ifndef       mybuf_h
00007 #define       mybuf_h
00008 
00009 
00010 /**************************************************************************/
00011 /*            A quick buffered I/O reader                           */
00012 /**************************************************************************/
00013 
00014 #ifndef       MYBUF_SIZE
00015 #define       MYBUF_SIZE    512
00016 #endif
00017 
00018 struct mybuf {
00019        char buffer[MYBUF_SIZE];
00020        int fd;
00021        char *readptr;
00022        int readleft;
00023        } ;
00024 
00025 #define       mybuf_init(p, f)     ((p)->fd=(f), (p)->readleft=0)
00026 
00027 #ifndef       mybuf_readfunc
00028 #define       mybuf_readfunc       read
00029 #endif
00030 
00031 #define       mybuf_get(p)  (  (p)->readleft <= 0 && \
00032               ((p)->readptr=(p)->buffer, \
00033                      (p)->readleft=mybuf_readfunc((p)->fd, (p)->buffer, \
00034                             sizeof((p)->buffer))) <= 0 ? -1: \
00035               (--(p)->readleft, (int)(unsigned char)*(p)->readptr++))
00036 
00037 #define       mybuf_more(q) (!!(q)->readleft)
00038 
00039 /* The following must be lvalues */
00040 
00041 #define       mybuf_ptr(p)         ( (p)->readptr )
00042 #define       mybuf_ptrleft(p)     ( (p)->readleft )
00043 
00044 #endif