~ubuntu-branches/ubuntu/vivid/unrar-nonfree/vivid

« back to all changes in this revision

Viewing changes to strfn.cpp

  • Committer: Package Import Robot
  • Author(s): Martin Meredith
  • Date: 2015-02-03 12:58:01 UTC
  • mfrom: (1.1.18) (5.1.18 sid)
  • Revision ID: package-import@ubuntu.com-20150203125801-od6ev8cqy1er51vz
Tags: 1:5.2.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
const char *NullToEmpty(const char *Str)
4
4
{
5
 
  return(Str==NULL ? "":Str);
 
5
  return Str==NULL ? "":Str;
6
6
}
7
7
 
8
8
 
9
9
const wchar *NullToEmpty(const wchar *Str)
10
10
{
11
 
  return(Str==NULL ? L"":Str);
 
11
  return Str==NULL ? L"":Str;
12
12
}
13
13
 
14
14
 
17
17
#ifdef _WIN_ALL
18
18
  OemToCharBuffA(Src,Dest,(DWORD)DestSize);
19
19
  Dest[DestSize-1]=0;
 
20
#elif defined(_ANDROID)
 
21
  wchar DestW[NM];
 
22
  UnkToWide(Src,DestW,ASIZE(DestW));
 
23
  WideToChar(DestW,Dest,DestSize);
20
24
#else
21
25
  if (Dest!=Src)
22
26
    strncpyz(Dest,Src,DestSize);
27
31
int stricomp(const char *s1,const char *s2)
28
32
{
29
33
#ifdef _WIN_ALL
30
 
  return(CompareStringA(LOCALE_USER_DEFAULT,NORM_IGNORECASE|SORT_STRINGSORT,s1,-1,s2,-1)-2);
 
34
  return CompareStringA(LOCALE_USER_DEFAULT,NORM_IGNORECASE|SORT_STRINGSORT,s1,-1,s2,-1)-2;
31
35
#else
32
36
  while (toupper(*s1)==toupper(*s2))
33
37
  {
47
51
  // If we specify 'n' exceeding the actual string length, CompareString goes
48
52
  // beyond the trailing zero and compares garbage. So we need to limit 'n'
49
53
  // to real string length.
50
 
  size_t l1=Min(strlen(s1)+1,n);
51
 
  size_t l2=Min(strlen(s2)+1,n);
52
 
  return(CompareStringA(LOCALE_USER_DEFAULT,NORM_IGNORECASE|SORT_STRINGSORT,s1,(int)l1,s2,(int)l2)-2);
 
54
  // It is important to use strnlen (or memchr(...,0)) instead of strlen,
 
55
  // because data can be not zero terminated.
 
56
  size_t l1=Min(strnlen(s1,n),n);
 
57
  size_t l2=Min(strnlen(s2,n),n);
 
58
  return CompareStringA(LOCALE_USER_DEFAULT,NORM_IGNORECASE|SORT_STRINGSORT,s1,(int)l1,s2,(int)l2)-2;
53
59
#else
54
60
  if (n==0)
55
61
    return 0;
192
198
    Number/=10;
193
199
    Digits++;
194
200
  }
195
 
  return(Digits);
 
201
  return Digits;
196
202
}
197
203
#endif
198
204
 
201
207
{
202
208
  for (int I=0;Str[I]!=0;I++)
203
209
    if ((byte)Str[I]<32 || (byte)Str[I]>127)
204
 
      return(false);
205
 
  return(true);
 
210
      return false;
 
211
  return true;
206
212
}
207
213
 
208
214
 
211
217
  for (int I=0;Str[I]!=0;I++)
212
218
  {
213
219
    // We convert wchar_t to uint just in case if some compiler
214
 
    // uses the signed wchar_t.
 
220
    // uses signed wchar_t.
215
221
    if ((uint)Str[I]<32 || (uint)Str[I]>127)
216
 
      return(false);
 
222
      return false;
217
223
  }
218
 
  return(true);
 
224
  return true;
219
225
}
220
226
 
221
227
 
222
228
int wcsicompc(const wchar *Str1,const wchar *Str2)
223
229
{
224
230
#if defined(_UNIX)
225
 
  return(wcscmp(Str1,Str2));
 
231
  return wcscmp(Str1,Str2);
226
232
#else
227
 
  return(wcsicomp(Str1,Str2));
 
233
  return wcsicomp(Str1,Str2);
228
234
#endif
229
235
}
230
236
 
237
243
    strncpy(dest,src,maxlen-1);
238
244
    dest[maxlen-1]=0;
239
245
  }
240
 
  return(dest);
 
246
  return dest;
241
247
}
242
248
 
243
249
 
259
265
char* strncatz(char* dest, const char* src, size_t maxlen)
260
266
{
261
267
  size_t Length = strlen(dest);
262
 
  if (Length + 1 < maxlen)
263
 
    strncat(dest, src, maxlen - Length - 1);
 
268
  int avail=int(maxlen - Length - 1);
 
269
  if (avail > 0)
 
270
    strncat(dest, src, avail);
264
271
  return dest;
265
272
}
266
273
 
271
278
wchar* wcsncatz(wchar* dest, const wchar* src, size_t maxlen)
272
279
{
273
280
  size_t Length = wcslen(dest);
274
 
  if (Length + 1 < maxlen)
275
 
    wcsncat(dest, src, maxlen - Length - 1);
 
281
  int avail=int(maxlen - Length - 1);
 
282
  if (avail > 0)
 
283
    wcsncat(dest, src, avail);
276
284
  return dest;
277
285
}
278
286
 
321
329
  wchar *Str=StrTable[StrNum];
322
330
  CharToWide(Src,Str,MaxLength);
323
331
  Str[MaxLength-1]=0;
324
 
  return(Str);
 
332
  return Str;
325
333
}
326
334
 
327
335
 
396
404
  Cvt[Dest]=0;
397
405
}
398
406
#endif
399
 
 
400
 
 
401
 
bool GetPassword(PASSWORD_TYPE Type,const wchar *FileName,SecPassword *Password)
402
 
{
403
 
#ifdef SILENT
404
 
  return false;
405
 
#else
406
 
  return GetConsolePassword(Type,FileName,Password);
407
 
#endif
408
 
}
409