Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
  2. /* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
  3. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  4. #ifndef __dj_include_libc_file_h__
  5. #define __dj_include_libc_file_h__
  6.  
  7. #include <fcntl.h>
  8. #include <libc/dosio.h>
  9. #include <libc/ttyprvt.h>
  10.  
  11. #ifdef __cplusplus
  12. extern "C" {
  13. #endif
  14.  
  15. #ifndef __dj_ENFORCE_ANSI_FREESTANDING
  16.  
  17. #ifndef __STRICT_ANSI__
  18.  
  19. #ifndef _POSIX_SOURCE
  20.  
  21. #define _IOREAD   000010
  22. #define _IOWRT    000020
  23. #define _IOMYBUF  000040
  24. #define _IOEOF    000100
  25. #define _IOERR    000200
  26. #define _IOSTRG   000400
  27. #define _IORW     001000
  28. #define _IOAPPEND 002000
  29. #define _IORMONCL 004000  /* remove on close, for temp files */
  30. /* if _flag & _IORMONCL, ._name_to_remove needs freeing */
  31. #define _IOUNGETC 010000  /* there is an ungetc'ed character in the buffer */
  32. #define _IOTERM   020000  /* file's handle hooked by termios */
  33. #define _IONTERM  040000  /* file's handle not hooked by termios */
  34.  
  35. int     _flsbuf(int, FILE*);
  36. int     _filbuf(FILE *);
  37. void    _fwalk(void (*)(FILE *));
  38.  
  39. static __inline__ int __getc_raw(FILE *const p)
  40. {
  41.    if(p->_cnt>0)
  42.    {
  43.       p->_cnt--;
  44.       return((unsigned char)*(p->_ptr++));
  45.    }
  46.    return(_filbuf(p));
  47. }
  48.  
  49. static __inline__ int __putc_raw(int const x,FILE *const p)
  50. {
  51.    if(p->_cnt>0)
  52.    {
  53.       p->_cnt--;
  54.       return((unsigned char)(*(p->_ptr++)=(unsigned char)x));
  55.    }
  56.    return(_flsbuf((unsigned char)x,p));
  57. }
  58.  
  59. static __inline__ int __is_text_file(FILE *const p)
  60. {
  61.    return(!((p)->_flag & (_IOSTRG | _IOTERM))
  62.           && (__file_handle_modes[(p)->_file]&O_TEXT));
  63. }
  64.  
  65. static __inline__ int __getc(FILE *const p)
  66. {
  67.   int __c;
  68.   if (__libc_read_termios_hook
  69.       && ((p)->_flag & (_IOTERM | _IONTERM)) == 0)
  70.   {
  71.     extern int __isatty(int);
  72.     /* first time we see this handle--see if termios hooked it */
  73.     if (!((p)->_flag & _IOSTRG) && __isatty((p)->_file))
  74.       (p)->_flag |= _IOTERM;
  75.     else
  76.       (p)->_flag |= _IONTERM;
  77.   }
  78.   __c = __getc_raw(p);
  79.   if (__c=='\r' && __is_text_file(p))
  80.     return __getc_raw(p);
  81.   return __c;
  82. }
  83.  
  84. static __inline__ int __putc(const int x,FILE *const p)
  85. {
  86.   if (__libc_write_termios_hook
  87.       && ((p)->_flag & (_IOTERM | _IONTERM)) == 0)
  88.   {
  89.     extern int __isatty(int);
  90.     /* first time we see this handle--see if termios hooked it */
  91.     if (!((p)->_flag & _IOSTRG) && __isatty((p)->_file))
  92.       (p)->_flag |= _IOTERM;
  93.     else
  94.       (p)->_flag |= _IONTERM;
  95.   }
  96.   if(x=='\n' && __is_text_file(p))
  97.     __putc_raw('\r',p);
  98.   return __putc_raw(x,p);
  99. }
  100.  
  101. #undef  fileno
  102. #define fileno(f)       (f->_file)
  103. #undef  feof
  104. #define feof(f)         (((f)->_flag&_IOEOF)!=0)
  105. #undef  ferror
  106. #define ferror(f)       (((f)->_flag&_IOERR)!=0)
  107.  
  108. #endif /* !_POSIX_SOURCE */
  109. #endif /* !__STRICT_ANSI__ */
  110. #endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
  111.  
  112. #ifndef __dj_ENFORCE_FUNCTION_CALLS
  113. #endif /* !__dj_ENFORCE_FUNCTION_CALLS */
  114.  
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118.  
  119. #endif /* __dj_include_libc_file_h__ */
  120.