string/string.c
/*
 * read until EOF or when blocking is set to 0 until EWOULDBLOCK
 */
read until EOF or when blocking is set to 0 until EWOULDBLOCK
read until EOF or when blocking is set to 0 until EWOULDBLOCK
void
StringBuffer_fdload(StringBuffer* buffer, int fd, size_t read_size)
{
	if (read_size == 0)
	{
		STRING_BUFFER_WARN(buffer, "read size 0");
		return;
	}
	size_t nread_total = 0;
	ssize_t nread;
	ssize_t read_size_original = read_size % READ_SIZE_MAX;
	ssize_t read_size_actual = read_size_original;
	while ((nread = StringBuffer_fdncat(buffer, fd, read_size_actual)) > 0)
	{
		nread_total += (size_t)nread;
		if (nread > 0 && nread < read_size_actual)
		{
			size_t nunused = StringBuffer_unused(buffer);
			if ((size_t)read_size_actual > nunused)
			{
				ssize_t chunk_size_reduced = (ssize_t)nunused;
				STRING_BUFFER_FDBG(buffer, "reduced read size (%zu --> %zu)",
						   read_size_actual, chunk_size_reduced);
				read_size_actual = chunk_size_reduced;
			}
		}
	}
	STRING_BUFFER_FDBG(buffer, "total bytes read %zu", nread_total);
}
void StringBuffer_fdload ( StringBuffer * buffer , int fd , size_t read_size ) { if ( read_size == 0 ) { STRING_BUFFER_WARN ( buffer , " " ) ; return ; } size_t nread_total = 0 ; ssize_t nread ; ssize_t read_size_original = read_size % READ_SIZE_MAX ; ssize_t read_size_actual = read_size_original ; while ( ( nread = StringBuffer_fdncat ( buffer , fd , read_size_actual ) ) > 0 ) { nread_total += ( size_t ) nread ; if ( nread > 0 && nread < read_size_actual ) { size_t nunused = StringBuffer_unused ( buffer ) ; if ( ( size_t ) read_size_actual > nunused ) { ssize_t chunk_size_reduced = ( ssize_t ) nunused ; STRING_BUFFER_FDBG ( buffer , " " , read_size_actual , chunk_size_reduced ) ; read_size_actual = chunk_size_reduced ; } } } STRING_BUFFER_FDBG ( buffer , " " , nread_total ) ; }
read until EOF or when blocking is set to 0 until EWOULDBLOCK
read until EOF or when blocking is set to 0 until EWOULDBLOCK
/* read until EOF or until an error occurs */ /* from 'man 2 read'
		 * "If read returns at least one character, there is no way you can tell whether end-of-file was reached.
		 * But if you did reach the end, the next read will return zero."
		 *
		 * Reduce read size to remaining buffer length if
		 * actual characters read < read size
		 */