summaryrefslogtreecommitdiff
path: root/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/CrtWrapper.c
blob: 051a67dc7a6bc037482ac770ef03b2976340a4ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/** @file
  C Run-Time Libraries (CRT) Wrapper Implementation for MbedTLS-based
  Cryptographic Library.

Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include <Base.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <stdio.h>

/**dummy mbedtls_printf function. **/
int
mbedtls_printf (
  char const  *fmt,
  ...
  )
{
  ASSERT (FALSE);
  return 0;
}

/**dummy mbedtls_vsnprintf function. **/
int
mbedtls_vsnprintf (
  char        *str,
  size_t      size,
  const char  *format,
  ...
  )
{
  ASSERT (FALSE);
  return 0;
}

/**strchr function. **/
char *
strchr (
  const char  *str,
  int         ch
  )
{
  return ScanMem8 (str, AsciiStrSize (str), (char)ch);
}

char *
strncpy (
  char        *strDest,
  const char  *strSource,
  size_t      count
  )
{
  UINTN  DestMax = MAX_STRING_SIZE;

  if (count < MAX_STRING_SIZE) {
    DestMax = count + 1;
  } else {
    count = MAX_STRING_SIZE-1;
  }

  AsciiStrnCpyS (strDest, DestMax, strSource, (UINTN)count);

  return strDest;
}

/**strcmp function. **/
int
strcmp (
  const char  *s1,
  const char  *s2
  )
{
  return (int)AsciiStrCmp (s1, s2);
}

/**strpbrk function. **/
char *
strpbrk (
  const char  *s,
  const char  *accept
  )
{
  int  i;

  for ( ; *s != '\0'; s++) {
    for (i = 0; accept[i] != '\0'; i++) {
      if (*s == accept[i]) {
        return (char *)s;
      }
    }
  }

  return NULL;
}