Changes in uspace/lib/posix/stdlib.c [ca1f1ec:102a729] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/stdlib.c
rca1f1ec r102a729 31 31 * @{ 32 32 */ 33 /** @file 33 /** @file Standard library definitions. 34 34 */ 35 35 … … 40 40 41 41 #include "errno.h" 42 #include "limits.h" 42 43 43 44 #include "libc/sort.h" … … 59 60 60 61 /** 62 * Integer absolute value. 61 63 * 62 64 * @param i Input value. … … 69 71 70 72 /** 73 * Long integer absolute value. 71 74 * 72 75 * @param i Input value. … … 79 82 80 83 /** 84 * Long long integer absolute value. 81 85 * 82 86 * @param i Input value. … … 88 92 } 89 93 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 */ 90 101 posix_div_t posix_div(int numer, int denom) 91 102 { … … 93 104 } 94 105 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 */ 95 113 posix_ldiv_t posix_ldiv(long numer, long denom) 96 114 { … … 98 116 } 99 117 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 */ 100 125 posix_lldiv_t posix_lldiv(long long numer, long long denom) 101 126 { … … 109 134 * @param elem2 Second element to compare. 110 135 * @param compare Comparison function without userdata parameter. 111 *112 136 * @return Relative ordering of the elements. 113 137 */ … … 115 139 { 116 140 int (*compare)(const void *, const void *) = userdata; 117 return compare(elem1, elem2); 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 } 118 151 } 119 152 … … 121 154 * Array sorting utilizing the quicksort algorithm. 122 155 * 123 * @param array 124 * @param count 125 * @param size 126 * @param compare 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. 127 160 */ 128 161 void posix_qsort(void *array, size_t count, size_t size, … … 171 204 /** 172 205 * Retrieve a value of the given environment variable. 206 * 173 207 * Since HelenOS doesn't support env variables at the moment, 174 208 * this function always returns NULL. 175 209 * 176 * @param name 177 * @return Always NULL.210 * @param name Name of the variable. 211 * @return Value of the variable or NULL if such variable does not exist. 178 212 */ 179 213 char *posix_getenv(const char *name) … … 195 229 196 230 /** 197 * 198 * @param string String to be passed to a command interpreter. 199 * @return 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). 200 237 */ 201 238 int posix_system(const char *string) { … … 205 242 206 243 /** 207 * 208 * @param name 209 * @param resolved 210 * @return 211 */ 212 char *posix_realpath(const char *name, char *resolved) 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) 213 254 { 214 255 #ifndef PATH_MAX … … 254 295 * its native representation. See posix_strtold(). 255 296 * 256 * @param nptr 257 * @return 297 * @param nptr String representation of a floating-point number. 298 * @return Double-precision number resulting from the string conversion. 258 299 */ 259 300 double posix_atof(const char *nptr) … … 266 307 * its native representation. See posix_strtold(). 267 308 * 268 * @param nptr 269 * @param endptr 270 * @return 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. 271 313 */ 272 314 float posix_strtof(const char *restrict nptr, char **restrict endptr) … … 279 321 * its native representation. See posix_strtold(). 280 322 * 281 * @param nptr 282 * @param endptr 283 * @return 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. 284 327 */ 285 328 double posix_strtod(const char *restrict nptr, char **restrict endptr) … … 289 332 290 333 /** 291 * 292 * @param size 293 * @return 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. 294 338 */ 295 339 void *posix_malloc(size_t size) … … 299 343 300 344 /** 301 * 302 * @param nelem 303 * @param elsize 304 * @return 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. 305 350 */ 306 351 void *posix_calloc(size_t nelem, size_t elsize) … … 310 355 311 356 /** 312 * 313 * @param ptr 314 * @param size 315 * @return 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. 316 362 */ 317 363 void *posix_realloc(void *ptr, size_t size) 318 364 { 319 return realloc(ptr, size); 320 } 321 322 /** 323 * 324 * @param ptr 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. 325 378 */ 326 379 void posix_free(void *ptr) … … 343 396 344 397 /** 345 * Should read system load statistics. Not supported. Always returns -1. 346 * 347 * @param loadavg 348 * @param nelem 349 * @return 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. 350 405 */ 351 406 int bsd_getloadavg(double loadavg[], int nelem)
Note:
See TracChangeset
for help on using the changeset viewer.