Ticket #51451: patch-tests-pkcs11-pkcs11-mock.c.2.diff

File patch-tests-pkcs11-pkcs11-mock.c.2.diff, 1.1 KB (added by help@…, 8 years ago)
  • tests/pkcs11/pkcs11-mock.c

    old new  
    1717#include "pkcs11-mock.h"
    1818#include <stdlib.h>
    1919
     20#ifdef __APPLE__
     21#ifndef __MAC_OS_X_VERSION_MIN_REQUIRED
     22#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1050
     23#include <Availability.h>
     24#else
     25#include <AvailabilityMacros.h>
     26#endif
     27#endif
     28#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1060
     29#define strndup osx_strndup
     30#define strnlen osx_strnlen
     31
     32static size_t
     33osx_strnlen (const char *string, size_t maxlen)
     34{
     35  const char *end = memchr (string, '\0', maxlen);
     36  return end ? (size_t) (end - string) : maxlen;
     37}
     38
     39static char *
     40osx_strndup (char const *s, size_t n)
     41{
     42  size_t len = strnlen (s, n);
     43  char *new = malloc (len + 1);
     44
     45  if (new == NULL)
     46    return NULL;
     47
     48  new[len] = '\0';
     49  return memcpy (new, s, len);
     50}
     51#endif
     52#endif
     53
    2054/* This is a very basic mock PKCS #11 module that will return a given fixed
    2155 * certificate, and public key for all searches. It will also provide a
    2256 * CKO_X_CERTIFICATE_EXTENSION so that it can be used as a p11-kit trust