bsdfuncs.inc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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; external name 'FPC_SYSC_UNAME';
  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. function GetDomainName(Name:PChar; NameLen:Cint):cint; external name 'FPC_SYSC_GETDOMAINNAME';
  49. Const Mib_GetDomainName : array[0..1] of cint=(CTL_KERN,KERN_NISDOMAINNAME);
  50. VAR
  51. tsize : size_t;
  52. begin
  53. tsize := namelen;
  54. if (sys_sysctl(@Mib_GetDomainname, 2, name, @tsize, NIL, 0) = -1) Then
  55. GetDomainName:=-1
  56. Else
  57. GetDomainName:=0;
  58. end;
  59. function GetHostName(Name:PChar; NameLen:Cint):cint; external name 'FPC_SYSC_GETHOSTNAME';
  60. Const Mib_GetHostName : array[0..1] of cint=(CTL_KERN,KERN_HOSTNAME);
  61. Var
  62. tsize : size_t;
  63. begin
  64. tsize := namelen;
  65. if (sys_sysctl(@Mib_GetHostName, 2, name, @tsize, NIL, 0) = -1) Then
  66. GetHostName:=-1
  67. Else
  68. GetHostName:=0;
  69. End;
  70. {
  71. $Log$
  72. Revision 1.4 2002-09-08 16:20:27 marco
  73. * Forgot external name's
  74. Revision 1.3 2002/09/08 16:11:59 marco
  75. * Added GetDomainName and that other one ..
  76. Revision 1.2 2002/09/07 16:01:17 peter
  77. * old logs removed and tabs fixed
  78. Revision 1.1 2002/08/21 07:03:16 marco
  79. * Fixes from Tuesday.
  80. Revision 1.1 2002/08/08 11:39:30 marco
  81. * Initial versions, to allow support for uname in posix.pp
  82. }