bsdfuncs.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 2001 by Free Pascal development team
  5. An *BSD implementation of Uname and in the future some more
  6. calls.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. function sys_uname(var name:utsname):cint;
  14. Var
  15. mib : array[0..1] of cint;
  16. rval : cint;
  17. len : size_t;
  18. i : longint;
  19. oerrno : cint;
  20. procedure Doone(pz:pchar;pzsize:cint;val1,val2:cint);
  21. Begin
  22. mib[0] := val1;
  23. mib[1] := val2;
  24. len := pzsize;
  25. oerrno := geterrno;
  26. if (sys_sysctl(@mib, 2, pz, @len, NIL, 0) = -1) Then
  27. Begin
  28. if (geterrno = sys_ENOMEM) Then
  29. seterrno(oerrno)
  30. else
  31. rval := -1;
  32. End;
  33. pz[pzsize- 1] := #0;
  34. End;
  35. Begin
  36. rval := 0;
  37. DoOne(@name.sysname,sizeof(name.sysname),CTL_KERN,KERN_OSTYPE);
  38. DoOne(@name.nodename,sizeof(name.nodename),CTL_KERN,KERN_HOSTNAME);
  39. DoOne(@name.release,sizeof(name.release),CTL_KERN,KERN_OSRELEASE);
  40. { The version may have newlines in it, turn them into spaces. }
  41. DoOne(@name.version,sizeof(name.version),CTL_KERN,KERN_VERSION);
  42. For I:=0 to sizeof(name.sysname)-2 Do
  43. If (name.version[i]=#13) or (name.version[i]=#9) Then
  44. name.version[i]:=' ';
  45. DoOne(@name.machine,sizeof(name.machine),CTL_HW,HW_MACHINE);
  46. sys_Uname:=rval;
  47. end;
  48. {
  49. $Log$
  50. Revision 1.1 2002-08-21 07:03:16 marco
  51. * Fixes from Tuesday.
  52. Revision 1.1 2002/08/08 11:39:30 marco
  53. * Initial versions, to allow support for uname in posix.pp
  54. }