Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/nslcd-common.h
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2006-11-03 14:46:20 +0100
committerArthur de Jong <arthur@arthurdejong.org>2006-11-03 14:46:20 +0100
commit4dfe010707bb299040170d3dbe3daf0a8cf3268d (patch)
tree78ec64135dedf3089285885f7ba17ce14952a98b /nslcd-common.h
parent52e474972326746f352cec15dc59cf08f2db0347 (diff)
split buffer management macros into separate macros
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/libnss_ldapd@65 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nslcd-common.h')
-rw-r--r--nslcd-common.h41
1 files changed, 26 insertions, 15 deletions
diff --git a/nslcd-common.h b/nslcd-common.h
index 4d3078b..f4ce301 100644
--- a/nslcd-common.h
+++ b/nslcd-common.h
@@ -87,23 +87,35 @@
i=tmpint32; \
DEBUG_PRINT("READ_INT32(%d)\n",(int)i);
+/* current position in the buffer */
+#define BUF_CUR \
+ (buffer+bufptr)
+
+/* check that the buffer has sz bytes left in it */
+#define BUF_CHECK(fp,sz) \
+ if ((bufptr+(size_t)(sz))>buflen) \
+ { ERROR_OUT_BUFERROR(fp) } /* will not fit */ \
+
+/* move the buffer pointer */
+#define BUF_SKIP(sz) \
+ bufptr+=(size_t)tmpint32+1;
+
/* read string in the buffer (using buffer, buflen and bufptr)
and store the actual location of the string in field */
#define READ_STRING_BUF(fp,field) \
/* read the size of the string */ \
READ_TYPE(fp,tmpint32,int32_t); \
/* check if read would fit */ \
- if ((bufptr+(size_t)tmpint32+1)>buflen) \
- { ERROR_OUT_BUFERROR(fp) } /* will not fit */ \
+ BUF_CHECK(fp,tmpint32+1); \
/* read string from the stream */ \
if (tmpint32>0) \
- { READ(fp,buffer+bufptr,(size_t)tmpint32); } \
+ { READ(fp,BUF_CUR,(size_t)tmpint32); } \
/* null-terminate string in buffer */ \
- buffer[bufptr+tmpint32]='\0'; \
- DEBUG_PRINT("READ_STRING_BUF(\"%s\"=%d)\n",buffer+bufptr,strlen(buffer+bufptr)); \
+ BUF_CUR[tmpint32]='\0'; \
+ DEBUG_PRINT("READ_STRING_BUF(\"%s\"=%d)\n",BUF_CUR,strlen(BUF_CUR)); \
/* prepare result */ \
- (field)=buffer+bufptr; \
- bufptr+=(size_t)tmpint32+1;
+ (field)=BUF_CUR; \
+ BUF_SKIP(tmpint32+1);
/* read a string from the stream dynamically allocating memory
for the string (don't forget to call free() later on) */
@@ -117,7 +129,7 @@
/* read string from the stream */ \
if (tmpint32>0) \
{ READ(fp,name,(size_t)tmpint32); } \
- /* null-terminate string in buffer */ \
+ /* null-terminate string */ \
(name)[tmpint32]='\0'; \
DEBUG_PRINT("READ_STRING(\"%s\"=%d)\n",(name),strlen(name));
@@ -128,10 +140,9 @@
(num)=tmpint32; \
/* allocate room for *char[num] */ \
tmpint32*=sizeof(char *); \
- if ((bufptr+(size_t)tmpint32)>buflen) \
- { ERROR_OUT_BUFERROR(fp) } /* will not fit */ \
- (arr)=(char **)(buffer+bufptr); \
- bufptr+=(size_t)tmpint32; \
+ BUF_CHECK(fp,tmpint32); \
+ (arr)=(char **)BUF_CUR; \
+ BUF_SKIP(tmpint32); \
for (tmp2int32=0;tmp2int32<(num);tmp2int32++) \
{ \
READ_STRING_BUF(fp,(arr)[tmp2int32]); \
@@ -143,9 +154,9 @@
READ_TYPE(fp,tmpint32,int32_t); \
/* allocate room for *char[num+1] */ \
tmp2int32=(tmpint32+1)*sizeof(char *); \
- if ((bufptr+(size_t)tmp2int32)>buflen) \
- { ERROR_OUT_BUFERROR(fp) } /* will not fit */ \
- (arr)=(char **)(buffer+bufptr); \
+ BUF_CHECK(fp,tmp2int32); \
+ (arr)=(char **)BUF_CUR; \
+ BUF_SKIP(tmpint32); \
/* read all entries */ \
bufptr+=(size_t)tmpint32; \
for (tmp2int32=0;tmp2int32<tmpint32;tmp2int32++) \