예제 #1
0
static int __sys_getc(ACL_VSTREAM *stream)
{
	stream->read_cnt = __vstream_sys_read(stream);
	if (stream->read_cnt <= 0)
		return (ACL_VSTREAM_EOF);
	else
		return (ACL_VSTREAM_GETC(stream));
}
예제 #2
0
파일: main.cpp 프로젝트: LazyPlanet/acl
static int test_vstream(void)
{
	const char *filename = "test.txt";
	ACL_VSTREAM *fp = acl_vstream_fopen(filename, O_RDWR | O_CREAT, 0644, 1024);
	struct acl_stat sbuf;
	char  buf[256];
	struct tm *local_time;

	acl_lib_init();

	if (fp == NULL) {
		printf("open file(%s) error(%s)\r\n", filename, acl_last_serror());
		end();
		return (-1);
	}

	if (acl_vstream_fstat(fp, &sbuf) < 0) {
		acl_vstream_close(fp);
		printf("fstat file(%s) error(%s)\r\n", filename, acl_last_serror());
		end();
		return (-1);
	}

	printf("file(%s) stat:\r\n", filename);

	printf("size=%d\r\n", (int) sbuf.st_size);

	local_time = localtime(&sbuf.st_mtime);
	if (local_time) {
		strftime(buf, sizeof(buf), "%Y/%m/%d %H:%M:%S", local_time);
		printf("修改时间,mtime=%s\r\n", buf);
	} else {
		printf("mtime: error(%s)\r\n", acl_last_serror());
	}

	local_time = localtime(&sbuf.st_ctime);
	if (local_time) {
		strftime(buf, sizeof(buf), "%Y/%m/%d %H:%M:%S", local_time);
		printf("创建时间,ctime=%s\r\n", buf);
	} else {
		printf("ctime: error(%s)\r\n", acl_last_serror());
	}

	local_time = localtime(&sbuf.st_atime);
	if (local_time) {
		strftime(buf, sizeof(buf), "%Y/%m/%d %H:%M:%S", local_time);
		printf("访问时间,atime=%s\r\n", buf);
	} else {
		printf("atime: error(%s)\r\n", acl_last_serror());
	}

	int  ch, ch1;

	ch = ACL_VSTREAM_GETC(fp);
	ch = 'a';

	for (int i = 0; i < 100; i++) {
		ch1 = ACL_VSTREAM_PUTC(ch, fp);
		assert(ch1 == ch);
		printf("ok write char: %c\n", ch1);
	}
	ACL_VSTREAM_PUTC('\n', fp);
	acl_vstream_fclose(fp);
	end();	

	FILE *fp1 = fopen("test.txt", "w+");
	assert(fp1);
	int ret = fputs("hello", fp1);
	printf("ret: %d\n", ret);
	fclose(fp1);
	return (0);
}