Skip to content
Snippets Groups Projects
Forked from openldap / OpenLDAP
21002 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
io.c 13.05 KiB
/* io.c - ber general i/o routines */
/* $OpenLDAP$ */
/*
 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
 */
/* Portions
 * Copyright (c) 1990 Regents of the University of Michigan.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the University of Michigan at Ann Arbor. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
 */

#include "portable.h"

#include <stdio.h>

#include <ac/stdlib.h>

#include <ac/ctype.h>
#include <ac/errno.h>
#include <ac/socket.h>
#include <ac/string.h>
#include <ac/unistd.h>

#ifdef HAVE_IO_H
#include <io.h>
#endif

#include "lber-int.h"

static ber_slen_t BerRead LDAP_P((
	Sockbuf *sb,
	char *buf,
	ber_len_t len ));

#define EXBUFSIZ	1024

/* probably far too large... */
#define MAX_BERBUFSIZE	(128*1024)

#if defined( DOS ) && !defined( _WIN32 ) && (MAX_BERBUFSIZE > 65535)
# undef MAX_BERBUFSIZE
# define MAX_BERBUFSIZE 65535
#endif

static ber_slen_t
BerRead(
	Sockbuf *sb,
	char *buf,
	ber_len_t len )
{
	ber_slen_t	c;
	ber_slen_t	nread = 0;

	assert( sb != NULL );
	assert( buf != NULL );

	assert( SOCKBUF_VALID( sb ) );

	while ( len > 0 ) {
		if ( (c = ber_pvt_sb_read( sb, buf, len )) <= 0 ) {
			if ( nread > 0 )
				break;
			return( c );