zoukankan      html  css  js  c++  java
  • ANSI C中关于FILE流的一些

    ANSI C只是一个定义,定义了一个借口与标准,具体实现将是不同的。

    刚看到I/O的时候就对于Stream非常的迷惑,这是什么玩意。后面才明白,这只是一个抽象出来的概念而已。对于一个Stream,它具有一切我们操控一个文件所需要的所有信息,我们只需要操控流,其他事情就交给内核或操作系统去完成就OK了。

    在Linux中,对于FILE结构有完整的定义,位于/usr/include/libio.h 下

    struct _IO_FILE {
      int _flags;           /* High-order word is _IO_MAGIC; rest is flags. */
    #define _IO_file_flags _flags
    
      /* The following pointers correspond to the C++ streambuf protocol. */
      /* Note:  Tk uses the _IO_read_ptr and _IO_read_end fields directly. */
      char* _IO_read_ptr;   /* Current read pointer */
      char* _IO_read_end;   /* End of get area. */
      char* _IO_read_base;  /* Start of putback+get area. */
      char* _IO_write_base; /* Start of put area. */
      char* _IO_write_ptr;  /* Current put pointer. */
      char* _IO_write_end;  /* End of put area. */
      char* _IO_buf_base;   /* Start of reserve area. */
      char* _IO_buf_end;    /* End of reserve area. */
      /* The following fields are used to support backing up and undo. */
      char *_IO_save_base; /* Pointer to start of non-current get area. */
      char *_IO_backup_base;  /* Pointer to first valid character of backup area */
      char *_IO_save_end; /* Pointer to end of non-current get area. */
    
      struct _IO_marker *_markers;
    
      struct _IO_FILE *_chain;
    
      int _fileno;
    #if 0
      int _blksize;
    #else
      int _flags2;
    #endif
      _IO_off_t _old_offset; /* This used to be _offset but it's too small.  */
    
    #define __HAVE_COLUMN /* temporary */
      /* 1+column number of pbase(); 0 is unknown. */
      unsigned short _cur_column;
      signed char _vtable_offset;
      char _shortbuf[1];
    
      /*  char* _save_gptr;  char* _save_egptr; */
    
      _IO_lock_t *_lock;
    #ifdef _IO_USE_OLD_IO_FILE
    };
    

      看了这才完整的明白 -这个流是什么东西。

  • 相关阅读:
    【递推】【HDU 2073】无限的路 (找规律)
    【省赛】山东省第七届ACM省赛(部分水题)
    【思维】牛客练习赛16 B-漂亮的树
    【搜索】牛客练习赛16 C-任意点 (类似求联通块)
    输入输出
    Python入门——运行python的两种方式&变量&常量
    编程语言分类
    What is an Operating System?
    计算机硬件&编程基础
    《SPA设计与架构》之认识SPA
  • 原文地址:https://www.cnblogs.com/dieangel/p/5610222.html
Copyright © 2011-2022 走看看