2 libc-extension.cc -- compensate for lacking libc functions.
5 source file of the flowerlib
7 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
13 #include "libc-extension.hh"
17 strnlwr (char* start_l ,int n)
19 char * p = start_l + n;
20 while (--p >= start_l)
22 *p = tolower (*p); /* a macro on some compilers */
28 strnupr (char* start_l, int n)
30 char * p = start_l + n;
31 while (--p >= start_l)
33 *p = toupper (*p); /* a macro on some compilers */
41 /** locate a substring. #memmem# finds the first occurrence of
42 #needle# in #haystack#. This is not ANSI-C.
44 The prototype is not in accordance with the Linux Programmer's
45 Manual v1.15, but it is with /usr/include/string.h */
48 memmem (Byte const *haystack, int haystack_len,
49 Byte const *needle,int needle_len)
51 Byte const * end_haystack = haystack + haystack_len - needle_len + 1;
52 Byte const * end_needle = needle + needle_len ;
54 /* Ahhh ... Some minimal lowlevel stuff. This *is* nice; Varation
55 is the spice of life */
56 while (haystack < end_haystack)
58 Byte const *subneedle_l = needle;
59 Byte const *subhaystack_l = haystack;
60 while (subneedle_l < end_needle)
61 if (*subneedle_l++ != *subhaystack_l++)
64 // completed the needle. Gotcha.
65 return (Byte *) haystack;
75 memrchr (Byte const * p, int n, char c)
89 my_swap (T &t1, T &t2, T &tmp)
97 strrev (Byte* byte_l, int length_i)
101 Byte* left_l = byte_l;
102 Byte* right_l = byte_l + length_i;
104 while (right_l > left_l)
106 my_swap (*right_l-- , *left_l++ , tmp_byte);
112 int snprintf (char *str, size_t,
113 char const *format, ...)
116 va_start (ap, format);
117 int i = vsprintf (str, format, ap);