memsrc.cpp

来自「伯克利做的SFTP安全文件传输协议」· C++ 代码 · 共 58 行

CPP
58
字号
// memsrc.cc// code for memsrc.h// copyright SafeTP Development Group, Inc., 2000  Terms of use are as specified in license.txt#include "memsrc.h"      // this module#include <string.h>      // memcpy#include "xassert.h"     // xassert#include "typ.h"         // SELFCHECK, min//#define min(a,b) ((a)<(b)?(a):(b))MemoryInputSource::MemoryInputSource(char const *D, int L)  : data(D),    dataLen(L),    next(D){  selfCheck();    // check ctor arguments}// check invariantsvoid MemoryInputSource::selfCheck() const{  xassert(data != NULL &&          dataLen >= 0 &&          0 <= (next-data) &&               (next-data) <= dataLen);}int MemoryInputSource::read(char *buffer, int bufLen){  SELFCHECK();  // compute # of bytes to copy  int rem = remaining();  int supply = mymin(rem, bufLen);  // copy bytes  if (supply > 0) {    memcpy(buffer, next, supply);    // consume bytes    next += supply;  }  SELFCHECK();  return supply;}int MemoryInputSource::remaining() const{  return dataLen - (next-data);}

⌨️ 快捷键说明

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