This file is indexed.

/usr/include/wvstreams/wvbufstore.h is in libwvstreams-dev 4.6.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
/* -*- Mode: C++ -*-
 * Worldvisions Weaver Software:
 *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
 *
 * Defines basic buffer storage classes.
 * These are not intended for use directly by clients.
 * See "wvbufbase.h" for the public API.
 */
#ifndef __WVBUFFERSTORE_H
#define __WVBUFFERSTORE_H

#include "wvlinklist.h"
#include <assert.h>
#include <limits.h>
#include <assert.h>

/**
 * This value is used internally to signal unlimited free space.
 * It is merely meant to be as large as possible yet leave enough
 * room to accomodate simple arithmetic operations without overflow.
 * Clients should NOT check for the presence of this value explicitly.
 */
#define UNLIMITED_FREE_SPACE (INT_MAX/2)

/** The abstract buffer storage base class. */
class WvBufStore
{
    // discourage copying
    explicit WvBufStore(const WvBufStore &other) { }

protected:
    // the suggested granularity
    int granularity;

    /**
     * Creates a new buffer.
     * "_granularity" is the suggested granularity for data allocation
     *        and alignment purposes
     */
    explicit WvBufStore(int _granularity);
    
public:
    virtual ~WvBufStore() { }

    /*** Buffer Reading ***/
    
    virtual bool isreadable() const
        { return true; }
    virtual size_t used() const = 0;
    virtual size_t optgettable() const
        { return used(); }
    virtual const void *get(size_t count) = 0;
    virtual void skip(size_t count)
        { get(count); }
    virtual void unget(size_t count) = 0;
    virtual size_t ungettable() const = 0;
    virtual size_t peekable(int offset) const;
    virtual size_t optpeekable(int offset) const
        { return peekable(offset); }
    virtual const void *peek(int offset, size_t count)
        { return mutablepeek(offset, count); }
    virtual void zap() = 0;
    
    // helpers
    void move(void *buf, size_t count);
    void copy(void *buf, int offset, size_t count);
    
    /*** Buffer Writing ***/
    
    virtual bool iswritable() const
        { return true; }
    virtual size_t free() const = 0;
    virtual size_t optallocable() const
        { return free(); }
    virtual void *alloc(size_t count) = 0;
    virtual void unalloc(size_t count) = 0;
    virtual size_t unallocable() const = 0;
    virtual void *mutablepeek(int offset, size_t count) = 0;
    
    // helpers
    void put(const void *data, size_t count);
    void fastput(const void *data, size_t count);
    void poke(const void *data, int offset, size_t count);

    /*** Buffer to Buffer Transfers ***/

    virtual void merge(WvBufStore &instore, size_t count);

    // default implementation
    void basicmerge(WvBufStore &instore, size_t count);

protected:
    /*** Support for buffers with subbuffers ***/

    /** Returns true if the buffer uses subbuffers for storage. */
    virtual bool usessubbuffers() const
        { return false; }

    /** Returns the number of subbuffers in the buffer. */
    virtual size_t numsubbuffers() const
        { return 0; }

    /**
     * Returns the first subbuffer.
     * Returns: the buffer or NULL if none or not supported
     */
    virtual WvBufStore *firstsubbuffer() const
        { return NULL; }

    /** Appends a subbuffer to the buffer. */
    virtual void appendsubbuffer(WvBufStore *buffer, bool autofree)
        { /*assert(! "not supported");*/ }

    /** Prepends a subbuffer to the buffer. */
    virtual void prependsubbuffer(WvBufStore *buffer, bool autofree)
        { /*assert(! "not supported");*/ }

    /**
     * Unlinks the specified subbuffer.
     * Only autofrees the buffer if allowautofree == true.
     * Returns: the autofree flag for the buffer
     */
    virtual bool unlinksubbuffer(WvBufStore *buffer,
        bool allowautofree)
        { /*assert(! "not supported");*/ return true; }
};

// lists of buffer stores are sometimes useful
DeclareWvList(WvBufStore);



/**
 * A statically bound mixin template for buffer implementations that are
 * read-only.  It is an error to attempt to write to a read-only buffer.
 * Note that read-only in this context does not mean the same as "const".
 */
template<class Super>
class WvReadOnlyBufferStoreMixin : public Super
{
public:
    explicit WvReadOnlyBufferStoreMixin(int _granularity) :
        Super(_granularity) { }
    virtual bool iswritable() const
    {
        return false;
    }
    virtual size_t free() const
    {
        return 0;
    }
    virtual size_t optallocable() const
    {
        return 0;
    }
    virtual void *alloc(size_t count)
    {
        assert(count == 0 ||
            ! "non-zero alloc() called on non-writable buffer");
        return NULL;
    }
    virtual void unalloc(size_t count)
    {
        assert(count == 0 ||
            ! "non-zero unalloc() called on non-writable buffer");
    }
    virtual size_t unallocable() const
    {
        return 0;
    }
    virtual void *mutablepeek(int offset, size_t count)
    {
        assert(count == 0 ||
            ! "mutablepeek() called on non-writable buffer");
        return NULL;
    }
    virtual void merge(WvBufStore &instore, size_t count)
    {
        assert(count == 0 ||
            ! "non-zero merge() called on non-writable buffer");
    }
};



/**
 * A statically bound mixin template for buffer implementations that are
 * write-only.  It is an error to attempt to read from a write-only buffer.
 */
template<class Super>
class WvWriteOnlyBufferStoreMixin : public Super
{
public:
    explicit WvWriteOnlyBufferStoreMixin(int _granularity) :
        Super(_granularity) { }
    virtual bool isreadable() const
    {
        return false;
    }
    virtual size_t used() const
    {
        return 0;
    }
    virtual size_t optgettable() const
    {
        return 0;
    }
    virtual size_t peekable(int offset) const
    {
        return 0;
    }
    virtual size_t optpeekable(int offset) const
    {
        return 0;
    }
    virtual const void *get(size_t count)
    {
        assert(count == 0 ||
            ! "non-zero get() called on non-readable buffer");
        return NULL;
    }
    virtual void skip(size_t count)
    {
        assert(count == 0 ||
            ! "non-zero skip() called on non-readable buffer");
    }
    virtual void unget(size_t count)
    {
        assert(count == 0 ||
            ! "non-zero unget() called on non-readable buffer");
    }
    virtual size_t ungettable() const
    {
        return 0;
    }
    virtual const void *peek(int offset, size_t count)
    {
        assert(count == 0 ||
            ! "peek() called on non-readable buffer");
        return NULL;
    }
    virtual void zap()
    {
        // nothing to zap
    }
};



/** The WvInPlaceBuf storage class. */
class WvInPlaceBufStore : public WvBufStore
{
protected:
    void *data;
    size_t xsize;
    size_t readidx;
    size_t writeidx;
    bool xautofree;

public:
    WvInPlaceBufStore(int _granularity,
        void *_data, size_t _avail, size_t _size, bool _autofree);
    WvInPlaceBufStore(int _granularity, size_t _size);
    virtual ~WvInPlaceBufStore();
    void *ptr() const
        { return data; }
    size_t size() const
        { return xsize; }
    bool get_autofree() const
        { return xautofree; }
    void set_autofree(bool _autofree)
        { xautofree = _autofree; }
    void reset(void *_data, size_t _avail, size_t _size, bool _autofree);
    void setavail(size_t _avail);
    
    /*** Overridden Members ***/
    virtual size_t used() const;
    virtual const void *get(size_t count);
    virtual void unget(size_t count);
    virtual size_t ungettable() const;
    virtual void zap();
    virtual size_t free() const;
    virtual void *alloc(size_t count);
    virtual void unalloc(size_t count);
    virtual size_t unallocable() const;
    virtual void *mutablepeek(int offset, size_t count);
};



/** The WvConstInPlaceBuf storage class. */
class WvConstInPlaceBufStore :
    public WvReadOnlyBufferStoreMixin<WvBufStore>
{
protected:
    const void *data;
    size_t avail;
    size_t readidx;

public:
    WvConstInPlaceBufStore(int _granularity,
        const void *_data, size_t _avail);
    const void *ptr() const
        { return data; }
    void reset(const void *_data, size_t _avail);
    void setavail(size_t _avail);

    /*** Overridden Members ***/
    virtual size_t used() const;
    virtual const void *get(size_t count);
    virtual void unget(size_t count);
    virtual size_t ungettable() const;
    virtual const void *peek(int offset, size_t count);
    virtual void zap();
};



/** The WvCircularBuf storage class. */
class WvCircularBufStore : public WvBufStore
{
protected:
    void *data;
    size_t xsize;
    size_t head;
    size_t totalused;
    size_t totalinit;
    bool xautofree;

public:
    WvCircularBufStore(int _granularity,
        void *_data, size_t _avail, size_t _size, bool _autofree);
    WvCircularBufStore(int _granularity, size_t _size);
    virtual ~WvCircularBufStore();
    void *ptr() const
        { return data; }
    size_t size() const
        { return xsize; }
    bool get_autofree() const
        { return xautofree; }
    void set_autofree(bool _autofree)
        { xautofree = _autofree; }
    void reset(void *_data, size_t _avail, size_t _size, bool _autofree);
    void setavail(size_t _avail);
    void normalize();
    
    /*** Overridden Members ***/
    virtual size_t used() const;
    virtual size_t optgettable() const;
    virtual const void *get(size_t count);
    virtual void unget(size_t count);
    virtual size_t ungettable() const;
    virtual void zap();
    virtual size_t free() const;
    virtual size_t optallocable() const;
    virtual void *alloc(size_t count);
    virtual void unalloc(size_t count);
    virtual size_t unallocable() const;
    virtual void *mutablepeek(int offset, size_t count);

protected:
    /**
     * Ensures that count new bytes can be read from or written
     * to the buffer beginning at the specified offset as one
     * large contiguous block.
     *
     * "offset" is the offset
     * "count" is the number of bytes
     * "keephistory" is if true, does not purge unget history
     * Returns: the offset of the first available byte
     */
    size_t ensurecontiguous(int offset, size_t count, bool keephistory);

