1 #/* @file
2 #  Copyright (c) 2018, Linaro Limited. All rights reserved.
3 #
4 #  SPDX-License-Identifier: BSD-2-Clause-Patent
5 #
6 #*/
7 
8 #include <Base.h>
9 #include <Library/BaseLib.h>
10 #include <Library/DebugLib.h>
11 
strtoul(const char * nptr,char ** endptr,int base)12 unsigned long strtoul(const char *nptr, char **endptr, int base)
13 {
14     RETURN_STATUS   Status;
15     UINTN           ReturnValue;
16 
17     ASSERT (base == 10 || base == 16);
18 
19     if (base == 10) {
20       Status = AsciiStrDecimalToUintnS (nptr, endptr, &ReturnValue);
21     } else if (base == 16) {
22       Status = AsciiStrHexToUintnS (nptr, endptr, &ReturnValue);
23     } else {
24       Status = RETURN_INVALID_PARAMETER;
25     }
26 
27     if (RETURN_ERROR (Status)) {
28       return MAX_UINTN;
29     }
30 
31     return ReturnValue;
32 }
33