Changeset 2b83add in mainline
- 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
- Location:
- uspace/lib/posix
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/Makefile
r458d356 r2b83add 44 44 stdio.c \ 45 45 stdlib.c \ 46 stdlib/strtol.c \ 46 47 stdlib/strtold.c \ 47 48 string.c \ -
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 -
uspace/lib/posix/stdlib.h
r458d356 r2b83add 53 53 /* Absolute Value */ 54 54 extern int posix_abs(int i); 55 extern long posix_labs(long i); 56 extern long long posix_llabs(long long i); 55 57 56 58 /* Array Sort Function */ … … 66 68 67 69 /* Floating Point Conversion */ 70 extern double posix_atof(const char *nptr); 68 71 extern float posix_strtof(const char *restrict nptr, char **restrict endptr); 69 72 extern double posix_strtod(const char *restrict nptr, char **restrict endptr); … … 71 74 72 75 /* Integer Conversion */ 73 extern int posix_atoi(const char *str); 76 extern int posix_atoi(const char *nptr); 77 extern long int posix_atol(const char *nptr); 78 extern long long int posix_atoll(const char *nptr); 79 80 extern long int posix_strtol(const char *restrict nptr, 81 char **restrict endptr, int base); 82 extern long long int posix_strtoll(const char *restrict nptr, 83 char **restrict endptr, int base); 84 extern unsigned long int posix_strtoul(const char *restrict nptr, 85 char **restrict endptr, int base); 86 extern unsigned long long int posix_strtoull( 87 const char *restrict nptr, char **restrict endptr, int base); 88 74 89 75 90 /* Memory Allocation */ … … 86 101 87 102 #define abs posix_abs 103 #define labs posix_labs 104 #define llabs posix_llabs 88 105 89 106 #define qsort posix_qsort 90 107 91 108 #define getenv posix_getenv 109 #define putenv posix_putenv 92 110 93 111 #define realpath posix_realpath 94 112 113 #define atof posix_atof 95 114 #define strtof posix_strtof 96 115 #define strtod posix_strtod … … 98 117 99 118 #define atoi posix_atoi 119 #define atol posix_atol 120 #define atoll posix_atoll 121 #define strtol posix_strtol 122 #define strtoll posix_strtoll 123 #define strtoul posix_strtoul 124 #define strtoull posix_strtoull 100 125 101 126 #define malloc posix_malloc
Note:
See TracChangeset
for help on using the changeset viewer.