⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 localio.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* *  Copyright 2000-2005 Wind River Systems, Inc. *  All rights reserved.  Provided under license only. *  Distribution or other use of this software is only *  permitted pursuant to the terms of a license agreement *  from Wind River Systems (and is otherwise prohibited). *  Refer to that license agreement for terms of use. *//* *  Copyright 1986-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. *//* * $Log: localio.c,v $ * Revision 1.2  2001/11/06 21:20:14  josh * revised new path hacking * * Revision 1.1.1.1  2001/11/05 17:47:42  tneale * Tornado shuffle * * Revision 9.2  2001/01/19 22:22:21  paul * Update copyright. * * Revision 9.1  2000/03/17 00:19:07  meister * Update copyright message * * Revision 9.0  1998/10/16 22:11:32  sar * Update version stamp to match release * * Revision 8.5  1998/09/04 14:15:44  sar * Clean up the return values for lcl_resize, we were trying to return * a -1 for an error.  As we weren't using the return values we now * return a 0 for succes and 1 for error. * * Revision 8.4  1998/06/22 03:11:14  sar * Changed the type used for lengths in localio.  We now use ALENGTH_Ts * to make it match the rest of the code and keep compilers happy * * Revision 8.3  1998/06/19 20:13:52  sar * make sure all files include asn1conf.h and snmp.h to pick up all of * the common code * * Revision 8.2  1998/06/05 18:53:13  sra * "#include <foo.h>" => "#include <envoy/h/foo.h>". * * Revision 8.1  1998/02/25 04:51:53  sra * Update copyrights. * * Revision 8.0  1997/11/18 00:56:50  sar * Updated revision to 8.0 * * Revision 7.3  1997/03/20 06:48:58  sra * DFARS-safe copyright text.  Zap! * * Revision 7.2  1997/02/25 10:49:26  sra * Update copyright notice, dust under the bed. * * Revision 7.1  1997/01/16 20:46:52  sar * changed uchar to bits8_t * * Revision 7.0  1996/03/18  20:01:11  sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.1  1995/10/20  22:59:09  sar * removed no_pp stuff & casts of 0 * modified memcpy to MEMCPY * * Revision 6.0  1995/05/31  21:47:26  sra * Release 6.0. * * Revision 5.0  1994/05/16  15:42:42  sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.1  1993/08/04  19:13:11  sra * Add a cast to make Borland C++ 3.1 happier. * * Revision 4.0  1993/06/24  15:45:46  sar * Updated revision to 4.0 and copyright to 93 * * Revision 3.3  1993/05/14  19:02:36  sar * made oldval in lcl_resize a size_t and cast it to an int for return * to avoid compiler warnings. * * Revision 3.2  1993/03/06  21:55:24  dab * Lcl_Dup() shouldn't assume that newfile is initialized even it * if it's non-zero. * * Revision 3.1  1993/02/17  21:04:43  sar * Removed #define then and uses of it. * Added Lcl_Dup - duplicate an i/o stream. * * Revision 3.0  92/04/03  19:52:37  dab * Release 3.0 *  * Revision 2.102  91/09/18  12:32:21  dab * Updated to use new macros from <asn1conf.h> and <snmpconf.h>. *  * Revision 2.101  91/08/15  12:31:02  dab * Removed <libfuncs.h>. *  * Revision 2.100  91/08/09  14:08:22  dab * Update version. *  * Revision 1.1  91/07/30  02:23:44  romkey * Initial revision *  *  *    Rev 2.0   31 Mar 1990 15:06:48 * Release 2.00 *  *    Rev 1.4   27 Apr 1989 15:56:38 * Removed unused variables *  *    Rev 1.3   12 Apr 1989 12:02:10 * Added cast on SNMP_mem_alloc. *  *    Rev 1.2   23 Mar 1989 11:22:02 * Revised Lcl_Open to return a null pointer if it can't obtain dynamic * memory for a local file descriptor. *  *    Rev 1.1   14 Sep 1988 17:57:10 * Moved includes of system include files into libfuncs.h. *  *    Rev 1.0   12 Sep 1988 10:47:00 * Initial revision.*//* [clearcase]modification history-------------------01c,12may05,job  fix apigen comments01b,18apr05,job  update copyright notices01a,24nov03,job  update copyright information*/#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/localio.h>/****************************************************************************Local I/O package -- performs I/O like operations on data in a buffer.Caveat: This version supports only input operations.****************************************************************************//****************************************************************************Lcl_Open -- Open a buffer for use as a local I/O streamPARAMETERS        LCL_FILE *	lfile	bits8_t  *	buffer	ALENGTH_T	nbytesIf lfile == (LCL_FILE *)0 a local file descriptor will be allocated.Returns: (LCL_FILE *) if sucessful, (LCL_FILE *)0 if unsucessful.****************************************************************************/LCL_FILE *  Lcl_Open(register LCL_FILE *lfile,	            bits8_t  *buff,	            ALENGTH_T nbytes){if (lfile == 0) {    if ((lfile = (LCL_FILE *)SNMP_memory_alloc(sizeof(LCL_FILE))) == 0)        return 0;    else        lfile->lcl_flags = LCL_MALLOC;    }else    lfile->lcl_flags = 0;lfile->lbuf_start = buff;lfile->lbuf_next = buff;lfile->lbuf_end = (bits8_t *)(buff + nbytes);return (lfile);}    /****************************************************************************Lcl_Close -- Close a local file descriptorPARAMETERS        LCL_FILE *	lfileReturns: nothing****************************************************************************/void  Lcl_Close(register LCL_FILE *lfile){if (lfile->lcl_flags & LCL_MALLOC) SNMP_memory_free((char *)lfile);}/****************************************************************************Lcl_Getc -- Read a character from a local I/O streamPARAMETERS        LCL_FILE *	lfileReturns: If sucessful: the character read, but in integer format	 If unsucessful: -1****************************************************************************/#if !defined(GETC_MACRO)int  Lcl_Getc(register 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;        }/*NOTREACHED*/}#endif	/* GETC_MACRO *//****************************************************************************Lcl_Peekc -- Peek at a character from a local I/O stream, the seek pointer	     is not advanced.PARAMETERS        LCL_FILE *	lfileReturns: If sucessful: the character read, but in integer format	 If unsucessful: -1****************************************************************************/int  Lcl_Peekc(register 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;    }/*NOTREACHED*/}/****************************************************************************Lcl_Read -- Read a set of characters from a local I/O stream.PARAMETERS        LCL_FILE *	lfile	bits8_t  *	ubuf	ALENGTH_T	nbytesReturns: The number of bytes actually read.****************************************************************************/ALENGTH_T  Lcl_Read(LCL_FILE *lfile,	   bits8_t  *ubuf,	   ALENGTH_T nbytes){/* This is a quick implementation, to be replaced later */ALENGTH_T orig_nbytes = nbytes;bits8_t c;while (nbytes > 0)    {    c = (bits8_t)Lcl_Getc(lfile);    if (Lcl_Eof(lfile)) break;    *ubuf++ = c;    --nbytes;    }return (orig_nbytes - nbytes);}/****************************************************************************Lcl_Seek -- Move the seek pointer to a give position in the local I/O buffer.PARAMETERS        LCL_FILE *	lfile	ALENGTH_T	offset	int		whence:			0 to set pointer to offset bytes from the start			1 to move pointer by offset bytes			2 to set pointer to offset bytes from the endReturns: 0 if sucessful, -1 if not.Note: The "end" position is the byte AFTER the last one in the buffercontaining data.  Thus, a Lcl_Seek(.., 0, 2) will leave the caller atthe end-of-file.  The last byte is reached by Lcl_Seek(.., 1, 2).****************************************************************************/int  Lcl_Seek(register LCL_FILE *lfile,	            ALENGTH_T offset,	            int	      whence){register bits8_t *next;switch (whence)    {    case 0:        next = (bits8_t *)(lfile->lbuf_start + offset);        break;    case 1:        next = (bits8_t *)(lfile->lbuf_next + offset);        break;    case 2:        next = (bits8_t *)(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;}/****************************************************************************Lcl_Resize -- Move the end-of-buffer position for the local I/O buffer.	      The buffer may be extended or contracted.PARAMETERS        LCL_FILE *	lfile	ALENGTH_T	offset	int		whence:			0 to set new end to offset bytes from the start			1 to move new end by offset bytes from the current			  read/write position			2 to set new end to offset bytes from the endReturns: 0 indicates success, 1 indicates error****************************************************************************/ALENGTH_T  Lcl_Resize(register LCL_FILE *lfile,	              ALENGTH_T	offset,	              int	whence){switch (whence)    {    case 0:        lfile->lbuf_end = (bits8_t *)(lfile->lbuf_start + offset);        break;    case 1:         lfile->lbuf_end = (bits8_t *)(lfile->lbuf_next + offset);        break;    case 2:         lfile->lbuf_end = (bits8_t *)(lfile->lbuf_end - offset);        break;    default:        return 1;    }if (lfile->lbuf_next < lfile->lbuf_end)    lfile->lcl_flags &= ~LCL_EOF;else    lfile->lcl_flags |= LCL_EOF;return (0);}/****************************************************************************Lcl_Dup -- Duplicate an I/O streamPARAMETERS        LCL_FILE *	newfile        LCL_FILE *	oldfileIf newfile == (LCL_FILE *)0 a local file descriptor will be allocated.If newfile != 0, the structure is assumed to be uninitialized and we markthe structure as not-malloc'd.Returns: (LCL_FILE *) if sucessful, (LCL_FILE *)0 if unsucessful.****************************************************************************/LCL_FILE *  Lcl_Dup(register LCL_FILE *newfile,	  register LCL_FILE *oldfile){if (newfile == 0) {    if ((newfile = (LCL_FILE *)SNMP_memory_alloc(sizeof(LCL_FILE))) == 0)        return 0;    else        newfile->lcl_flags = LCL_MALLOC | oldfile->lcl_flags;    }else    newfile->lcl_flags = oldfile->lcl_flags & ~LCL_MALLOC;newfile->lbuf_start = oldfile->lbuf_start;newfile->lbuf_next = oldfile->lbuf_next;newfile->lbuf_end = oldfile->lbuf_end;return (newfile);}    

⌨️ 快捷键说明

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