    /**
     * Compacts an array arranged as a circular buffer such that
     * the specified region is moved to the beginning of the array.
     *
     * "data" is the array base
     * "size" is the size of the array
     * "head" is the beginning of the region to keep
     * "count" is the number of bytes in the region to keep
     */
    static void compact(void *data, size_t size,
        size_t head, size_t count);
};



/**
 * The WvLinkedBuffer storage class.
 * 
 * A buffer store built out of a list of other buffers linked together.
 * Buffers may be appended or prepended to the list at any time, at
 * which point they act as slaves for the master buffer.  Slaves may
 * be expunged from the list at any time when the master buffer
 * determines that they are of no further use.
 * 
 * This is mostly useful for building other buffer storage classes.
 * 
 */
class WvLinkedBufferStore : public WvBufStore
{
protected:
    WvBufStoreList list;
    size_t totalused;
    size_t maxungettable;

public:
    explicit WvLinkedBufferStore(int _granularity);

    /*** Overridden Members ***/
    virtual size_t used() const;
    virtual size_t optgettable() const;
    virtual const void *get(size_t count);
    virtual void unget(size_t count);
    virtual size_t ungettable() const;
    virtual void zap();
    virtual size_t free() const;
    virtual size_t optallocable() const;
    virtual void *alloc(size_t count);
    virtual void unalloc(size_t count);
    virtual size_t unallocable() const;
    virtual size_t optpeekable(int offset) const;
    virtual void *mutablepeek(int offset, size_t count);

protected:
    virtual bool usessubbuffers() const;
    virtual size_t numsubbuffers() const;
    virtual WvBufStore *firstsubbuffer() const;
    virtual void appendsubbuffer(WvBufStore *buffer, bool autofree);
    virtual void prependsubbuffer(WvBufStore *buffer, bool autofree);
    virtual bool unlinksubbuffer(WvBufStore *buffer,
        bool allowautofree);

protected:
    /**
     * Called when a new buffer must be allocated to coalesce chunks.
     *
     * "minsize" is the minimum size for the new buffer
     * Returns: the new buffer
     */
    virtual WvBufStore *newbuffer(size_t minsize);

    /**
     * Called when a buffer with autofree is removed from the list.
     * This function is not called during object destruction.
     *
     * "buffer" is the buffer to be destroyed
     */
    virtual void recyclebuffer(WvBufStore *buffer);

    /**
     * Searches for the buffer containing the offset.
     * 
     * "it" is the iterator updated to point to buffer found,
     *        or to an invalid region if the offset is invalid
     * "offset" is the offset for which to search
     * Returns: the corrected offset within the buffer at it.ptr()
     */
    int search(WvBufStoreList::Iter &it, int offset) const;

    /**
     * Coalesces a sequence of buffers.
     *
     * "it" is the iterator pointing to the first buffer
     * "count" is the required number of contiguous used bytes
     * Returns: the composite buffer
     */
    WvBufStore *coalesce(WvBufStoreList::Iter &it,
        size_t count);

private:
    // unlinks and recycles the buffer pointed at by the iterator
    void do_xunlink(WvBufStoreList::Iter &it);
};



/** The WvDynBuf storage class. */
class WvDynBufStore : public WvLinkedBufferStore
{
    size_t minalloc;
    size_t maxalloc;
    
public:
    WvDynBufStore(size_t _granularity,
        size_t _minalloc, size_t _maxalloc);

    /*** Overridden Members ***/
    virtual size_t free() const;
    virtual size_t optallocable() const;
    virtual void *alloc(size_t count);

protected:
    virtual WvBufStore *newbuffer(size_t minsize);
};



/** The WvNullBuf storage class. */
class WvNullBufStore : public WvWriteOnlyBufferStoreMixin<
    WvReadOnlyBufferStoreMixin<WvBufStore> >
{
public:
    explicit WvNullBufStore(size_t _granularity);
};



/** The WvBufCursor storage class. */
class WvBufCursorStore :
    public WvReadOnlyBufferStoreMixin<WvBufStore>
{
protected:
    WvBufStore *buf;
    int start;
    size_t length;
    size_t shift;

public:
    WvBufCursorStore(size_t _granularity, WvBufStore *_buf,
        int _start, size_t _length);

    /*** Overridden Members ***/
    virtual bool isreadable() const;
    virtual size_t used() const;
    virtual size_t optgettable() const;
    virtual const void *get(size_t count);
    virtual void skip(size_t count);
    virtual void unget(size_t count);
    virtual size_t ungettable() const;
    virtual size_t peekable(int offset) const;
    virtual size_t optpeekable(int offset) const;
    virtual const void *peek(int offset, size_t count);
    virtual void zap();
    virtual bool iswritable() const;
    virtual void *mutablepeek(int offset, size_t count);
};

#endif // __WVBUFFERSTORE_H