Exemple #1
0
/**
 * cdk_stream_read: Try to read count bytes from the STREAM object.
 * @s: The STREAM object.
 * @buf: The buffer to insert the readed bytes.
 * @count: Request so much bytes.
 *
 * When this function is called the first time, it can take a while
 * because all filters need to be processed. Please remember that you
 * need to add the filters in reserved order.
 **/
int
cdk_stream_read( cdk_stream_t s, void * buf, size_t count )
{
    int nread;
    int rc;

    if( !s )
        return EOF;
    
    if( s->flags.write && !s->flags.temp )
        return EOF; /* this is a write stream */
  
    if( !s->flags.no_filter && !s->cache.on && !s->flags.filtrated ) {
        rc = stream_filter_read( s );
        if( rc ) {
            s->error = rc;
            return EOF;
        }
        s->flags.filtrated = 1;
    }
    if( !buf && !count )
        return 0;
    nread = fread( buf, 1, count, s->fp );  
    if( !nread )
        nread = EOF;
    if( feof( s->fp ) )
        s->flags.eof = 1;
    return nread;
}
Exemple #2
0
/**
 * cdk_stream_read: 
 * @s: The STREAM object.
 * @buf: The buffer to insert the readed bytes.
 * @count: Request so much bytes.
 *
 * Tries to read count bytes from the STREAM object.
 * When this function is called the first time, it can take a while
 * because all filters need to be processed. Please remember that you
 * need to add the filters in reserved order.
 **/
int
cdk_stream_read (cdk_stream_t s, void *buf, size_t buflen)
{
  int nread;
  int rc;

  if (!s)
    {
      s->error = CDK_Inv_Value;
      gnutls_assert();
      return EOF;
    }

  if (s->cbs_hd)
    {
      if (s->cbs.read)
	return s->cbs.read (s->cbs_hd, buf, buflen);
      return 0;
    }

  if (s->flags.write && !s->flags.temp)
    {
      s->error = CDK_Inv_Mode;
      gnutls_assert();
      return EOF;		/* This is a write stream */
    }

  if (!s->flags.no_filter && !s->cache.on && !s->flags.filtrated)
    {
      rc = stream_filter_read (s);
      if (rc)
	{
	  s->error = rc;
	  if (feof (s->fp))
	    s->flags.eof = 1;
          gnutls_assert();
	  return EOF;
	}
      s->flags.filtrated = 1;
    }

  if (!buf && !buflen)
    return 0;

  nread = fread (buf, 1, buflen, s->fp);
  if (!nread)
    nread = EOF;

  if (feof (s->fp))
    {
      s->error = 0;
      s->flags.eof = 1;
    }
  return nread;
}