This file is indexed.

/usr/share/doc/libsnacc-dev/examples/c-examples/simple/expbuf-ex.c is in libsnacc-dev 1.3.1-5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
 * c_examples/simple/expbuf_ex.c - an example of how to call C ASN.1-BER
 *              encoders and decoders generated by snacc
 *              with the ExpBuf buffer.
 *
 * AUTHOR: Mike Sample
 * DATE:   Mar 92
 *
 * $Header: /usr/app/odstb/CVS/snacc/c-examples/simple/expbuf-ex.c,v 1.5 1995/07/24 20:44:58 rj Exp $
 * $Log: expbuf-ex.c,v $
 * Revision 1.5  1995/07/24 20:44:58  rj
 * changed `_' to `-' in file names.
 *
 * Revision 1.4  1995/02/18  15:12:53  rj
 * cosmetic changes
 *
 * Revision 1.3  1994/08/31  23:48:29  rj
 * more portable .h file inclusion.
 *
 * Revision 1.2  1994/08/31  08:59:34  rj
 * first check-in. for a list of changes to the snacc-1.1 distribution please refer to the ChangeLog.
 *
 */

#include "asn-incl.h"

#include <sys/file.h>
#include <sys/stat.h>
#if HAVE_FCNTL_H 
#include <fcntl.h>
#endif
#include <stdio.h>

#include "p-rec.h"


main PARAMS ((argc, argv),
    int argc _AND_
    char *argv[])
{
    int fd;
    ExpBuf *buf;
    ExpBuf  b;
    ExpBuf *tmpBuf;
    AsnLen encodedLen;
    AsnLen decodedLen;
    int     val;
    PersonnelRecord pr;
    int      size;
    char    *origData;
    struct stat sbuf;
    jmp_buf env;
    int  decodeErr;
    AsnTag tag;


    if (argc != 2)
    {
        fprintf (stderr, "Usage: %s <BER data file name>\n", argv[0]);
        fprintf (stderr, "   Decodes the given PersonnelRecord BER data file\n");
        fprintf (stderr, "   and re-encodes it to stdout\n");
        exit (1);
    }

    fd = open (argv[1], O_RDONLY, 0);
    if (fd < 0)
    {
        perror ("main: fopen");
        exit (1);
    }

    if (fstat (fd, &sbuf) < 0)
    {
        perror ("main: fstat");
        exit (1);
    }

    size = sbuf.st_size;
    origData = (char*)malloc (size);
    if (read (fd, origData, size) != size)
    {
        perror ("main: read");
        exit (1);
    }

    close (fd);

    /*
     * the "1024" is the size in bytes of the data
     * blk to allocate when writing to a buffer that
     * fills up.
     */
    ExpBufInit (1024);

    /*
     * the first argument (512) is the number of bytes to
     * initially allocate for the decoder to allocate from.
     * The second argument (512) is the size in bytes to
     * enlarge the nibble memory by when it fills up
     */
    InitNibbleMem (512, 512);

    /*
     * put the BER data read from the file
     * into buffer format, ready for reading from the
     * beginning
     */
    buf = &b;
    ExpBufInstallDataInBuf (buf, origData, size);

    decodedLen = 0;
    decodeErr = FALSE;
    if ((val = setjmp (env)) == 0)
    {
        BDecPersonnelRecord (&buf, &pr, &decodedLen, env);
    }
    else
    {
        decodeErr = TRUE;
        fprintf (stderr, "ERROR - Decode routines returned %d\n",val);
    }

    if (decodeErr)
        exit (1);

    fprintf (stderr, "decodedValue PersonnelRecord ::= ");
    PrintPersonnelRecord (stderr, &pr, 0);
    fprintf (stderr, "\n\n");

    /*
     * allocate a new buffer set up for writing to
     */
    buf = ExpBufAllocBufAndData();

    encodedLen =  BEncPersonnelRecord (&buf, &pr);

    /*
     * Alway check for a buffer write error after encoding
     */
    if (ExpBufWriteError (&buf))
    {
        fprintf (stderr, "ERROR - buffer write error during encoding\n");
        exit (1);
    }


    /*
     * free all of the decoded value since
     * it has been encoded into the buffer.
     * This is much more efficient than freeing
     * each compontent of the value individually
     */
    ResetNibbleMem();

    /*
     * go through buffer (s) and write encoded value
     * to stdout
     */
    buf->curr = buf->dataStart;
    for ( tmpBuf = buf; tmpBuf != NULL; tmpBuf = tmpBuf->next)
    {
        fwrite (tmpBuf->dataStart, tmpBuf->dataEnd - tmpBuf->dataStart, 1, stdout);
    }

    return 0;
}