Subversion Repositories HelenOS

Rev

Rev 4013 | Rev 4345 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4013 Rev 4014
Line 24... Line 24...
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup generic
29
/** @addtogroup generic
30
 * @{
30
 * @{
31
 */
31
 */
32
 
32
 
33
/**
33
/**
34
 * @file
34
 * @file
35
 * @brief   Miscellaneous functions.
35
 * @brief Miscellaneous functions.
36
 */
36
 */
37
 
37
 
38
#include <string.h>
38
#include <string.h>
39
#include <print.h>
39
#include <print.h>
40
#include <cpu.h>
40
#include <cpu.h>
Line 45... Line 45...
45
/** Return number of characters in a string.
45
/** Return number of characters in a string.
46
 *
46
 *
47
 * @param str NULL terminated string.
47
 * @param str NULL terminated string.
48
 *
48
 *
49
 * @return Number of characters in str.
49
 * @return Number of characters in str.
-
 
50
 *
50
 */
51
 */
51
size_t strlen(const char *str)
52
size_t strlen(const char *str)
52
{
53
{
53
    int i;
54
    int i;
54
   
55
   
55
    for (i = 0; str[i]; i++)
56
    for (i = 0; str[i]; i++);
56
        ;
-
 
57
   
57
   
58
    return i;
58
    return i;
59
}
59
}
60
 
60
 
61
/** Compare two NULL terminated strings
61
/** Compare two NULL terminated strings
Line 78... Line 78...
78
        if (*src > *dst)
78
        if (*src > *dst)
79
            return 1;
79
            return 1;
80
    }
80
    }
81
    if (*src == *dst)
81
    if (*src == *dst)
82
        return 0;
82
        return 0;
-
 
83
   
83
    if (!*src)
84
    if (!*src)
84
        return -1;
85
        return -1;
-
 
86
   
85
    return 1;
87
    return 1;
86
}
88
}
87
 
89
 
88
 
90
 
89
/** Compare two NULL terminated strings
91
/** Compare two NULL terminated strings
Line 105... Line 107...
105
    unsigned int i;
107
    unsigned int i;
106
   
108
   
107
    for (i = 0; (*src) && (*dst) && (i < len); src++, dst++, i++) {
109
    for (i = 0; (*src) && (*dst) && (i < len); src++, dst++, i++) {
108
        if (*src < *dst)
110
        if (*src < *dst)
109
            return -1;
111
            return -1;
-
 
112
       
110
        if (*src > *dst)
113
        if (*src > *dst)
111
            return 1;
114
            return 1;
112
    }
115
    }
-
 
116
   
113
    if (i == len || *src == *dst)
117
    if (i == len || *src == *dst)
114
        return 0;
118
        return 0;
-
 
119
   
115
    if (!*src)
120
    if (!*src)
116
        return -1;
121
        return -1;
-
 
122
   
117
    return 1;
123
    return 1;
118
}
124
}
119
 
125
 
120
 
126
 
121
 
127
 
Line 123... Line 129...
123
 *
129
 *
124
 * Copy at most 'len' characters from string 'src' to 'dest'.
130
 * Copy at most 'len' characters from string 'src' to 'dest'.
125
 * If 'src' is shorter than 'len', '\0' is inserted behind the
131
 * If 'src' is shorter than 'len', '\0' is inserted behind the
126
 * last copied character.
132
 * last copied character.
127
 *
133
 *
128
 * @param src Source string.
134
 * @param src  Source string.
129
 * @param dest Destination buffer.
135
 * @param dest Destination buffer.
130
 * @param len Size of destination buffer.
136
 * @param len  Size of destination buffer.
-
 
137
 *
131
 */
138
 */
132
void strncpy(char *dest, const char *src, size_t len)
139
void strncpy(char *dest, const char *src, size_t len)
133
{
140
{
134
    unsigned int i;
141
    unsigned int i;
135
 
142
   
136
    for (i = 0; i < len; i++) {
143
    for (i = 0; i < len; i++) {
137
        if (!(dest[i] = src[i]))
144
        if (!(dest[i] = src[i]))
138
            return;
145
            return;
139
    }
146
    }
140
 
147
   
141
    dest[i - 1] = '\0';
148
    dest[i - 1] = '\0';
142
}
149
}
143
 
150
 
144
/** Find first occurence of character in string.
151
/** Find first occurence of character in string.
145
 *
152
 *
146
 * @param s String to search.
153
 * @param s String to search.
147
 * @param i Character to look for.
154
 * @param i Character to look for.
148
 *
155
 *
149
 * @return  Pointer to character in @a s or NULL if not found.
156
 * @return Pointer to character in @a s or NULL if not found.
150
 */
157
 */
151
extern char *strchr(const char *s, int i)
158
extern char *strchr(const char *s, int i)
152
{
159
{
153
    while (*s != '\0') {
160
    while (*s != '\0') {
-
 
161
        if (*s == i)
154
        if (*s == i) return (char *) s;
162
            return (char *) s;
155
        ++s;
163
        ++s;
156
    }
164
    }
157
 
165
   
158
    return NULL;
166
    return NULL;
159
}
167
}
160
 
168
 
161
/** @}
169
/** @}
162
 */
170
 */