getc.c

来自「异步通讯C语言例行子程序」· C语言 代码 · 共 26 行

C
26
字号
/* A module of ASYNCx.LIB version 1.20 */

#include "asyncdef.h"

/***************************************************************
 Get one byte from the input buffer of the async port
 associated with p. If a byte is found in the buffer, return
 its value in the form of an integer (without sign extension).
 If the buffer is empty, return a value of -1.
***************************************************************/
int a_getc(register ASYNC *p)
{byte c,*bp;
 if (p)
  {bp=p->ibuftail;        /* point to the next byte in the buffer */
   if (bp==p->ibufhead)   /* if there is nothing in the buffer,   */
     return -1;           /* return EOF.                          */
   c=(byte)(*bp++);       /* else, get the next byte.             */
   p->icount--;           /* adjust the byte count                */
   if (bp==p->ibufend)    /* wrap if necessary                    */
     bp=p->ibuf;
   p->ibuftail=bp;
   return (unsigned)c;    /* return the value retrieved           */
  }
 return -1;
} /* end of a_getc(p) */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?