Changeset 2b83add in mainline for uspace/lib/posix/stdlib.c
- Timestamp:
- 2011-06-25T12:41:40Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cc3652db
- Parents:
- 458d356
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/stdlib.c
r458d356 r2b83add 37 37 38 38 #include "stdlib.h" 39 #include "libc/sort.h" 40 #include "libc/str.h" 41 #include "libc/vfs/vfs.h" 39 42 #include "internal/common.h" 43 #include <errno.h> // FIXME: use POSIX errno 40 44 41 45 /** … … 54 58 /** 55 59 * 60 * @param i Input value. 61 * @return Absolute value of the parameter. 62 */ 63 int posix_abs(int i) 64 { 65 return i < 0 ? -i : i; 66 } 67 68 /** 69 * 70 * @param i Input value. 71 * @return Absolute value of the parameter. 72 */ 73 long posix_labs(long i) 74 { 75 return i < 0 ? -i : i; 76 } 77 78 /** 79 * 80 * @param i Input value. 81 * @return Absolute value of the parameter. 82 */ 83 long long posix_llabs(long long i) 84 { 85 return i < 0 ? -i : i; 86 } 87 88 /** 89 * Private helper function that serves as a compare function for qsort(). 90 * 91 * @param elem1 First element to compare. 92 * @param elem2 Second element to compare. 93 * @param compare Comparison function without userdata parameter. 94 * 95 * @return Relative ordering of the elements. 96 */ 97 static int sort_compare_wrapper(void *elem1, void *elem2, void *userdata) 98 { 99 int (*compare)(const void *, const void *) = userdata; 100 return compare(elem1, elem2); 101 } 102 103 /** 104 * Array sorting utilizing the quicksort algorithm. 105 * 56 106 * @param array 57 107 * @param count … … 59 109 * @param compare 60 110 */ 61 int posix_abs(int i)62 {63 // TODO64 not_implemented();65 }66 67 /**68 *69 * @param array70 * @param count71 * @param size72 * @param compare73 */74 111 void posix_qsort(void *array, size_t count, size_t size, 75 112 int (*compare)(const void *, const void *)) 76 113 { 77 // TODO 78 not_implemented(); 79 } 80 81 /** 114 /* Implemented in libc with one extra argument. */ 115 qsort(array, count, size, sort_compare_wrapper, compare); 116 } 117 118 /** 119 * Retrieve a value of the given environment variable. 120 * Since HelenOS doesn't support env variables at the moment, 121 * this function always returns NULL. 82 122 * 83 123 * @param name 84 * @return 124 * @return Always NULL. 85 125 */ 86 126 char *posix_getenv(const char *name) 87 127 { 88 // TODO 89 not_implemented(); 128 return NULL; 90 129 } 91 130 … … 110 149 char *posix_realpath(const char *name, char *resolved) 111 150 { 112 // TODO 113 not_implemented(); 151 #ifndef PATH_MAX 152 assert(resolved == NULL); 153 #endif 154 155 if (name == NULL) { 156 errno = EINVAL; 157 return NULL; 158 } 159 160 // TODO: symlink resolution 161 162 /* Function absolutize is implemented in libc and declared in vfs.h. 163 * No more processing is required as HelenOS doesn't have symlinks 164 * so far (as far as I can tell), although this function will need 165 * to be updated when that support is implemented. 166 */ 167 char* absolute = absolutize(name, NULL); 168 169 if (absolute == NULL) { 170 /* POSIX requires some specific errnos to be set 171 * for some cases, but there is no way to find out from 172 * absolutize(). 173 */ 174 errno = EINVAL; 175 return NULL; 176 } 177 178 if (resolved == NULL) { 179 return absolute; 180 } else { 181 #ifdef PATH_MAX 182 str_cpy(resolved, PATH_MAX, absolute); 183 #endif 184 free(absolute); 185 return resolved; 186 } 114 187 } 115 188 … … 119 192 * 120 193 * @param nptr 121 * @param endptr 122 * @return 123 */ 124 float posix_strtof(const char *restrict nptr, char **restrict endptr) 125 { 126 return (float) posix_strtold(nptr, endptr); 194 * @return 195 */ 196 double posix_atof(const char *nptr) 197 { 198 return posix_strtod(nptr, NULL); 127 199 } 128 200 … … 135 207 * @return 136 208 */ 209 float posix_strtof(const char *restrict nptr, char **restrict endptr) 210 { 211 return (float) posix_strtold(nptr, endptr); 212 } 213 214 /** 215 * Converts a string representation of a floating-point number to 216 * its native representation. See posix_strtold(). 217 * 218 * @param nptr 219 * @param endptr 220 * @return 221 */ 137 222 double posix_strtod(const char *restrict nptr, char **restrict endptr) 138 223 { 139 224 return (double) posix_strtold(nptr, endptr); 140 }141 142 /**143 *144 * @param str145 * @return146 */147 int posix_atoi(const char *str)148 {149 // TODO150 not_implemented();151 225 } 152 226
Note:
See TracChangeset
for help on using the changeset viewer.