c - FILE类型的对象有哪些属性

标签 c file properties stdio

FILE objects are usually created by a call to either fopen or tmpfile, which both return a reference to one of these objects.

名为 FILE 的结构有哪些属性,或者它是否依赖于平台?

最佳答案

答案是它依赖于平台。至少在 Linux 上使用 glibc,FILE 实际上是 _IO_FILE 的 typedef,它在 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
};

正如 Martin York 在他的评论中所说,你不应该了解这个结构的内部结构。不保证该结构的特定定义在不同实现中是相同的;我希望 MSVC 的文件结构有所不同。

关于c - FILE类型的对象有哪些属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4862532/

相关文章:

c++ - 为什么在 C 和 C++ 中算术运算之前必须将 Short 转换为 int?

c - 将有符号的 char 数组传递给需要 const char 指针的函数会导致数组值出现乱码

c - 我需要在程序中解决这两个问题。根据输入,我需要修复代码以产生所需的输出

c++ - 通过读取文件检测 C++ 中的空行

javascript - 按钮值未显示 -javascript

字符数组打印垃圾,除非我增加数组大小

php - 使用 symfony2 和 twig 创建文件文本

javascript - 使用 Javascript 将 blob 转换为 .doc、.docx、.xls 或 .txt 以在浏览器中查看而无需下载

c++ - 我正在尝试通过 Boost 图形库从 Graphviz DOT 文件中读取图形。如何读取存储在数组中的未知数量的属性?

java - 让 Spring 替换不同文件类型中的占位符(除了 Spring 的配置)