MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / MkTemp

Function MkTemp

Libraries/unrar/filefn.cpp:324–356  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322
323#if 0
324wchar *MkTemp(wchar *Name,size_t MaxSize)
325{
326 size_t Length=wcslen(Name);
327
328 RarTime CurTime;
329 CurTime.SetCurrentTime();
330
331 // We cannot use CurTime.GetWin() as is, because its lowest bits can
332 // have low informational value, like being a zero or few fixed numbers.
333 uint Random=(uint)(CurTime.GetWin()/100000);
334
335 // Using PID we guarantee that different RAR copies use different temp names
336 // even if started in exactly the same time.
337 uint PID=0;
338#ifdef _WIN_ALL
339 PID=(uint)GetCurrentProcessId();
340#elif defined(_UNIX)
341 PID=(uint)getpid();
342#endif
343
344 for (uint Attempt=0;;Attempt++)
345 {
346 uint Ext=Random%50000+Attempt;
347 wchar RndText[50];
348 swprintf(RndText,ASIZE(RndText),L"%u.%03u",PID,Ext);
349 if (Length+wcslen(RndText)>=MaxSize || Attempt==1000)
350 return NULL;
351 wcsncpyz(Name+Length,RndText,MaxSize-Length);
352 if (!FileExist(Name))
353 break;
354 }
355 return Name;
356}
357#endif
358
359

Callers

nothing calls this directly

Calls 4

wcsncpyzFunction · 0.85
FileExistFunction · 0.85
SetCurrentTimeMethod · 0.80
GetWinMethod · 0.80

Tested by

no test coverage detected