ungetc.c

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

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

#include <dos.h>
#include "asyncdef.h"

/*
** Place the character c into the input buffer being used by p so that
** it will be the next character to be read from the port. This
** operation may be performed until the buffer is full of the characters
** that have been pushed into it. If the port cannot accept the
** character, a value of -1 is returned. Otherwise, the value of the
** character that was pushed into the port's input buffer is returned.
*/
int a_ungetc(int c,register ASYNC *p)
{byte *bp;
 if (p)
  {disable();
   bp=p->ibuftail;
   if (bp==p->ibuf)
     bp=p->ibufend-1;
   else
     bp--;
   if (bp==p->ibufhead)
    {enable();
     return -1;
    }
   else
    {*bp=(byte)c;
     p->ibuftail=bp;
     p->icount++;
    }
   enable();
   return c;
  }
 return -1;
} /* end of a_ungetc(c,p) */

⌨️ 快捷键说明

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