中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

gnu c的setbuf函數源代碼

發布時間:2020-07-27 17:31:56 來源:網絡 閱讀:583 作者:hjun169 欄目:編程語言
  1. libio/sebuf.c定義了sebbuf函數:

    void setbuf (FILE *fp, char *buf)
    {
      _IO_setbuffer (fp, buf, BUFSIZ);
    }

  2. libio/iosetbuffer.c定義了_IO_setbuffer函數:

    void _IO_setbuffer (FILE *fp, char *buf, size_t size)
    {
      CHECK_FILE (fp, );
      _IO_acquire_lock (fp);
      fp->_flags &= ~_IO_LINE_BUF;
      if (!buf)
        size = 0;
      (void) _IO_SETBUF (fp, buf, size);
      if (_IO_vtable_offset (fp) == 0 && fp->_mode == 0 && _IO_CHECK_WIDE (fp))
        /* We also have to set the buffer using the wide char function.  */
        (void) _IO_WSETBUF (fp, buf, size);
      _IO_release_lock (fp);
    }

    除了鎖定FILE指針外,核心代碼就是_IO_SETBUF和用于多字節環境的_IO_WSETBUF,最后解析,重點介紹下_IO_SETBUF

  3. libio/libioP.h定義了_IO_SETBUF和_IO_WSETBUF:

    typedef FILE* (*_IO_setbuf_t) (FILE *, char *, ssize_t);
    #define _IO_SETBUF(FP, BUFFER, LENGTH) JUMP2 (__setbuf, FP, BUFFER, LENGTH)
    #define _IO_WSETBUF(FP, BUFFER, LENGTH) WJUMP2 (__setbuf, FP, BUFFER, LENGTH)

       #define JUMP2(FUNC, THIS, X1, X2) (_IO_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)

       #define WJUMP2(FUNC, THIS, X1, X2) (_IO_WIDE_JUMPS_FUNC(THIS)->FUNC) (THIS, X1, X2)


       struct _IO_FILE_plus
       {
          FILE file;
          const struct _IO_jump_t *vtable;
        };

       1)_IO_JUMPS_FUNC(THIS)是通過_IO_CAST_FIELD_ACCESS將setbuf函數的參數fp轉成struct _IO_FILE_plus類型,

并返回struct _IO_FILE_plus的vtable變量,通過vtable調用__setbuf函數(JUMP2的參數),

      2)通過JUMP_INIT (setbuf, _IO_default_setbuf)定義了vtable默認的__setbuf函數

   4. libio/genops.c定義了_IO_default_setbuf及其調用的_IO_setb,_IO_setb設置了setbuf函數的參數fp的_IO_buf_base等buf變量:

        FILE * _IO_default_setbuf (FILE *fp, char *p, ssize_t len)
        {
            if (_IO_SYNC (fp) == EOF)
                   return NULL;
            if (p == NULL || len == 0)
              {
                    fp->_flags |= _IO_UNBUFFERED;
                    _IO_setb (fp, fp->_shortbuf, fp->_shortbuf+1, 0);
             }
            else
              {
                    fp->_flags &= ~_IO_UNBUFFERED;
                    _IO_setb (fp, p, p+len, 0);
              }
               fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_write_end = 0;
               fp->_IO_read_base = fp->_IO_read_ptr = fp->_IO_read_end = 0;
              return fp;
        }

       void _IO_setb (FILE *f, char *b, char *eb, int a)
      {
          if (f->_IO_buf_base && !(f->_flags & _IO_USER_BUF))
            free (f->_IO_buf_base);
          f->_IO_buf_base = b;
          f->_IO_buf_end = eb;
          if (a)
            f->_flags &= ~_IO_USER_BUF;
          else
            f->_flags |= _IO_USER_BUF;
    }

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

灵山县| 麻阳| 黄大仙区| 新丰县| 五河县| 江孜县| 武汉市| 东宁县| 和田县| 连平县| 大荔县| 延寿县| 咸丰县| 凉山| 沂水县| 丽江市| 盘山县| 都江堰市| 屯门区| 栾城县| 榆社县| 绥滨县| 洪洞县| 扬州市| 永嘉县| 阳高县| 临西县| 贺兰县| 张家界市| 应城市| 卢氏县| 辽阳市| 融水| 隆回县| 榆社县| 阳江市| 海门市| 麟游县| 浮山县| 安仁县| 昌宁县|