xref: /freebsd/sys/contrib/ncsw/inc/stdlib_ext.h (revision c2c014f24c10f90d85126ac5fbd4d8524de32b1c)
1*852ba100SJustin Hibbits /*
2*852ba100SJustin Hibbits  * Copyright 2008-2012 Freescale Semiconductor Inc.
30aeed3e9SJustin Hibbits  *
40aeed3e9SJustin Hibbits  * Redistribution and use in source and binary forms, with or without
50aeed3e9SJustin Hibbits  * modification, are permitted provided that the following conditions are met:
60aeed3e9SJustin Hibbits  *     * Redistributions of source code must retain the above copyright
70aeed3e9SJustin Hibbits  *       notice, this list of conditions and the following disclaimer.
80aeed3e9SJustin Hibbits  *     * Redistributions in binary form must reproduce the above copyright
90aeed3e9SJustin Hibbits  *       notice, this list of conditions and the following disclaimer in the
100aeed3e9SJustin Hibbits  *       documentation and/or other materials provided with the distribution.
110aeed3e9SJustin Hibbits  *     * Neither the name of Freescale Semiconductor nor the
120aeed3e9SJustin Hibbits  *       names of its contributors may be used to endorse or promote products
130aeed3e9SJustin Hibbits  *       derived from this software without specific prior written permission.
140aeed3e9SJustin Hibbits  *
150aeed3e9SJustin Hibbits  *
160aeed3e9SJustin Hibbits  * ALTERNATIVELY, this software may be distributed under the terms of the
170aeed3e9SJustin Hibbits  * GNU General Public License ("GPL") as published by the Free Software
180aeed3e9SJustin Hibbits  * Foundation, either version 2 of that License or (at your option) any
190aeed3e9SJustin Hibbits  * later version.
200aeed3e9SJustin Hibbits  *
210aeed3e9SJustin Hibbits  * THIS SOFTWARE IS PROVIDED BY Freescale Semiconductor ``AS IS'' AND ANY
220aeed3e9SJustin Hibbits  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
230aeed3e9SJustin Hibbits  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
240aeed3e9SJustin Hibbits  * DISCLAIMED. IN NO EVENT SHALL Freescale Semiconductor BE LIABLE FOR ANY
250aeed3e9SJustin Hibbits  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
260aeed3e9SJustin Hibbits  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
270aeed3e9SJustin Hibbits  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
280aeed3e9SJustin Hibbits  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
290aeed3e9SJustin Hibbits  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
300aeed3e9SJustin Hibbits  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
310aeed3e9SJustin Hibbits  */
320aeed3e9SJustin Hibbits 
330aeed3e9SJustin Hibbits 
340aeed3e9SJustin Hibbits #ifndef __STDLIB_EXT_H
350aeed3e9SJustin Hibbits #define __STDLIB_EXT_H
360aeed3e9SJustin Hibbits 
370aeed3e9SJustin Hibbits 
380aeed3e9SJustin Hibbits #if (defined(NCSW_LINUX)) && defined(__KERNEL__)
390aeed3e9SJustin Hibbits #include "stdarg_ext.h"
400aeed3e9SJustin Hibbits #include "std_ext.h"
410aeed3e9SJustin Hibbits 
420aeed3e9SJustin Hibbits 
430aeed3e9SJustin Hibbits /**
440aeed3e9SJustin Hibbits  * strtoul - convert a string to an uint32_t
450aeed3e9SJustin Hibbits  * @cp: The start of the string
460aeed3e9SJustin Hibbits  * @endp: A pointer to the end of the parsed string will be placed here
470aeed3e9SJustin Hibbits  * @base: The number base to use
480aeed3e9SJustin Hibbits  */
490aeed3e9SJustin Hibbits uint32_t strtoul(const char *cp,char **endp,uint32_t base);
500aeed3e9SJustin Hibbits 
510aeed3e9SJustin Hibbits /**
520aeed3e9SJustin Hibbits  * strtol - convert a string to a int32_t
530aeed3e9SJustin Hibbits  * @cp: The start of the string
540aeed3e9SJustin Hibbits  * @endp: A pointer to the end of the parsed string will be placed here
550aeed3e9SJustin Hibbits  * @base: The number base to use
560aeed3e9SJustin Hibbits  */
570aeed3e9SJustin Hibbits long strtol(const char *cp,char **endp,uint32_t base);
580aeed3e9SJustin Hibbits 
590aeed3e9SJustin Hibbits /**
600aeed3e9SJustin Hibbits  * strtoull - convert a string to an uint64_t
610aeed3e9SJustin Hibbits  * @cp: The start of the string
620aeed3e9SJustin Hibbits  * @endp: A pointer to the end of the parsed string will be placed here
630aeed3e9SJustin Hibbits  * @base: The number base to use
640aeed3e9SJustin Hibbits  */
650aeed3e9SJustin Hibbits uint64_t strtoull(const char *cp,char **endp,uint32_t base);
660aeed3e9SJustin Hibbits 
670aeed3e9SJustin Hibbits /**
680aeed3e9SJustin Hibbits  * strtoll - convert a string to a int64 long
690aeed3e9SJustin Hibbits  * @cp: The start of the string
700aeed3e9SJustin Hibbits  * @endp: A pointer to the end of the parsed string will be placed here
710aeed3e9SJustin Hibbits  * @base: The number base to use
720aeed3e9SJustin Hibbits  */
730aeed3e9SJustin Hibbits long long strtoll(const char *cp,char **endp,uint32_t base);
740aeed3e9SJustin Hibbits 
750aeed3e9SJustin Hibbits /**
760aeed3e9SJustin Hibbits  * atoi - convert a character to a int
770aeed3e9SJustin Hibbits  * @s: The start of the string
780aeed3e9SJustin Hibbits  */
790aeed3e9SJustin Hibbits int atoi(const char *s);
800aeed3e9SJustin Hibbits 
810aeed3e9SJustin Hibbits /**
820aeed3e9SJustin Hibbits  * strnlen - Find the length of a length-limited string
830aeed3e9SJustin Hibbits  * @s: The string to be sized
840aeed3e9SJustin Hibbits  * @count: The maximum number of bytes to search
850aeed3e9SJustin Hibbits  */
860aeed3e9SJustin Hibbits size_t strnlen(const char * s, size_t count);
870aeed3e9SJustin Hibbits 
880aeed3e9SJustin Hibbits /**
890aeed3e9SJustin Hibbits  * strlen - Find the length of a string
900aeed3e9SJustin Hibbits  * @s: The string to be sized
910aeed3e9SJustin Hibbits  */
920aeed3e9SJustin Hibbits size_t strlen(const char * s);
930aeed3e9SJustin Hibbits 
940aeed3e9SJustin Hibbits /**
950aeed3e9SJustin Hibbits  * strtok - Split a string into tokens
960aeed3e9SJustin Hibbits  * @s: The string to be searched
970aeed3e9SJustin Hibbits  * @ct: The characters to search for
980aeed3e9SJustin Hibbits  *
990aeed3e9SJustin Hibbits  * WARNING: strtok is deprecated, use strsep instead.
1000aeed3e9SJustin Hibbits  */
1010aeed3e9SJustin Hibbits char * strtok(char * s,const char * ct);
1020aeed3e9SJustin Hibbits 
1030aeed3e9SJustin Hibbits /**
1040aeed3e9SJustin Hibbits  * strncpy - Copy a length-limited, %NUL-terminated string
1050aeed3e9SJustin Hibbits  * @dest: Where to copy the string to
1060aeed3e9SJustin Hibbits  * @src: Where to copy the string from
1070aeed3e9SJustin Hibbits  * @count: The maximum number of bytes to copy
1080aeed3e9SJustin Hibbits  *
1090aeed3e9SJustin Hibbits  * Note that unlike userspace strncpy, this does not %NUL-pad the buffer.
1100aeed3e9SJustin Hibbits  * However, the result is not %NUL-terminated if the source exceeds
1110aeed3e9SJustin Hibbits  * @count bytes.
1120aeed3e9SJustin Hibbits  */
1130aeed3e9SJustin Hibbits char * strncpy(char * dest,const char *src,size_t count);
1140aeed3e9SJustin Hibbits 
1150aeed3e9SJustin Hibbits /**
1160aeed3e9SJustin Hibbits  * strcpy - Copy a %NUL terminated string
1170aeed3e9SJustin Hibbits  * @dest: Where to copy the string to
1180aeed3e9SJustin Hibbits  * @src: Where to copy the string from
1190aeed3e9SJustin Hibbits  */
1200aeed3e9SJustin Hibbits char * strcpy(char * dest,const char *src);
1210aeed3e9SJustin Hibbits 
1220aeed3e9SJustin Hibbits /**
1230aeed3e9SJustin Hibbits  * vsscanf - Unformat a buffer into a list of arguments
1240aeed3e9SJustin Hibbits  * @buf:    input buffer
1250aeed3e9SJustin Hibbits  * @fmt:    format of buffer
1260aeed3e9SJustin Hibbits  * @args:    arguments
1270aeed3e9SJustin Hibbits  */
1280aeed3e9SJustin Hibbits int vsscanf(const char * buf, const char * fmt, va_list args);
1290aeed3e9SJustin Hibbits 
1300aeed3e9SJustin Hibbits /**
1310aeed3e9SJustin Hibbits  * vsnprintf - Format a string and place it in a buffer
1320aeed3e9SJustin Hibbits  * @buf: The buffer to place the result into
1330aeed3e9SJustin Hibbits  * @size: The size of the buffer, including the trailing null space
1340aeed3e9SJustin Hibbits  * @fmt: The format string to use
1350aeed3e9SJustin Hibbits  * @args: Arguments for the format string
1360aeed3e9SJustin Hibbits  *
1370aeed3e9SJustin Hibbits  * Call this function if you are already dealing with a va_list.
1380aeed3e9SJustin Hibbits  * You probably want snprintf instead.
1390aeed3e9SJustin Hibbits  */
1400aeed3e9SJustin Hibbits int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
1410aeed3e9SJustin Hibbits 
1420aeed3e9SJustin Hibbits /**
1430aeed3e9SJustin Hibbits  * vsprintf - Format a string and place it in a buffer
1440aeed3e9SJustin Hibbits  * @buf: The buffer to place the result into
1450aeed3e9SJustin Hibbits  * @fmt: The format string to use
1460aeed3e9SJustin Hibbits  * @args: Arguments for the format string
1470aeed3e9SJustin Hibbits  *
1480aeed3e9SJustin Hibbits  * Call this function if you are already dealing with a va_list.
1490aeed3e9SJustin Hibbits  * You probably want sprintf instead.
1500aeed3e9SJustin Hibbits  */
1510aeed3e9SJustin Hibbits int vsprintf(char *buf, const char *fmt, va_list args);
1520aeed3e9SJustin Hibbits 
1530aeed3e9SJustin Hibbits #elif defined(NCSW_FREEBSD)
1540aeed3e9SJustin Hibbits #include <sys/param.h>
1550aeed3e9SJustin Hibbits #include <sys/kernel.h>
1560aeed3e9SJustin Hibbits #include <sys/libkern.h>
1570aeed3e9SJustin Hibbits 
1580aeed3e9SJustin Hibbits #else
1590aeed3e9SJustin Hibbits #include <stdlib.h>
1600aeed3e9SJustin Hibbits #include <stdio.h>
1610aeed3e9SJustin Hibbits #endif /* defined(NCSW_LINUX) && defined(__KERNEL__) */
1620aeed3e9SJustin Hibbits 
1630aeed3e9SJustin Hibbits #include "std_ext.h"
1640aeed3e9SJustin Hibbits 
1650aeed3e9SJustin Hibbits 
1660aeed3e9SJustin Hibbits #endif /* __STDLIB_EXT_H */
167