home *** CD-ROM | disk | FTP | other *** search
/ Zodiac Super OZ / MEDIADEPOT.ISO / FILES / 13 / DJCRX201.ZIP / include / libc / file.h < prev    next >
C/C++ Source or Header  |  1996-07-24  |  2KB  |  93 lines

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