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