xref: /freebsd/sys/contrib/ncsw/inc/stdlib_ext.h (revision 8aac90f18aef7c9eea906c3ff9a001ca7b94f375)
1 /*
2  * Copyright 2008-2012 Freescale Semiconductor Inc.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *     * Redistributions of source code must retain the above copyright
7  *       notice, this list of conditions and the following disclaimer.
8  *     * Redistributions in binary form must reproduce the above copyright
9  *       notice, this list of conditions and the following disclaimer in the
10  *       documentation and/or other materials provided with the distribution.
11  *     * Neither the name of Freescale Semiconductor nor the
12  *       names of its contributors may be used to endorse or promote products
13  *       derived from this software without specific prior written permission.
14  *
15  *
16  * ALTERNATIVELY, this software may be distributed under the terms of the
17  * GNU General Public License ("GPL") as published by the Free Software
18  * Foundation, either version 2 of that License or (at your option) any
19  * later version.
20  *
21  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
22  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
25  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 
34 #ifndef __STDLIB_EXT_H
35 #define __STDLIB_EXT_H
36 
37 
38 #if (defined(NCSW_LINUX)) && defined(__KERNEL__)
39 #include "stdarg_ext.h"
40 #include "std_ext.h"
41 
42 
43 /**
44  * strtoul - convert a string to an uint32_t
45  * @cp: The start of the string
46  * @endp: A pointer to the end of the parsed string will be placed here
47  * @base: The number base to use
48  */
49 uint32_t strtoul(const char *cp,char **endp,uint32_t base);
50 
51 /**
52  * strtol - convert a string to a int32_t
53  * @cp: The start of the string
54  * @endp: A pointer to the end of the parsed string will be placed here
55  * @base: The number base to use
56  */
57 long strtol(const char *cp,char **endp,uint32_t base);
58 
59 /**
60  * strtoull - convert a string to an uint64_t
61  * @cp: The start of the string
62  * @endp: A pointer to the end of the parsed string will be placed here
63  * @base: The number base to use
64  */
65 uint64_t strtoull(const char *cp,char **endp,uint32_t base);
66 
67 /**
68  * strtoll - convert a string to a int64 long
69  * @cp: The start of the string
70  * @endp: A pointer to the end of the parsed string will be placed here
71  * @base: The number base to use
72  */
73 long long strtoll(const char *cp,char **endp,uint32_t base);
74 
75 /**
76  * atoi - convert a character to a int
77  * @s: The start of the string
78  */
79 int atoi(const char *s);
80 
81 /**
82  * strnlen - Find the length of a length-limited string
83  * @s: The string to be sized
84  * @count: The maximum number of bytes to search
85  */
86 size_t strnlen(const char * s, size_t count);
87 
88 /**
89  * strlen - Find the length of a string
90  * @s: The string to be sized
91  */
92 size_t strlen(const char * s);
93 
94 /**
95  * strtok - Split a string into tokens
96  * @s: The string to be searched
97  * @ct: The characters to search for
98  *
99  * WARNING: strtok is deprecated, use strsep instead.
100  */
101 char * strtok(char * s,const char * ct);
102 
103 /**
104  * strncpy - Copy a length-limited, %NUL-terminated string
105  * @dest: Where to copy the string to
106  * @src: Where to copy the string from
107  * @count: The maximum number of bytes to copy
108  *
109  * Note that unlike userspace strncpy, this does not %NUL-pad the buffer.
110  * However, the result is not %NUL-terminated if the source exceeds
111  * @count bytes.
112  */
113 char * strncpy(char * dest,const char *src,size_t count);
114 
115 /**
116  * strcpy - Copy a %NUL terminated string
117  * @dest: Where to copy the string to
118  * @src: Where to copy the string from
119  */
120 char * strcpy(char * dest,const char *src);
121 
122 /**
123  * vsscanf - Unformat a buffer into a list of arguments
124  * @buf:    input buffer
125  * @fmt:    format of buffer
126  * @args:    arguments
127  */
128 int vsscanf(const char * buf, const char * fmt, va_list args);
129 
130 /**
131  * vsnprintf - Format a string and place it in a buffer
132  * @buf: The buffer to place the result into
133  * @size: The size of the buffer, including the trailing null space
134  * @fmt: The format string to use
135  * @args: Arguments for the format string
136  *
137  * Call this function if you are already dealing with a va_list.
138  * You probably want snprintf instead.
139  */
140 int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
141 
142 /**
143  * vsprintf - Format a string and place it in a buffer
144  * @buf: The buffer to place the result into
145  * @fmt: The format string to use
146  * @args: Arguments for the format string
147  *
148  * Call this function if you are already dealing with a va_list.
149  * You probably want sprintf instead.
150  */
151 int vsprintf(char *buf, const char *fmt, va_list args);
152 
153 #elif defined(NCSW_FREEBSD)
154 #include <sys/param.h>
155 #include <sys/kernel.h>
156 #include <sys/libkern.h>
157 
158 #else
159 #include <stdlib.h>
160 #include <stdio.h>
161 #endif /* defined(NCSW_LINUX) && defined(__KERNEL__) */
162 
163 #include "std_ext.h"
164 
165 
166 #endif /* __STDLIB_EXT_H */
167