#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define WRITE_BUFFER_SIZE 4096
static unsigned char write_buffer[WRITE_BUFFER_SIZE];
static unsigned char *bufptr;
static int flushbuffer(int size)
{
return 0;
}
static void bufwrite1(char *p, int n)
{
while(--n > 0)
{
if (bufptr == &write_buffer[WRITE_BUFFER_SIZE])
{
if (flushbuffer(WRITE_BUFFER_SIZE) != 0)
{
printf("flushbuffer failed \r\n");
}
bufptr = write_buffer;
}
*bufptr++ = *p++;
}
}
static void bufwrite(unsigned char *p, int n)
{
while (n > 0)
{
int k, rem;
if (bufptr == &write_buffer[WRITE_BUFFER_SIZE])
{
if (flushbuffer(WRITE_BUFFER_SIZE) != 0)
{
printf("flushbuffer failed \r\n");
}
bufptr = write_buffer;
}
rem = WRITE_BUFFER_SIZE - (bufptr - write_buffer);
k = n > rem ? rem : n;
memcpy(bufptr, p, k);
bufptr += k;
p += k;
n -= k;
}
}
int main(int argc, char *argv[])
{
printf("hello tyustli\r\n");
bufptr = write_buffer;
return 0;
}
C语言-一种写缓存区数组的方法
最新推荐文章于 2023-10-30 15:03:21 发布