summaryrefslogtreecommitdiff
path: root/exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h
diff options
context:
space:
mode:
authorRoot THC2026-02-24 12:42:47 +0000
committerRoot THC2026-02-24 12:42:47 +0000
commitc9cbeced5b3f2bdd7407e29c0811e65954132540 (patch)
treeaefc355416b561111819de159ccbd86c3004cf88 /exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h
parent073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff)
initial
Diffstat (limited to 'exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h')
-rw-r--r--exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h
new file mode 100644
index 0000000..56f1123
--- /dev/null
+++ b/exploits/7350855-netkit/netkit-telnet-0.16/telnet/array.h
@@ -0,0 +1,97 @@
1//
2// File: array.h
3// Date: 16-Jul-95
4// Description: array template
5//
6/*
7 * Copyright (c) 1995 David A. Holland.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the Author nor the names of any contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#ifndef ARRAY_H
36#define ARRAY_H
37
38#ifndef assert
39#include <assert.h>
40#endif
41
42#ifndef NULL
43#define NULL 0
44#endif
45
46inline void *operator new(size_t, void *v) { return v; }
47
48template <class T>
49class array {
50 protected:
51 T *v;
52 int n, max;
53
54 void reallocto(int newsize) {
55 while (max<newsize) max += 16;
56 char *x = new char[max*sizeof(T)];
57 memcpy(x,v,n*sizeof(T));
58 delete []((char *)v);
59 v = (T *) x;
60 }
61 public:
62 array() { v=NULL; n=max=0; }
63 ~array() { setsize(0); delete []((char *)v); }
64
65 int num() const { return n; }
66
67 void setsize(int newsize) {
68 if (newsize>max) reallocto(newsize);
69 if (newsize>n) {
70 // call default constructors
71 for (int i=n; i<newsize; i++) (void) new(&v[i]) T;
72 }
73 else {
74 // call destructors
75 for (int i=newsize; i<n; i++) v[i].~T();
76 }
77 n = newsize;
78 }
79
80 T &operator [] (int ix) const {
81 assert(ix>=0 && ix<n);
82 return v[ix];
83 }
84
85 int add(const T &val) {
86 int ix = n;
87 setsize(n+1);
88 v[ix] = val;
89 return ix;
90 }
91
92 void push(const T &val) { add(val); }
93
94 T pop() { T t = (*this)[n-1]; setsize(n-1); return t; }
95};
96
97#endif