2
0

termio.pp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. {$IFNDEF FPC_DOTTEDUNITS}
  13. unit termio;
  14. {$ENDIF FPC_DOTTEDUNITS}
  15. interface
  16. {$inline on}
  17. {$IFDEF FPC_DOTTEDUNITS}
  18. Uses UnixApi.Base; // load base UnixApi.Unix typing
  19. {$ELSE FPC_DOTTEDUNITS}
  20. Uses BaseUnix; // load base unix typing
  21. {$ENDIF FPC_DOTTEDUNITS}
  22. // load types + consts
  23. {$i termios.inc}
  24. // load default prototypes from unix dir.
  25. {$i termiosh.inc}
  26. implementation
  27. // load implementation for prototypes from current dir.
  28. {$i termiosproc.inc}
  29. {We can implement ttyname more efficiently using proc than by including the
  30. generic ttyname.inc file.}
  31. function TTYName(Handle:cint):shortstring;
  32. { Return the name of the current tty described by handle f.
  33. returns empty string in case of an error.}
  34. var s:string[32];
  35. t:string[64];
  36. begin
  37. ttyname:='';
  38. if isatty(handle)=1 then
  39. begin
  40. str(handle,s);
  41. t:='/proc/self/fd/'+s+#0;
  42. ttyname[0]:=AnsiChar(fpreadlink(@t[1],@ttyname[1],255));
  43. end;
  44. end;
  45. function TTYName(var F:Text):shortstring;{$ifndef ver2_0}inline;{$endif}
  46. {
  47. Idem as previous, only now for text variables;
  48. }
  49. begin
  50. TTYName:=TTYName(textrec(f).handle);
  51. end;
  52. end.