示例#1
0
int private_vstream_gets(ACL_VSTREAM *stream, void *vptr, size_t maxlen)
{
	int   n, ch;
	unsigned char *ptr;

	if (stream == NULL || vptr == NULL || maxlen <= 0)
		return (ACL_VSTREAM_EOF);

	stream->flag &= ~ACL_VSTREAM_FLAG_TAGYES;

	ptr = (unsigned char *) vptr;
	for (n = 1; n < (int) maxlen; n++) {  /* left one byte for '\0' */
		ch = private_vstream_getc(stream);
		if (ch == ACL_VSTREAM_EOF) {
			if (n == 1)
				return (ACL_VSTREAM_EOF);/* EOF, nodata read */
			break;		/* EOF, some data was read */
		} else {
			*ptr++ = ch;
			if (ch == '\n'){	/* newline is stored, like fgets() */
				stream->flag |= ACL_VSTREAM_FLAG_TAGYES;
				break;
			}
		}
	}

	*ptr = 0;				/* null terminate like fgets() */
	return (n);
}
示例#2
0
int private_vstream_readn(ACL_VSTREAM *stream, void *vptr, size_t maxlen)
{
	int   n, ch;
	unsigned char *ptr;

	if (stream == NULL || vptr == NULL || (int) maxlen <= 0)
		return (ACL_VSTREAM_EOF);

	ptr = (unsigned char *) vptr;
	for (n = 0; n < (int) maxlen; n++) {
		ch = private_vstream_getc(stream);
		if (ch == ACL_VSTREAM_EOF) {
			if (n == 0)
				return (ACL_VSTREAM_EOF); /* EOF, nodata read */
			else
				break;		/* EOF, some data was read */
		} else {
			*ptr++ = ch;
		}
	}

	if (n != (int) maxlen) {
		snprintf(stream->errbuf, sizeof(stream->errbuf),
			"nread=%d, nneed=%d, errmsg=not read the needed data",
			n, (int) maxlen);
		stream->flag |= ACL_VSTREAM_FLAG_RDSHORT;

		return (ACL_VSTREAM_EOF);
	}

	return (n);
}
示例#3
0
int private_vstream_gets_nonl(ACL_VSTREAM *stream, void *vptr, size_t maxlen)
{
	int   n, ch;
	unsigned char *ptr;

	if (stream == NULL || vptr == NULL || maxlen <= 0)
		return (ACL_VSTREAM_EOF);

	ptr = (unsigned char *) vptr;
	for (n = 1; n < (int) maxlen; n++) {
		ch = private_vstream_getc(stream);
		if (ch == ACL_VSTREAM_EOF) {
			stream->flag &= ~ACL_VSTREAM_FLAG_TAGYES;
			stream->flag |= ACL_VSTREAM_FLAG_TAGNO;
			if (n == 1)
				return (ACL_VSTREAM_EOF);  /* EOF, nodata read */
			else
				break;		/* EOF, some data was read */
		} else {
			*ptr++ = ch;
			if (ch == '\n') {
				stream->flag |= ACL_VSTREAM_FLAG_TAGYES;
				stream->flag &= ~ACL_VSTREAM_FLAG_TAGNO;
				break;		/* newline is stored, like fgets() */
			}
		}
	}

	*ptr = 0;				/* null terminate like fgets() */
	ptr--;
	while (ptr >= (unsigned char *) vptr) {
		if (*ptr == '\r' || *ptr == '\n') {
			*ptr-- = 0;
			n--;
			continue;
		}
		break;
	}
	return (n);
}