This file is indexed.

/usr/include/crystalspace-2.0/csutil/util.h is in libcrystalspace-dev 2.0+dfsg-1build1.

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
/*
    Copyright (C) 1998 by Jorrit Tyberghein

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public
    License along with this library; if not, write to the Free
    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifndef __CS_UTIL_H__
#define __CS_UTIL_H__

#include <stdio.h>
#include "csextern.h"
#include "csutil/csunicode.h"

/**\file
 * Miscellaneous utilities
 */

/**\addtogroup util
 * @{ */

namespace CS
{
  /**
   * Allocate a char string with cs_malloc() and copy the string into the 
   * newly allocated storage.
   * This is a handy method for copying strings, in fact it is an analogue
   * of the strdup() function from string.h, but using cs_malloc(). (Also,
   * strdup() is not present on some platforms). To free the pointer the 
   * caller should call cs_free().
   */
  CS_CRYSTALSPACE_EXPORT char* StrDup (const char *s);
  /**
   * Allocate a char string with cs_malloc() and copy an UTF-8 version of the 
   * string into the newly allocated storage.
   * \sa StrDup(const char*)
   */
  CS_CRYSTALSPACE_EXPORT char* StrDup (const wchar_t *s);
  /**
   * Allocate a wide char string with cs_malloc() and copy the string into 
   * the newly allocated storage.
   * \sa StrDup(const char*)
   */
  CS_CRYSTALSPACE_EXPORT wchar_t* StrDupW (const wchar_t *s);
  /**
   * Allocate a wide char string with cs_malloc() and copy the string 
   * converted from UTF-8 into the newly allocated storage.
   * \sa StrDup(const char*)
   */
  CS_CRYSTALSPACE_EXPORT wchar_t* StrDupW (const char *s);
}

///\internal Helper function needed by the csStrNew variants below
CS_CRYSTALSPACE_EXPORT size_t cs_wcslen (wchar_t const* s);

/**
 * Allocate a new char [] and copy the string into the newly allocated 
 * storage.
 * This is a handy method for copying strings, in fact it is the C++ analogue
 * of the strdup() function from string.h (strdup() is not present on some
 * platforms). To free the pointer the caller should call delete[].
 * \sa CS::StrDup which is slightly more efficient
 */
inline char *csStrNew (const char *s)
{
  if (!s) return 0;
  size_t sl = strlen (s) + 1;
  char *r = new char [sl];
  memcpy (r, s, sl);
  return r;
}
/**
 * Allocate a new char [] and copy an UTF-8 version of the string into 
 * the newly allocated storage.
 * \sa csStrNew(const char*)
 * \sa CS::StrDup which is slightly more efficient
 */
inline char *csStrNew (const wchar_t *s)
{
  if (!s) return 0;
  char* cs = CS::StrDup (s);
  size_t sl = strlen (cs) + 1;
  char *r = new char [sl];
  memcpy (r, cs, sl);
  cs_free (cs);
  return r;
}
/**
 * Allocate a new widechar [] and copy the string into the newly allocated 
 * storage.
 * \sa csStrNew(const char*)
 * \sa CS::StrDupW which is slightly more efficient
 */
inline wchar_t* csStrNewW (const wchar_t *s)
{
  if (!s) return 0;
  size_t sl = cs_wcslen (s) + 1;
  wchar_t *r = new wchar_t [sl];
  memcpy (r, s, sl * sizeof (wchar_t));
  return r;
}
/**
 * Allocate a new widechar [] and copy the string converted from UTF-8 into 
 * the newly allocated storage.
 * \sa csStrNew(const char*)
 * \sa CS::StrDupW which is slightly more efficient
 */
inline wchar_t* csStrNewW (const char *s)
{
  if (!s) return 0;
  wchar_t* ws = CS::StrDupW (s);
  size_t sl = cs_wcslen (ws) + 1;
  wchar_t *r = new wchar_t [sl];
  memcpy (r, ws, sl * sizeof (wchar_t));
  cs_free (ws);
  return r;
}

/**
 * Perform case-insensitive string comparison. Returns a negative number if \p
 * str1 is less than \p str2, zero if they are equal, or a positive number if
 * \p str1 is greater than \p str2. For best portability, use function rather
 * than strcasecmp() or stricmp().
 */
CS_CRYSTALSPACE_EXPORT int csStrCaseCmp(char const* str1, char const* str2);

