termio.pp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by Peter Vreman
  4. member of the Free Pascal development team.
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This file contains the termios interface.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. unit termio;
  13. interface
  14. {$inline on}
  15. Uses BaseUnix; // load base unix typing
  16. // load types + consts
  17. {$i termios.inc}
  18. // load default prototypes from unix dir.
  19. {$i termiosh.inc}
  20. implementation
  21. // load implementation for prototypes from current dir.
  22. {$i termiosproc.inc}
  23. {We can implement ttyname more efficiently using proc than by including the
  24. generic ttyname.inc file.}
  25. function TTYName(Handle:cint):string;
  26. { Return the name of the current tty described by handle f.
  27. returns empty string in case of an error.}
  28. var s:string[32];
  29. t:string[64];
  30. begin
  31. ttyname:='';
  32. if isatty(handle)=1 then
  33. begin
  34. str(handle,s);
  35. t:='/proc/self/fd/'+s+#0;
  36. ttyname[0]:=char(fpreadlink(@t[1],@ttyname[1],255));
  37. end;
  38. end;
  39. function TTYName(var F:Text):string;{$ifndef ver2_0}inline;{$endif}
  40. {
  41. Idem as previous, only now for text variables;
  42. }
  43. begin
  44. TTYName:=TTYName(textrec(f).handle);
  45. end;
  46. end.