📄 a_localio.c
字号:
#include "snmptype.h"
#include "a_localio.h"
/****************************************************************************
Lcl_Open -- Open a buffer for use as a local I/O stream
Parameters: LCL_FILE *lfile
_UINT8 *buffer
_UINT16 nbytes
Returns: (LCL_FILE *) if sucessful, (LCL_FILE *)0 if unsucessful.
****************************************************************************/
LCL_FILE *Lcl_Open(LCL_FILE * lfile, _UINT8 * buff, _UINT16 nbytes)
{
if(lfile == 0)
return 0;
lfile->lcl_flags = 0;
lfile->lbuf_start = buff;
lfile->lbuf_next = buff;
lfile->lbuf_end = (_UINT8 *) (buff + nbytes);
return (lfile);
}
/****************************************************************************
Lcl_Peekc -- Peek at a character from a local I/O stream, the seek poINT32er is not advanced.
Parameters: LCL_FILE * lfile
Returns: If sucessful: the character read, but in INT32eger format
If unsucessful: -1
****************************************************************************/
_INT16 Lcl_Peekc(LCL_FILE * lfile)
{
if(lfile->lcl_flags & LCL_EOF)
return -1;
if(lfile->lbuf_next < lfile->lbuf_end)
return (*(lfile->lbuf_next));
else
{
lfile->lcl_flags |= LCL_EOF;
return -1;
}
}
/****************************************************************************
Lcl_Read -- Read a set of characters from a local I/O stream.
Parameters:
LCL_FILE * lfile
_UINT8 * ubuf
_UINT16 nbytes
Returns: The number of bytes actually read.
****************************************************************************/
_UINT16 Lcl_Read(LCL_FILE * lfile, _UINT8 * ubuf, _UINT16 nbytes)
{
/* This is a quick implementation, to be replaced later */
_UINT16 orig_nbytes = nbytes;
_UINT8 c;
while(nbytes > 0)
{
c = (_UINT8) Lcl_Getc(lfile);
if(Lcl_Eof(lfile))
break;
*ubuf++ = c;
--nbytes;
}
return (orig_nbytes - nbytes);
}
/****************************************************************************
Lcl_Seek -- Move the seek poINT32er to a give position in the local I/O buffer.
Parameters:
LCL_FILE * lfile
_UINT16 offset
_INT32 whence:
0 to set poINT32er to offset bytes from the start
1 to move poINT32er by offset bytes
2 to set poINT32er to offset bytes from the end
Returns: 0 if sucessful, -1 if not.
Note: The "end" position is the byte AFTER the last one in the buffer
containing data. Thus, a Lcl_Seek(.., 0, 2) will leave the caller at
the end-of-file. The last byte is reached by Lcl_Seek(.., 1, 2).
****************************************************************************/
_INT16 Lcl_Seek(LCL_FILE * lfile, _UINT16 offset, _INT16 whence)
{
_UINT8 *next;
switch (whence)
{
case 0:
next = (_UINT8 *) (lfile->lbuf_start + offset);
break;
case 1:
next = (_UINT8 *) (lfile->lbuf_next + offset);
break;
case 2:
next = (_UINT8 *) (lfile->lbuf_end - offset);
break;
default:
return -1;
}
if((next < lfile->lbuf_start) || (next > lfile->lbuf_end))
return -1;
if(next < lfile->lbuf_end)
lfile->lcl_flags &= ~LCL_EOF;
lfile->lbuf_next = next;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -