suuid.inc 653 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. Const
  2. RandomDevice = '/dev/urandom';
  3. Function GetURandomBytes(Var Buf; NBytes : Integer) : Boolean;
  4. Var
  5. fd,I : Integer;
  6. P : PByte;
  7. begin
  8. P:=@Buf;
  9. fd:=FileOpen(RandomDevice,fmOpenRead);
  10. Result:=(fd>=0);
  11. if Result then
  12. Try
  13. While (NBytes>0) do
  14. begin
  15. I:=FileRead(fd,P^,nbytes);
  16. If I>0 then
  17. begin
  18. Inc(P,I);
  19. Dec(NBytes,I);
  20. end;
  21. end;
  22. Finally
  23. FileClose(Fd);
  24. end;
  25. end;
  26. Function SysCreateGUID(out GUID : TGUID) : Integer;
  27. begin
  28. if not GetUrandomBytes(Guid,SizeOf(GUID)) then
  29. GetRandomBytes(GUID,SizeOf(Guid));
  30. Result:=0;
  31. end;