source: trunk/kernel/libk/string.h @ 458

Last change on this file since 458 was 457, checked in by alain, 6 years ago

This version modifies the exec syscall and fixes a large number of small bugs.
The version number has been updated (0.1)

File size: 7.7 KB
RevLine 
[1]1/*
2 * string.h - string related helper functions definition.
3 *
4 * Authors      Ghassan Almaless (2007,2009,2010,2011,2012)
5 *              Alain Greiner (2017)
6 *
7 * Copyright (c) UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef _STRING_H_
26#define _STRING_H_
27
[457]28#include <hal_kernel_types.h>
[1]29
30
31/********************************************************************************************
32 * This function returns the length of a character string.
33 ********************************************************************************************
34 * @ s     : pointer on the string.
35 * @ return the number of characters preceding the NUL character.
36 *******************************************************************************************/
37uint32_t strlen( const char * s );
38
39/********************************************************************************************
40 * This function attempts to compute the length of a string, but never scans beyond
41 * <maxlen> characters.
42 ********************************************************************************************
43 * @ s     : pointer on the string.
44 * returns min( maxlen , number of characters preceding the NUL character).
45 *******************************************************************************************/
46uint32_t strnlen( const char * str, 
47                  uint32_t     maxlen );
48
49/********************************************************************************************
50 * This function compares lexicographically the strind s1 and s2.
51 * characters are considered unsigned.
52 * I does not compare characters after the first NUL character.
53 ********************************************************************************************
54 * @ s1   : pointer on string.
55 * @ s2   : pointer on string.
56 * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2
57 *******************************************************************************************/
58int strcmp ( const char * s1, 
59             const char * s2 );
60
61/********************************************************************************************
62 * This function compares lexicographically the strind s1 and s2.
63 * I does not compare than <n> characters and stops after the first NUL character.
64 ********************************************************************************************
65 * @ s1   : pointer on string.
66 * @ s2   : pointer on string.
67 * @ n    : max number of compared characters.
68 * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2
69 *******************************************************************************************/
70int strncmp ( const char * s1,
71              const char * s2,
72              uint32_t     n );
73
74/********************************************************************************************
75 * This function compares lexicographically the strind s1 and s2, ignoring case.
76 ********************************************************************************************
77 * @ s1   : pointer on string.
78 * @ s2   : pointer on string.
79 * @ return 0 if s1 == s2 / return 1 if s1 > s2 / return -1 if s1 < s2
80 *******************************************************************************************/
81int strcasecmp ( const char * s1,
82                 const char * s2 );
83
84/********************************************************************************************
[23]85 * this function copies the <src> buffer to the <dst> buffer, including the terminating NUL.
[1]86 ********************************************************************************************
[23]87 * @ dst   : pointer on destination buffer.
88 * @ src   : pointer on source buffer.
[1]89 *******************************************************************************************/
[23]90char * strcpy ( char * dst, 
[1]91                char * src );
92
93/********************************************************************************************
[23]94 * This function copies <n> characters from the <sr> buffer to the <dst> buffer.
[1]95 ********************************************************************************************
[23]96 * @ dst   : pointer on destination buffer.
97 * @ src   : pointer on source buffer.
98 * @ n     : number of characters to be copied.
[1]99 *******************************************************************************************/
[23]100char * strncpy ( char    * dst,
[1]101                 char    * src,
102                 uint32_t  n );
103
104/********************************************************************************************
[323]105 * This function locates the first occurence of the <find> string in the <s> string.
106 ********************************************************************************************
107 * @ s     : string to be analysed.
108 * @ find  : searched string
109 * @ return pointer on the found string / return NULL if not found.
110 *******************************************************************************************/
111char * strstr( char       * s,
112               const char * find);
113
114/********************************************************************************************
[23]115 * This function locates the first occurence of the <c> character in the <s> string.
[1]116 ********************************************************************************************
[23]117 * @ s     : string to be analysed.
118 * @ c     : searched character value (casted to a char)
119 * @ return pointer on the found character / return NULL if not found.
[1]120 *******************************************************************************************/
121char * strchr ( const char * s,
122                int          c );
123
124/********************************************************************************************
[23]125 * This function locates the last occurence of the <c> character in the <s> string.
[1]126 ********************************************************************************************
[23]127 * @ s     : string to be analysed.
128 * @ c     : searched character value (casted to a char)
129 * @ return pointer on the found character / return NULL if not found.
[1]130 *******************************************************************************************/
131char * strrchr ( const char * t,
132                 int          c );
133
[238]134/********************************************************************************************
135 * This function returns a lower case ASCII code if input is in [A...Z] range.
136 ********************************************************************************************
137 * @ c     : character to be forced to lower case.
138 * @ return lower case ASCII code.
139 *******************************************************************************************/
140inline uint8_t to_lower( uint8_t  c );
141
142/********************************************************************************************
143 * This function returns an upper case ASCII code if input is in [a...z] range.
144 ********************************************************************************************
145 * @ c     : character to be forced to upper case.
146 * @ return upper case ASCII code.
147 *******************************************************************************************/
148inline uint8_t to_upper( uint8_t  c );
149
[1]150#endif  /* _STRING_H_ */
Note: See TracBrowser for help on using the repository browser.