是什么类型的文件对象的属性 [英] What are the properties of the Objects of type FILE

查看:197
本文介绍了是什么类型的文件对象的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文件对象通常是由创建
  打电话要么FOPEN或TMPFILE,这
  既是一个参考返回之一
  这些对象。

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

什么是结构体命名文件的属性,或者是与平台相关的?

What are the attributes of the Struct named FILE, or is it platform dependent?

推荐答案

答案是它依赖于平台。至少在Linux上使用的glibc,文件其实从 _IO_FILE 的typedef这是在 libio.h :

The answer is it is platform dependent. At least using glibc on Linux, FILE is in fact a typedef from _IO_FILE which is implemented in 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
};

由于马丁在纽约他的评论说,你是不是要了解该结构的内部。该结构的这一特定定义是不能保证是相同的跨实现;我期望MSVC的文件结构是不同的。

As Martin York says in his comments, you are not meant to know about the internals of this structure. This particular definition of the structure is not guaranteed to be the same across implementations; I'd expect MSVC's file structure to be different.

这篇关于是什么类型的文件对象的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