Chinaunix首页 | 论坛 | 博客
  • 博客访问: 132792
  • 博文数量: 75
  • 博客积分: 3483
  • 博客等级: 中校
  • 技术积分: 820
  • 用 户 组: 普通用户
  • 注册时间: 2010-01-07 08:31
文章分类

全部博文(75)

文章存档

2011年(53)

2010年(22)

我的朋友
RSF

分类: BSD

2011-01-13 21:39:33


/*
* Rainbow read in 2011.1.13
* Times:1
* For: struct FILE
*/
* Rainbow 2011.1.12
------------------------------------------
fopen
 __sflags 设置标志位
 __sfp Find a free FILE for fopen et al. 分配一个FILE 从池中?
  __sfp --> findfp.c
  struct glue --> The first few FILEs are statically allocated; others are dynamically
    struct glue {
      struct glue *next;
      int niobs;
      FILE *iobs;
      } __sglue;
  In param.h:
   Round p (pointer or byte index) up to a correctly-aligned value for all data types (int, long, ...).
   对齐..? see my blog.
   #define ALIGNBYTES 3
   #define ALIGN(p) (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
  FILE in stdio.h
   typedef struct __sFILE {
    unsigned char *_p; /* current position in (some) buffer */ 偏移值
    int _r;  /* read space left for getc() */
    int _w;  /* write space left for putc() */
    short _flags;  /* flags, below; this FILE is free if 0 */标志位 用于各种判断 feof, ferror
    short _file;  /* fileno, if Unix descriptor, else -1 */ 文件描述符
    struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */ 设置缓冲区 setbuf(BUFFSIZ定义在stdio.h中), setvbuf
    int _lbfsize; /* 0 or -_bf._size, for inline putc */ 用于putc?
   
    /* operations */
    void *_cookie; /* cookie passed to io functions */
    int (*_close) __P((void *));
    int (*_read)  __P((void *, char *, int));
    fpos_t (*_seek)  __P((void *, fpos_t, int));
    int (*_write) __P((void *, const char *, int));
   
    /* separate buffer for long sequences of ungetc() */
    struct __sbuf _ub; /* ungetc buffer */
    unsigned char *_up; /* saved _p when _p is doing ungetc data */
    int _ur;  /* saved _r when _r is counting ungetc data */
   
    /* tricks to meet minimum requirements even when malloc() fails */
    unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
    unsigned char _nbuf[1]; /* guarantee a getc() buffer */
   
    /* separate buffer for fgetln() when line crosses buffer boundary */
    struct __sbuf _lb; /* buffer for fgetln() */
   
    /* Unix stdio files get aligned to block boundaries on fseek() */
    int _blksize; /* stat.st_blksize (may be != _bf._size) */
    fpos_t _offset; /* current lseek offset (see WARNING) */
   } FILE;
  _fwalk(function)
   遍历glue.h里面的__sglue,只要f->flag不等于0的,用对应的函数来调用
   比如fflush(fp),当fp == NULL时,会遍历调用__sflush所有未清空的fp
   @@ problem: in fflush.c
   
  我为什么要去看setvbuf()? 因为我在看__sfp的时候看到了FILE的设置 __sbuf... 产生了中断.. =.=!
  
  To fflush.c 85
  FILE结构体的定义..
阅读(381) | 评论(0) | 转发(0) |
0

上一篇:extern void _sig_ign __P

下一篇:何夕的作品

给主人留下些什么吧!~~