5557bb2813fb31fa14c3ce152043af451eb64113
[yaz-moved-to-github.git] / src / waislen.c
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) 1995-2008 Index Data
3  * See the file LICENSE for details.
4  */
5 /**
6  * \file waislen.c
7  * \brief Implements WAIS package handling
8  */
9
10 #include <stdio.h>
11 #include <yaz/comstack.h>
12 /*
13  * Return length of WAIS package or 0
14  */
15 int completeWAIS(const char *buf, int len)
16 {
17     int i, lval = 0;
18
19     if (len < 25)
20         return 0;
21     if (*buf != '0')
22         return 0;
23     /* calculate length */
24     for (i = 0; i < 10; i++)
25         lval = lval * 10 + (buf[i] - '0');
26     lval += 25;
27     if (len >= lval)
28         return lval;
29     return 0;
30 }
31 /*
32  * Local variables:
33  * c-basic-offset: 4
34  * indent-tabs-mode: nil
35  * End:
36  * vim: shiftwidth=4 tabstop=8 expandtab
37  */
38