Changeset cc3652db in mainline
- Timestamp:
- 2011-06-25T13:59:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- be64a84
- Parents:
- 2b83add
- Location:
- uspace/lib/posix
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/stdlib.c
r2b83add rcc3652db 86 86 } 87 87 88 posix_div_t posix_div(int numer, int denom) 89 { 90 return (posix_div_t) { .quot = numer / denom, .rem = numer % denom }; 91 } 92 93 posix_ldiv_t posix_ldiv(long numer, long denom) 94 { 95 return (posix_ldiv_t) { .quot = numer / denom, .rem = numer % denom }; 96 } 97 98 posix_lldiv_t posix_lldiv(long long numer, long long denom) 99 { 100 return (posix_lldiv_t) { .quot = numer / denom, .rem = numer % denom }; 101 } 102 88 103 /** 89 104 * Private helper function that serves as a compare function for qsort(). … … 117 132 118 133 /** 134 * Binary search in a sorted array. 135 * 136 * @param key Object to search for. 137 * @param base Pointer to the first element of the array. 138 * @param nmemb Number of elements in the array. 139 * @param size Size of each array element. 140 * @param compar Comparison function. 141 * @return Pointer to a matching element, or NULL if none can be found. 142 */ 143 void *posix_bsearch(const void *key, const void *base, 144 size_t nmemb, size_t size, int (*compar)(const void *, const void *)) 145 { 146 while (nmemb > 0) { 147 const void *middle = base + (nmemb / 2) * size; 148 int cmp = compar(key, middle); 149 if (cmp == 0) { 150 return (void *) middle; 151 } 152 if (middle == base) { 153 /* There is just one member left to check and it 154 * didn't match the key. Avoid infinite loop. 155 */ 156 break; 157 } 158 if (cmp < 0) { 159 nmemb = nmemb / 2; 160 } else if (cmp > 0) { 161 nmemb = nmemb - (nmemb / 2); 162 base = middle; 163 } 164 } 165 166 return NULL; 167 } 168 169 /** 119 170 * Retrieve a value of the given environment variable. 120 171 * Since HelenOS doesn't support env variables at the moment, … … 139 190 // TODO: low priority, just a compile-time dependency of binutils 140 191 not_implemented(); 192 } 193 194 /** 195 * 196 * @param string String to be passed to a command interpreter. 197 * @return 198 */ 199 int posix_system(const char *string) { 200 // TODO: does nothing at the moment 201 return 0; 141 202 } 142 203 -
uspace/lib/posix/stdlib.h
r2b83add rcc3652db 56 56 extern long long posix_llabs(long long i); 57 57 58 /* Array Sort Function */ 58 /* Integer division */ 59 60 typedef struct { 61 int quot, rem; 62 } posix_div_t; 63 64 typedef struct { 65 long quot, rem; 66 } posix_ldiv_t; 67 68 typedef struct { 69 long long quot, rem; 70 } posix_lldiv_t; 71 72 extern posix_div_t posix_div(int numer, int denom); 73 extern posix_ldiv_t posix_ldiv(long numer, long denom); 74 extern posix_lldiv_t posix_lldiv(long long numer, long long denom); 75 76 /* Array Functions */ 59 77 extern void posix_qsort(void *array, size_t count, size_t size, 60 78 int (*compare)(const void *, const void *)); 79 extern void *posix_bsearch(const void *key, const void *base, 80 size_t nmemb, size_t size, int (*compar)(const void *, const void *)); 81 61 82 62 83 /* Environment Access */ 63 84 extern char *posix_getenv(const char *name); 64 85 extern int posix_putenv(char *string); 86 87 extern int posix_system(const char *string); 88 65 89 66 90 /* Symbolic Links */ … … 104 128 #define llabs posix_llabs 105 129 130 #define div_t posix_div_t 131 #define ldiv_t posix_ldiv_t 132 #define lldiv_t posix_lldiv_t 133 #define div posix_div 134 #define ldiv posix_ldiv 135 #define lldiv posix_lldiv 136 106 137 #define qsort posix_qsort 138 #define bsearch posix_bsearch 107 139 108 140 #define getenv posix_getenv 109 141 #define putenv posix_putenv 142 #define system posix_system 110 143 111 144 #define realpath posix_realpath
Note:
See TracChangeset
for help on using the changeset viewer.