RSA BSAFE Crypto-C

Cryptographic Components for C

Search

tstdlib.c

/* $Id: tstdlib.c,v 1.7.4.2 2005/02/21 03:01:42 qviet Exp $ */
/*
 * Copyright (C) 1998-2005 RSA Security Inc.
 *
 * This file shall only be used to demonstrate how to interface to an
 * RSA Security Inc. licensed development product.
 *
 * You have a royalty-free right to use, reproduce and distribute this
 * demonstration file, provided that you agree that RSA Security Inc.
 * has no warranty, implied or otherwise, or liability for this
 * demonstration file (including any modified version).  This software
 * is provided "as is" without warranties or representations of any
 * kind. RSA Security disclaims all conditions and warranties, statutory
 * and otherwise, both express and implied, with respect to the software,
 * its quality and performance, including but not limited to, all
 * implied warranties of merchantability, fitness for a particular
 * purpose, title and noninfringement of third party rights. Without
 * limiting the foregoing, RSA Security does not warrant that the
 * software is error-free or that errors in the product will be
 * corrected. You agree that RSA Security shall not be liable for any
 * direct, indirect, incidental, special, consequential, punitive or
 * other damages whatsoever resulting from your use of this software
 * or any modified version.
 *
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "aglobal.h"
#include "bsafe.h"

/* If the standard C library comes with a memmove() that correctly
     handles overlapping buffers, MEMMOVE_PRESENT should be defined as
     1, else 0.
   The following defines MEMMOVE_PRESENT as 1 if it has not already been
     defined as 0 with C compiler flags.
 */
#ifndef MEMMOVE_PRESENT
#define MEMMOVE_PRESENT 1
#endif

void CALL_CONV T_memset(POINTER p, int c, unsigned int count)
{
  if (count != 0)
    memset (p, c, count);
}

void CALL_CONV T_memcpy(POINTER d, POINTER s, unsigned int count)
{
  if (count != 0)
    memcpy (d, s, count);
}

void CALL_CONV T_memmove(POINTER d, POINTER s, unsigned int count)
{
#if MEMMOVE_PRESENT
  if (count != 0)
    memmove (d, s, count);
#else
  unsigned int i;

  if ((char *)d == (char *)s)
    return;
  else if ((char *)d > (char *)s) {
    for (i = count; i > 0; i--)
      ((char *)d)[i-1] = ((char *)s)[i-1];
  }
  else {
    for (i = 0; i < count; i++)
      ((char *)d)[i] = ((char *)s)[i];
  }
#endif
}

int CALL_CONV T_memcmp(POINTER s1, POINTER s2, unsigned int count)
{
  if (count == 0)
    return (0);
  else
    return (memcmp (s1, s2, count));
}

POINTER CALL_CONV T_malloc(unsigned int size)
{
  return ((POINTER)malloc (size == 0 ? 1 : size));
}

POINTER CALL_CONV T_realloc(POINTER p, unsigned int size)
{
  return ((POINTER)realloc (p, size == 0 ? 1 : size));
}

void CALL_CONV T_free(POINTER p)
{
  if (p != NULL_PTR)
    free (p);
}


unsigned int CALL_CONV T_strlen(char *p)
{
    return strlen(p);
}

void CALL_CONV T_strcpy(char *dest, char *src)
{
    strcpy(dest, src);
}

int CALL_CONV T_strcmp(char *a, char *b)
{
  return (strcmp (a, b));
}



Copyright (c) 1999-2005 RSA Security Inc. All rights reserved. 068-001001-6210-001-000 - 6.2.1