/*
* Copyright (c) 2004, 2005 Sendmail, Inc. and its suppliers.
* All rights reserved.
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the sendmail distribution.
*/
#include "sm/generic.h"
SM_RCSID("@(#)$Id: rcbputuint64.c,v 1.5 2007/10/23 03:56:31 ca Exp $")
#include "sm/assert.h"
#include "sm/magic.h"
#include "sm/error.h"
#include "sm/memops.h"
#include "sm/rpool.h"
#include "sm/limits.h"
#include "sm/rcb.h"
#include "sm/str-int.h"
#include "sm/str2rcb.h"
#include "sm/reccom.h"
/*
** SM_RCB_PUTUINT64 -- Append one uint64 to the end of a sm_rcb_P
**
** Parameters:
** rcb -- sm_rcb_P object to append onto.
** u -- uint64 value to append.
**
** Returns:
** usual sm_error code; ENOMEM, SM_E_OVFLW_SC, SM_E_OVFLW_NS
*/
sm_ret_T
sm_rcb_putuint64(sm_rcb_P rcb, uint64_t u)
{
uint nsize, l;
SM_IS_RCB(rcb);
l = sizeof(uint64_t);
nsize = rcb->sm_rcb_len + l;
/* overflow? */
if (nsize <= rcb->sm_rcb_len)
return sm_error_perm(SM_EM_RECCOM, SM_E_OVFLW_SC);
/* do we really want to do this? */
if (rcb->sm_rcb_rw >= 0 && (int)l > rcb->sm_rcb_rw)
return sm_error_perm(SM_EM_RECCOM, SM_E_FULL);
if (nsize > rcb->sm_rcb_size)
SM_STR_INCREASE_R(rcb, nsize);
sm_uint64_2buf(u, rcb->sm_rcb_base + rcb->sm_rcb_len);
rcb->sm_rcb_len += sizeof(uint64_t);
if (rcb->sm_rcb_rw >= 0)
rcb->sm_rcb_rw -= l;
return SM_SUCCESS;
}
syntax highlighted by Code2HTML, v. 0.9.1