source: trunk/libs/mini-libc/string.h @ 662

Last change on this file since 662 was 619, checked in by alain, 6 years ago

1) Fix a bug in KSH : after the "load" command,

the [ksh] prompt is now printed after completion
of the loaded application.

2) Fix a bug in vmm_handle_cow() : the copy-on-write

use now a hal_remote_memcpy() to replicate the page content.


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