Changes in uspace/lib/posix/stdlib.c [102a729:ca1f1ec] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/stdlib.c
r102a729 rca1f1ec 31 31 * @{ 32 32 */ 33 /** @file Standard library definitions.33 /** @file 34 34 */ 35 35 … … 40 40 41 41 #include "errno.h" 42 #include "limits.h"43 42 44 43 #include "libc/sort.h" … … 60 59 61 60 /** 62 * Integer absolute value.63 61 * 64 62 * @param i Input value. … … 71 69 72 70 /** 73 * Long integer absolute value.74 71 * 75 72 * @param i Input value. … … 82 79 83 80 /** 84 * Long long integer absolute value.85 81 * 86 82 * @param i Input value. … … 92 88 } 93 89 94 /**95 * Compute the quotient and remainder of an integer division.96 *97 * @param numer Numerator.98 * @param denom Denominator.99 * @return Quotient and remainder packed into structure.100 */101 90 posix_div_t posix_div(int numer, int denom) 102 91 { … … 104 93 } 105 94 106 /**107 * Compute the quotient and remainder of a long integer division.108 *109 * @param numer Numerator.110 * @param denom Denominator.111 * @return Quotient and remainder packed into structure.112 */113 95 posix_ldiv_t posix_ldiv(long numer, long denom) 114 96 { … … 116 98 } 117 99 118 /**119 * Compute the quotient and remainder of a long long integer division.120 *121 * @param numer Numerator.122 * @param denom Denominator.123 * @return Quotient and remainder packed into structure.124 */125 100 posix_lldiv_t posix_lldiv(long long numer, long long denom) 126 101 { … … 134 109 * @param elem2 Second element to compare. 135 110 * @param compare Comparison function without userdata parameter. 111 * 136 112 * @return Relative ordering of the elements. 137 113 */ … … 139 115 { 140 116 int (*compare)(const void *, const void *) = userdata; 141 int ret = compare(elem1, elem2); 142 143 /* Native qsort internals expect this. */ 144 if (ret < 0) { 145 return -1; 146 } else if (ret > 0) { 147 return 1; 148 } else { 149 return 0; 150 } 117 return compare(elem1, elem2); 151 118 } 152 119 … … 154 121 * Array sorting utilizing the quicksort algorithm. 155 122 * 156 * @param array Array of elements to sort.157 * @param count Number of elements in the array.158 * @param size Width of each element.159 * @param compare Decides relative ordering of two elements.123 * @param array 124 * @param count 125 * @param size 126 * @param compare 160 127 */ 161 128 void posix_qsort(void *array, size_t count, size_t size, … … 204 171 /** 205 172 * Retrieve a value of the given environment variable. 206 *207 173 * Since HelenOS doesn't support env variables at the moment, 208 174 * this function always returns NULL. 209 175 * 210 * @param name Name of the variable.211 * @return Value of the variable or NULL if such variable does not exist.176 * @param name 177 * @return Always NULL. 212 178 */ 213 179 char *posix_getenv(const char *name) … … 229 195 230 196 /** 231 * Issue a command. 232 * 233 * @param string String to be passed to a command interpreter or NULL. 234 * @return Termination status of the command if the command is not NULL, 235 * otherwise indicate whether there is a command interpreter (non-zero) 236 * or not (zero). 197 * 198 * @param string String to be passed to a command interpreter. 199 * @return 237 200 */ 238 201 int posix_system(const char *string) { … … 242 205 243 206 /** 244 * Resolve absolute pathname. 245 * 246 * @param name Pathname to be resolved. 247 * @param resolved Either buffer for the resolved absolute pathname or NULL. 248 * @return On success, either resolved (if it was not NULL) or pointer to the 249 * newly allocated buffer containing the absolute pathname (if resolved was 250 * NULL). Otherwise NULL. 251 * 252 */ 253 char *posix_realpath(const char *restrict name, char *restrict resolved) 207 * 208 * @param name 209 * @param resolved 210 * @return 211 */ 212 char *posix_realpath(const char *name, char *resolved) 254 213 { 255 214 #ifndef PATH_MAX … … 295 254 * its native representation. See posix_strtold(). 296 255 * 297 * @param nptr String representation of a floating-point number.298 * @return Double-precision number resulting from the string conversion.256 * @param nptr 257 * @return 299 258 */ 300 259 double posix_atof(const char *nptr) … … 307 266 * its native representation. See posix_strtold(). 308 267 * 309 * @param nptr String representation of a floating-point number. 310 * @param endptr Pointer to the final part of the string which 311 * was not used for conversion. 312 * @return Single-precision number resulting from the string conversion. 268 * @param nptr 269 * @param endptr 270 * @return 313 271 */ 314 272 float posix_strtof(const char *restrict nptr, char **restrict endptr) … … 321 279 * its native representation. See posix_strtold(). 322 280 * 323 * @param nptr String representation of a floating-point number. 324 * @param endptr Pointer to the final part of the string which 325 * was not used for conversion. 326 * @return Double-precision number resulting from the string conversion. 281 * @param nptr 282 * @param endptr 283 * @return 327 284 */ 328 285 double posix_strtod(const char *restrict nptr, char **restrict endptr) … … 332 289 333 290 /** 334 * Allocate memory chunk. 335 * 336 * @param size Size of the chunk to allocate. 337 * @return Either pointer to the allocated chunk or NULL if not possible. 291 * 292 * @param size 293 * @return 338 294 */ 339 295 void *posix_malloc(size_t size) … … 343 299 344 300 /** 345 * Allocate memory for an array of elements. 346 * 347 * @param nelem Number of elements in the array. 348 * @param elsize Size of each element. 349 * @return Either pointer to the allocated array or NULL if not possible. 301 * 302 * @param nelem 303 * @param elsize 304 * @return 350 305 */ 351 306 void *posix_calloc(size_t nelem, size_t elsize) … … 355 310 356 311 /** 357 * Reallocate memory chunk to a new size. 358 * 359 * @param ptr Memory chunk to reallocate. Might be NULL. 360 * @param size Size of the reallocated chunk. Might be zero. 361 * @return Either NULL or the pointer to the newly reallocated chunk. 312 * 313 * @param ptr 314 * @param size 315 * @return 362 316 */ 363 317 void *posix_realloc(void *ptr, size_t size) 364 318 { 365 if (ptr != NULL && size == 0) { 366 /* Native realloc does not handle this special case. */ 367 free(ptr); 368 return NULL; 369 } else { 370 return realloc(ptr, size); 371 } 372 } 373 374 /** 375 * Free allocated memory chunk. 376 * 377 * @param ptr Memory chunk to be freed. 319 return realloc(ptr, size); 320 } 321 322 /** 323 * 324 * @param ptr 378 325 */ 379 326 void posix_free(void *ptr) … … 396 343 397 344 /** 398 * Get system load average statistics. 399 * 400 * Not supported. Always returns -1. 401 * 402 * @param loadavg Array where the load averages shall be placed. 403 * @param nelem Maximum number of elements to be placed into the array. 404 * @return Number of elements placed into the array on success, -1 otherwise. 345 * Should read system load statistics. Not supported. Always returns -1. 346 * 347 * @param loadavg 348 * @param nelem 349 * @return 405 350 */ 406 351 int bsd_getloadavg(double loadavg[], int nelem)
Note:
See TracChangeset
for help on using the changeset viewer.