/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223/*24* return the length of the current record at b, size n, according to f25* -1 returned on error26* 0 returned if more data is required27*/2829#include <recfmt.h>30#include <ctype.h>3132ssize_t33reclen(Recfmt_t f, const void* b, size_t n)34{35register unsigned char* s = (unsigned char*)b;36register unsigned char* e;37size_t h;38size_t z;3940switch (RECTYPE(f))41{42case REC_delimited:43if (e = (unsigned char*)memchr(s, REC_D_DELIMITER(f), n))44return e - s + 1;45return 0;46case REC_fixed:47return REC_F_SIZE(f);48case REC_variable:49h = REC_V_HEADER(f);50if (n < h)51return 0;52z = 0;53s += REC_V_OFFSET(f);54e = s + REC_V_LENGTH(f);55if (REC_V_LITTLE(f))56while (e > s)57z = (z<<8)|*--e;58else59while (s < e)60z = (z<<8)|*s++;61if (!REC_V_INCLUSIVE(f))62z += h;63else if (z < h)64z = h;65return z;66case REC_method:67return -1;68}69return -1;70}717273