/**
 * Perform case-insensitive string comparison of the first \p n characters of
 * \p str1 and \p str2. Returns a negative number if the n-character prefix of
 * \p str1 is less than \p str2, zero if they are equal, or a positive number
 * if the prefix of \p str1 is greater than \p str2. For best portability, use
 * function rather than strncasecmp() or strnicmp().
 */
CS_CRYSTALSPACE_EXPORT int csStrNCaseCmp(char const* str1, char const* str2,
  size_t n);

/**
 * Helper class to convert wchar_t* to char* (UTF-8 encoded) strings for use
 * as function parameters.
 * Use of this helper class is more convenient than a csStrNew() / delete[]
 * pair, but essentially does the same (with the convenience of automatic
 * cleanup).
 * \code
 *   wchar_t* wstr = L"Hello World";
 *    ... 
 *   iNativeWindow* natwin =  ... ;
 *     natwin->SetTitle (csWtoC (wstr));
 * \endcode
 */
struct csWtoC
{
private:
  char* s;
public:
  /**
   * Constructor.
   * Stores an UTF-8 converted version of \p ws internally.   
   */
  csWtoC (const wchar_t* ws)
  { s = CS::StrDup (ws); }
  /**
   * Deletes the internally stored string.
   */
  ~csWtoC ()
  { cs_free (s); }
  /**
   * Retrieve the converted string.
   */
  operator const char* () const
  { return s; }
};

/**
 * Helper class to convert char* (UTF-8 encoded )to wchar_t* strings for use
 * as function parameters.
 * Use of this helper class is more convenient than a csStrNewW() / delete[]
 * pair, but essentially does the same (with the convenience of automatic
 * cleanup).
 */
struct csCtoW
{
private:
  wchar_t* ws;
public:
  /**
   * Constructor.
   * Stores an UTF-16 converted version of \p s internally.   
   */
  csCtoW (const char* s)
  { ws = CS::StrDupW (s); }
  /**
   * Deletes the internally stored string.
   */
  ~csCtoW ()
  { cs_free (ws); }
  /**
   * Retrieve the converted string.
   */
  operator const wchar_t* () const
  { return ws; }
};

/**
 * Expand a filename if it contains shortcuts.
 * Currently the following macros are recognised and expanded:
 * <pre>
 * '.', '~', '..', 'drive:' (on DOS/Win32/OS2)
 * </pre>
 * The returned filename is always absolute, i.e. it always starts
 * from root. Return a string allocated with csStrNew().
 */
CS_CRYSTALSPACE_EXPORT char *csExpandName (const char *iName);

/**
 * Split a pathname into separate path and name.
 */
CS_CRYSTALSPACE_EXPORT void csSplitPath (const char *iPathName, char *oPath,
  size_t iPathSize, char *oName, size_t iNameSize);

/**
 * Perform shell-like filename \e globbing (pattern matching).
 * The special token \p * matches zero or more characters, and the token \p ? 
 * matches exactly one character. Examples: "*a*.txt", "*a?b*", "*"
 * Character-classes \p [a-z] are not understood by this function.
 * \remark If you want case-insensitive comparison, convert \p fName and
 *   \p fMask to upper- or lower-case first.
 */
CS_CRYSTALSPACE_EXPORT bool csGlobMatches (const char *fName,
	const char *fMask);

/**
 * Finds the smallest number that is a power of two and is larger or
 * equal to n.
 */
static inline int csFindNearestPowerOf2 (int n)
{
  int v=n;

  v--;
  v |= v >> 1;
  v |= v >> 2;
  v |= v >> 4;
  v |= v >> 8;
  v |= v >> 16;
  v++;

  return v;
}

/// Returns true if n is a power of two.
static inline bool csIsPowerOf2 (int n)
{
  return !(n & (n - 1)) && n;	// (n-1) ^ n >= n;
}

/// Find the log2 of 32bit argument.
CS_CRYSTALSPACE_EXPORT int csLog2 (int n);

/**
 * Given \p src and \p dest, which are already allocated, copy \p source to \p
 * dest.  But, do not copy \p search, instead replace that with \p replace
 * string.  \p max is size in bytes of \p dest.
 */
CS_CRYSTALSPACE_EXPORT void csReplaceAll (char *dest, const char *src,
  const char *search, const char *replace, int max);


/** @} */
  
#endif // __CS_UTIL_H__