Changes in / [8119363:e768aea] in mainline
- Files:
-
- 1 added
- 17 deleted
- 43 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
r8119363 re768aea 139 139 nic/rtl8169 \ 140 140 nic/ar9271 \ 141 nic/virtio-net \142 141 block/ahci 143 142 -
kernel/generic/include/stdbool.h
r8119363 re768aea 41 41 #define true 1 42 42 43 #define __bool_true_false_are_defined 43 #define __bool_true_false_are_defined 1 44 44 45 45 #endif -
tools/ew.py
r8119363 re768aea 146 146 return ' -device rtl8139,vlan=0' 147 147 148 def qemu_nic_virtio_options():149 return ' -device virtio-net,vlan=0'150 151 148 def qemu_net_options(): 152 149 if is_override('nonet'): … … 161 158 if 'ne2k' in overrides['net'].keys(): 162 159 nic_options += qemu_nic_ne2k_options() 163 if 'virtio-net' in overrides['net'].keys():164 nic_options += qemu_nic_virtio_options()165 160 else: 166 161 # Use the default NIC … … 331 326 def usage(): 332 327 print("%s - emulator wrapper for running HelenOS\n" % os.path.basename(sys.argv[0])) 333 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k |virtio-net] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci] [-notablet]\n" %328 print("%s [-d] [-h] [-net e1k|rtl8139|ne2k] [-nohdd] [-nokvm] [-nonet] [-nosnd] [-nousb] [-noxhci] [-notablet]\n" % 334 329 os.path.basename(sys.argv[0])) 335 330 print("-d\tDry run: do not run the emulation, just print the command line.") … … 365 360 elif sys.argv[i] == 'ne2k': 366 361 overrides['net']['ne2k'] = True 367 elif sys.argv[i] == 'virtio-net':368 overrides['net']['virtio-net'] = True369 362 else: 370 363 usage() -
uspace/Makefile
r8119363 re768aea 181 181 drv/nic/rtl8169 \ 182 182 drv/nic/ar9271 \ 183 drv/nic/virtio-net \184 183 drv/platform/amdm37x \ 185 184 drv/platform/icp \ … … 252 251 lib/bithenge \ 253 252 lib/posix \ 254 lib/ieee80211 \ 255 lib/virtio 253 lib/ieee80211 256 254 257 255 BASE_BUILDS := $(addsuffix .build,$(BASE_LIBS)) -
uspace/Makefile.common
r8119363 re768aea 165 165 ifneq ($(TEST_SOURCES),) 166 166 TEST_OUTPUTS = $(TEST_BINARY) $(TEST_BINARY).disasm 167 TEST_CFLAGS = -I$(LIB_PREFIX)/pcut/include -D__helenos__ $(EXTRA_TEST_CFLAGS)167 TEST_CFLAGS = -I$(LIB_PREFIX)/pcut/include -D__helenos__ 168 168 TEST_BINARY_LIBS = $(LIB_PREFIX)/pcut/libpcut.a 169 169 EXTRA_CLEAN += $(TEST_OUTPUTS) $(TEST_BINARY).map -
uspace/drv/bus/pci/pciintel/pci.c
r8119363 re768aea 738 738 739 739 if (pio_enable_resource(&bus->pio_win, 740 &hw_resources.resources[0], (void **) &bus->conf_space,741 NULL, NULL)) {740 &hw_resources.resources[0], 741 (void **) &bus->conf_space)) { 742 742 ddf_msg(LVL_ERROR, 743 743 "Failed to map configuration space."); … … 759 759 760 760 if (pio_enable_resource(&bus->pio_win, 761 &hw_resources.resources[0], (void **) &bus->conf_addr_reg,762 NULL, NULL)) {761 &hw_resources.resources[0], 762 (void **) &bus->conf_addr_reg)) { 763 763 ddf_msg(LVL_ERROR, 764 764 "Failed to enable configuration ports."); … … 767 767 } 768 768 if (pio_enable_resource(&bus->pio_win, 769 &hw_resources.resources[1], (void **) &bus->conf_data_reg,770 NULL, NULL)) {769 &hw_resources.resources[1], 770 (void **) &bus->conf_data_reg)) { 771 771 ddf_msg(LVL_ERROR, 772 772 "Failed to enable configuration ports."); -
uspace/lib/bithenge/src/helenos/common.h
r8119363 re768aea 73 73 } 74 74 75 static inline void *memchr(const void *s, int c, size_t n) 76 { 77 for (size_t i = 0; i < n; i++) 78 if (((char *)s)[i] == c) 79 return (void *)(s + i); 80 return NULL; 81 } 82 75 83 static inline errno_t bithenge_parse_int(const char *start, bithenge_int_t *result) 76 84 { -
uspace/lib/c/Makefile
r8119363 re768aea 41 41 EXTRA_OUTPUT = $(LINKER_SCRIPTS) 42 42 EXTRA_CLEAN = $(LINKER_SCRIPTS) 43 EXTRA_TEST_CFLAGS = -Wno-deprecated-declarations44 43 LIBRARY = libc 45 44 SOVERSION = 0.0 … … 133 132 generic/malloc.c \ 134 133 generic/stdio/scanf.c \ 135 generic/stdio/sprintf.c \136 134 generic/stdio/sscanf.c \ 137 135 generic/stdio/sstream.c \ 138 generic/stdio/vsprintf.c \139 136 generic/sysinfo.c \ 140 137 generic/ipc.c \ … … 152 149 generic/adt/prodcons.c \ 153 150 generic/time.c \ 154 generic/tmpfile.c \155 151 generic/stdio.c \ 156 152 generic/stdlib.c \ … … 193 189 test/fibril/timer.c \ 194 190 test/main.c \ 195 test/mem.c \196 191 test/io/table.c \ 197 192 test/stdio/scanf.c \ … … 199 194 test/qsort.c \ 200 195 test/sprintf.c \ 201 test/stdio.c \202 196 test/stdlib.c \ 203 197 test/str.c -
uspace/lib/c/arch/arm32/include/libarch/fibril_context.h
r8119363 re768aea 49 49 uint32_t r7; 50 50 uint32_t r8; 51 /* r9 51 /* r9*/ 52 52 uint32_t tls; 53 53 uint32_t r10; … … 57 57 58 58 #endif 59 -
uspace/lib/c/generic/async/client.c
r8119363 re768aea 190 190 free(msg); 191 191 } 192 192 193 193 194 /** Mutex protecting inactive_exch_list and avail_phone_cv. -
uspace/lib/c/generic/ddi.c
r8119363 re768aea 220 220 /** Enable PIO for specified HW resource wrt. to the PIO window. 221 221 * 222 * @param win PIO window. May be NULL if the resources are known to be 223 * absolute. 224 * @param res Resources specifying the I/O range wrt. to the PIO window. 225 * @param[out] virt Virtual address for application's PIO operations. 226 * @param[out] phys If non-NULL, physical address of the resource 227 * @param[out] size If non-NULL, size of the enabled resource. 222 * @param win PIO window. May be NULL if the resources are known to be 223 * absolute. 224 * @param res Resources specifying the I/O range wrt. to the PIO window. 225 * @param virt Virtual address for application's PIO operations. 228 226 * 229 227 * @return EOK on success. … … 231 229 * 232 230 */ 233 errno_t pio_enable_resource(pio_window_t *win, hw_resource_t *res, void **virt, 234 uintptr_t *phys, size_t *size) 231 errno_t pio_enable_resource(pio_window_t *win, hw_resource_t *res, void **virt) 235 232 { 236 233 uintptr_t addr; 237 size_t s z;234 size_t size; 238 235 239 236 switch (res->type) { … … 245 242 addr += win->io.base; 246 243 } 247 s z= res->res.io_range.size;244 size = res->res.io_range.size; 248 245 break; 249 246 case MEM_RANGE: … … 254 251 addr += win->mem.base; 255 252 } 256 s z= res->res.mem_range.size;253 size = res->res.mem_range.size; 257 254 break; 258 255 default: … … 260 257 } 261 258 262 if (phys) 263 *phys = addr; 264 if (size) 265 *size = sz; 266 267 return pio_enable((void *) addr, sz, virt); 259 return pio_enable((void *) addr, size, virt); 268 260 } 269 261 -
uspace/lib/c/generic/io/printf_core.c
r8119363 re768aea 39 39 #include <stdio.h> 40 40 #include <stddef.h> 41 #include <stdlib.h>42 41 #include <io/printf_core.h> 43 42 #include <ctype.h> -
uspace/lib/c/generic/io/snprintf.c
r8119363 re768aea 35 35 #include <stdarg.h> 36 36 #include <stdio.h> 37 #include <io/printf_core.h> 37 38 38 39 /** Print formatted to the given buffer with limited size. -
uspace/lib/c/generic/mem.c
r8119363 re768aea 1 1 /* 2 2 * Copyright (c) 2005 Martin Decky 3 * Copyright (c) 20 18 Jiri Svoboda3 * Copyright (c) 2008 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 252 252 } 253 253 254 /** Search memory area.255 *256 * @param s Memory area257 * @param c Character (byte) to search for258 * @param n Size of memory area in bytes259 *260 * @return Pointer to the first occurrence of @a c in the first @a n261 * bytes of @a s or @c NULL if not found.262 */263 void *memchr(const void *s, int c, size_t n)264 {265 uint8_t *u = (uint8_t *) s;266 unsigned char uc = (unsigned char) c;267 size_t i;268 269 for (i = 0; i < n; i++) {270 if (u[i] == uc)271 return (void *) &u[i];272 }273 274 return NULL;275 }276 277 254 /** @} 278 255 */ -
uspace/lib/c/generic/stdio.c
r8119363 re768aea 1 1 /* 2 * Copyright (c) 201 8Jiri Svoboda2 * Copyright (c) 2017 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 34 34 35 35 #include <errno.h> 36 #include <stdbool.h>37 36 #include <stdio.h> 38 #include <str.h>39 #include <str_error.h>40 #include <tmpfile.h>41 37 #include <vfs/vfs.h> 42 43 /** Static buffer for tmpnam function */44 static char tmpnam_buf[L_tmpnam];45 46 /** Get stream position.47 *48 * @param stream Stream49 * @param pos Place to store position50 *51 * @return Zero on success, non-zero on failure52 */53 int fgetpos(FILE *stream, fpos_t *pos)54 {55 off64_t p;56 57 p = ftell64(stream);58 if (p < 0)59 return -1;60 61 pos->pos = p;62 return 0;63 }64 65 /** Get stream position.66 *67 * @param stream Stream68 * @param pos Position69 *70 * @return Zero on sucess, non-zero on failure71 */72 int fsetpos(FILE *stream, const fpos_t *pos)73 {74 int rc;75 76 rc = fseek64(stream, pos->pos, SEEK_SET);77 if (rc < 0)78 return -1;79 80 return 0;81 }82 38 83 39 /** Rename file or directory (C standard) */ … … 88 44 rc = vfs_rename_path(old_path, new_path); 89 45 if (rc != EOK) { 90 /*91 * Note that ISO C leaves the value of errno undefined,92 * whereas according to UN*X standards, it is set.93 */94 46 errno = rc; 95 47 return -1; … … 106 58 rc = vfs_unlink_path(path); 107 59 if (rc != EOK) { 108 /*109 * Note that ISO C leaves the value of errno undefined,110 * whereas according to UN*X standards, it is set.111 */112 60 errno = rc; 113 61 return -1; … … 117 65 } 118 66 119 /** Create a temporary file.120 *121 * @return Open stream descriptor or @c NULL on error. In that case122 * errno is set (UN*X). Note that ISO C leaves the value of errno123 * undefined.124 */125 FILE *tmpfile(void)126 {127 int file;128 FILE *stream;129 130 file = __tmpfile();131 if (file < 0) {132 printf("file is < 0\n");133 errno = EEXIST;134 return NULL;135 }136 137 stream = fdopen(file, "w+");138 if (stream == NULL) {139 printf("stream = NULL\n");140 vfs_put(file);141 errno = EACCES;142 return NULL;143 }144 145 return stream;146 }147 148 /** Create name for a temporary file.149 *150 * @param s Pointer to array of at least L_tmpnam bytes or @c NULL.151 * @return The pointer @a s or pointer to internal static buffer on success,152 * @c NULL on error.153 */154 char *tmpnam(char *s)155 {156 char *p;157 158 p = (s != NULL) ? s : tmpnam_buf;159 return __tmpnam(p);160 }161 162 /** Print error message and string representation of @c errno.163 *164 * @param s Error message165 */166 void perror(const char *s)167 {168 if (s != NULL && *s != '\0')169 fprintf(stderr, "%s: %s\n", s, str_error(errno));170 else171 fprintf(stderr, "%s\n", str_error(errno));172 }173 174 175 67 /** @} 176 68 */ -
uspace/lib/c/generic/stdlib.c
r8119363 re768aea 195 195 } 196 196 197 /** Compute the absolute value of an integer.198 *199 * If the result cannot be represented, the behavior is undefined.200 *201 * @param j Integer202 * @return The absolute value of @a j203 */204 int abs(int j)205 {206 int aj;207 208 if (j < 0) {209 aj = -j;210 assert(aj >= 0);211 } else {212 aj = j;213 }214 215 return aj;216 }217 218 /** Compute the absolute value of a long integer.219 *220 * If the result cannot be represented, the behavior is undefined.221 *222 * @param j Long integer223 * @return The absolute value of @a j224 */225 long labs(long j)226 {227 long aj;228 229 if (j < 0) {230 aj = -j;231 assert(aj >= 0);232 } else {233 aj = j;234 }235 236 return aj;237 }238 239 /** Compute the absolute value of a long long integer.240 *241 * If the result cannot be represented, the behavior is undefined.242 *243 * @param j Long long integer244 * @return The absolute value of @a j245 */246 long long llabs(long long j)247 {248 long long aj;249 250 if (j < 0) {251 aj = -j;252 assert(aj >= 0);253 } else {254 aj = j;255 }256 257 return aj;258 }259 260 197 /** Compute quotient and remainder of int division. 261 198 * -
uspace/lib/c/generic/vfs/vfs.c
r8119363 re768aea 285 285 { 286 286 size_t abs_size; 287 char *abs _path= vfs_absolutize(path, &abs_size);288 if ( abs_path == NULL)287 char *abs = vfs_absolutize(path, &abs_size); 288 if (!abs) 289 289 return ENOMEM; 290 290 291 291 int fd; 292 errno_t rc = vfs_lookup(abs _path, WALK_DIRECTORY, &fd);292 errno_t rc = vfs_lookup(abs, WALK_DIRECTORY, &fd); 293 293 if (rc != EOK) { 294 free(abs _path);294 free(abs); 295 295 return rc; 296 296 } … … 305 305 306 306 cwd_fd = fd; 307 cwd_path = abs _path;307 cwd_path = abs; 308 308 cwd_size = abs_size; 309 309 -
uspace/lib/c/include/adt/hash_table.h
r8119363 re768aea 102 102 void *); 103 103 104 104 105 #endif 105 106 -
uspace/lib/c/include/cc.h
r8119363 re768aea 44 44 #endif 45 45 46 46 47 #endif 47 48 -
uspace/lib/c/include/ddi.h
r8119363 re768aea 40 40 #include <stdint.h> 41 41 #include <sys/time.h> 42 #include <byteorder.h>43 42 #include <abi/ddi/irq.h> 44 43 #include <device/hw_res.h> … … 65 64 66 65 extern errno_t pio_enable_range(addr_range_t *, void **); 67 extern errno_t pio_enable_resource(pio_window_t *, hw_resource_t *, void **, 68 uintptr_t *, size_t *); 66 extern errno_t pio_enable_resource(pio_window_t *, hw_resource_t *, void **); 69 67 extern errno_t pio_enable(void *, size_t, void **); 70 68 extern errno_t pio_disable(void *, size_t); … … 86 84 extern uint32_t pio_read_32(const ioport32_t *); 87 85 extern uint64_t pio_read_64(const ioport64_t *); 88 89 static inline void pio_write_le16(ioport16_t *reg, uint16_t val)90 {91 pio_write_16(reg, host2uint16_t_le(val));92 }93 static inline void pio_write_be16(ioport16_t *reg, uint16_t val)94 {95 pio_write_16(reg, host2uint16_t_be(val));96 }97 static inline void pio_write_le32(ioport32_t *reg, uint32_t val)98 {99 pio_write_32(reg, host2uint32_t_le(val));100 }101 static inline void pio_write_be32(ioport32_t *reg, uint32_t val)102 {103 pio_write_32(reg, host2uint32_t_be(val));104 }105 static inline void pio_write_le64(ioport64_t *reg, uint64_t val)106 {107 pio_write_64(reg, host2uint64_t_le(val));108 }109 static inline void pio_write_be64(ioport64_t *reg, uint64_t val)110 {111 pio_write_64(reg, host2uint64_t_be(val));112 }113 114 static inline uint16_t pio_read_le16(const ioport16_t *reg)115 {116 return uint16_t_le2host(pio_read_16(reg));117 }118 static inline uint16_t pio_read_be16(const ioport16_t *reg)119 {120 return uint16_t_be2host(pio_read_16(reg));121 }122 static inline uint32_t pio_read_le32(const ioport32_t *reg)123 {124 return uint32_t_le2host(pio_read_32(reg));125 }126 static inline uint32_t pio_read_be32(const ioport32_t *reg)127 {128 return uint32_t_be2host(pio_read_32(reg));129 }130 static inline uint64_t pio_read_le64(const ioport64_t *reg)131 {132 return uint64_t_le2host(pio_read_64(reg));133 }134 static inline uint64_t pio_read_be64(const ioport64_t *reg)135 {136 return uint64_t_be2host(pio_read_64(reg));137 }138 86 139 87 static inline uint8_t pio_change_8(ioport8_t *reg, uint8_t val, uint8_t mask, -
uspace/lib/c/include/fibril_synch.h
r8119363 re768aea 67 67 typedef struct { 68 68 fibril_owner_info_t oi; /**< Keep this the first thing. */ 69 unsigned intwriters;70 unsigned intreaders;69 unsigned writers; 70 unsigned readers; 71 71 list_t waiters; 72 72 } fibril_rwlock_t; … … 145 145 /** A counting semaphore for fibrils. */ 146 146 typedef struct { 147 long intcount;147 long count; 148 148 list_t waiters; 149 149 } fibril_semaphore_t; -
uspace/lib/c/include/ipc/common.h
r8119363 re768aea 50 50 task_id_t in_task_id; 51 51 sysarg_t in_phone_hash; 52 unsigned intflags;52 unsigned flags; 53 53 struct async_call *label; 54 54 cap_call_handle_t cap_handle; -
uspace/lib/c/include/macros.h
r8119363 re768aea 38 38 #define min(a, b) ((a) < (b) ? (a) : (b)) 39 39 #define max(a, b) ((a) > (b) ? (a) : (b)) 40 #define mabs(a)((a) >= 0 ? (a) : -(a))40 #define abs(a) ((a) >= 0 ? (a) : -(a)) 41 41 42 42 #define ARRAY_SIZE(array) (sizeof(array) / sizeof(array[0])) -
uspace/lib/c/include/mem.h
r8119363 re768aea 1 1 /* 2 2 * Copyright (c) 2005 Martin Decky 3 * Copyright (c) 2018 Jiri Svoboda4 3 * All rights reserved. 5 4 * … … 50 49 extern int memcmp(const void *, const void *, size_t) 51 50 __attribute__((nonnull(1, 2))); 52 extern void *memchr(const void *, int, size_t)53 __attribute__((nonnull(1)));54 51 55 52 #endif -
uspace/lib/c/include/stdbool.h
r8119363 re768aea 41 41 #define true 1 42 42 43 #define __bool_true_false_are_defined 43 #define __bool_true_false_are_defined 1 44 44 45 45 #endif -
uspace/lib/c/include/stdio.h
r8119363 re768aea 1 1 /* 2 2 * Copyright (c) 2005 Martin Decky 3 * Copyright (c) 2018 Jiri Svoboda4 3 * All rights reserved. 5 4 * … … 37 36 #define LIBC_STDIO_H_ 38 37 39 #include <offset.h>40 38 #include <stdarg.h> 41 39 #include <io/verify.h> 42 #include <_bits/NULL.h>43 40 #include <_bits/size_t.h> 44 41 #include <_bits/wchar_t.h> 45 42 #include <_bits/wint_t.h> 46 43 47 /** Forward declaration */48 struct _IO_FILE;49 typedef struct _IO_FILE FILE;50 51 /** File position */52 typedef struct {53 off64_t pos;54 } fpos_t;55 56 #ifndef _HELENOS_SOURCE57 #define _IONBF 058 #define _IOLBF 159 #define _IOFBF 260 #endif61 62 /** Default size for stream I/O buffers */63 #define BUFSIZ 409664 65 44 #define EOF (-1) 66 67 /** Max number of files that is guaranteed to be able to open at the same time */68 #define FOPEN_MAX VFS_MAX_OPEN_FILES69 70 /** Recommended size of fixed-size array for holding file names. */71 #define FILENAME_MAX 409672 73 /** Length of "/tmp/tmp.XXXXXX" + 1 */74 #define L_tmpnam 1675 45 76 46 #ifndef SEEK_SET … … 86 56 #endif 87 57 88 /** Minimum number of unique temporary file names */ 89 #define TMP_MAX 1000000 58 /** Default size for stream I/O buffers */ 59 #define BUFSIZ 4096 60 61 /** Recommended size of fixed-size array for holding file names. */ 62 #define FILENAME_MAX 4096 63 64 /** Forward declaration */ 65 struct _IO_FILE; 66 typedef struct _IO_FILE FILE; 90 67 91 68 extern FILE *stdin; … … 97 74 extern int fgetc(FILE *); 98 75 extern char *fgets(char *, int, FILE *); 99 extern char *gets(char *, size_t) __attribute__((deprecated));100 76 101 77 extern int getchar(void); … … 128 104 extern int vasprintf(char **, const char *, va_list); 129 105 extern int asprintf(char **, const char *, ...) 106 #endif 130 107 _HELENOS_PRINTF_ATTRIBUTE(2, 3); 131 #endif132 108 extern int vsnprintf(char *, size_t, const char *, va_list); 133 134 extern int sprintf(char *, const char *, ...)135 __attribute__((deprecated)) _HELENOS_PRINTF_ATTRIBUTE(2, 3);136 extern int vsprintf(char *, const char *, va_list) __attribute__((deprecated));137 109 138 110 /* Formatted input */ … … 152 124 extern size_t fwrite(const void *, size_t, size_t, FILE *); 153 125 154 extern int fgetpos(FILE *, fpos_t *);155 extern int fsetpos(FILE *, const fpos_t *);156 157 126 extern int fseek(FILE *, long, int); 158 127 extern void rewind(FILE *); … … 164 133 extern void clearerr(FILE *); 165 134 166 extern void perror(const char *);167 168 135 extern void setvbuf(FILE *, void *, int, size_t); 169 136 extern void setbuf(FILE *, void *); 170 137 171 138 /* Misc file functions */ 139 extern int rename(const char *, const char *); 172 140 extern int remove(const char *); 173 extern int rename(const char *, const char *);174 141 175 extern FILE *tmpfile(void); 176 extern char *tmpnam(char *s) __attribute__((deprecated)); 142 #ifndef _HELENOS_SOURCE 143 #define _IONBF 0 144 #define _IOLBF 1 145 #define _IOFBF 2 146 147 extern char *gets(char *, size_t); 148 149 #endif 177 150 178 151 #ifdef _HELENOS_SOURCE -
uspace/lib/c/include/stdlib.h
r8119363 re768aea 87 87 extern int system(const char *); 88 88 89 extern int abs(int);90 extern long labs(long);91 extern long long llabs(long long);92 93 89 extern int atoi(const char *); 94 90 extern long atol(const char *); -
uspace/lib/c/include/vfs/vfs.h
r8119363 re768aea 45 45 #include <offset.h> 46 46 47 #define VFS_MAX_OPEN_FILES12847 #define MAX_OPEN_FILES 128 48 48 49 49 enum vfs_change_state_type { -
uspace/lib/c/test/main.c
r8119363 re768aea 34 34 PCUT_IMPORT(circ_buf); 35 35 PCUT_IMPORT(fibril_timer); 36 PCUT_IMPORT(mem);37 36 PCUT_IMPORT(odict); 38 37 PCUT_IMPORT(qsort); 39 38 PCUT_IMPORT(scanf); 40 39 PCUT_IMPORT(sprintf); 41 PCUT_IMPORT(stdio);42 40 PCUT_IMPORT(stdlib); 43 41 PCUT_IMPORT(str); -
uspace/lib/c/test/stdlib.c
r8119363 re768aea 361 361 } 362 362 363 /** abs function of positive number */364 PCUT_TEST(abs_pos)365 {366 int i;367 368 i = abs(1);369 PCUT_ASSERT_TRUE(i == 1);370 }371 372 /** abs function of negative number */373 PCUT_TEST(abs_neg)374 {375 int i;376 377 i = abs(-1);378 PCUT_ASSERT_TRUE(i == 1);379 }380 381 /** labs function of positive number */382 PCUT_TEST(labs_pos)383 {384 long li;385 386 li = labs(1);387 PCUT_ASSERT_TRUE(li == 1);388 }389 390 /** labs function of negative number */391 PCUT_TEST(labs_neg)392 {393 long li;394 395 li = labs(-1);396 PCUT_ASSERT_TRUE(li == 1);397 }398 399 /** llabs function of positive number */400 PCUT_TEST(llabs_pos)401 {402 long long lli;403 404 lli = llabs(1);405 PCUT_ASSERT_TRUE(lli == 1);406 }407 408 /** llabs function of negative number */409 PCUT_TEST(llabs_neg)410 {411 long long lli;412 413 lli = llabs(-1);414 PCUT_ASSERT_TRUE(lli == 1);415 }416 417 363 /** Integer division */ 418 364 PCUT_TEST(div_func) -
uspace/lib/drv/include/pci_dev_iface.h
r8119363 re768aea 42 42 #define PCI_VENDOR_ID 0x00 43 43 #define PCI_DEVICE_ID 0x02 44 #define PCI_STATUS 0x0645 44 #define PCI_SUB_CLASS 0x0A 46 45 #define PCI_BASE_CLASS 0x0B 47 #define PCI_BAR0 0x1048 #define PCI_CAP_PTR 0x3449 50 #define PCI_BAR_COUNT 651 52 #define PCI_STATUS_CAP_LIST (1 << 4)53 54 #define PCI_CAP_ID(c) ((c) + 0x0)55 #define PCI_CAP_NEXT(c) ((c) + 0x1)56 57 #define PCI_CAP_PMID 0x158 #define PCI_CAP_VENDORSPECID 0x959 46 60 47 extern errno_t pci_config_space_read_8(async_sess_t *, uint32_t, uint8_t *); … … 65 52 extern errno_t pci_config_space_write_16(async_sess_t *, uint32_t, uint16_t); 66 53 extern errno_t pci_config_space_write_32(async_sess_t *, uint32_t, uint32_t); 67 68 static inline errno_t69 pci_config_space_cap_first(async_sess_t *sess, uint8_t *c, uint8_t *id)70 {71 errno_t rc;72 uint16_t status;73 74 rc = pci_config_space_read_16(sess, PCI_STATUS, &status);75 if (rc != EOK)76 return rc;77 78 if (!(status & PCI_STATUS_CAP_LIST)) {79 *c = 0;80 return EOK;81 }82 83 rc = pci_config_space_read_8(sess, PCI_CAP_PTR, c);84 if (rc != EOK)85 return rc;86 if (!c)87 return EOK;88 return pci_config_space_read_8(sess, PCI_CAP_ID(*c), id);89 }90 91 static inline errno_t92 pci_config_space_cap_next(async_sess_t *sess, uint8_t *c, uint8_t *id)93 {94 errno_t rc = pci_config_space_read_8(sess, PCI_CAP_NEXT(*c), c);95 if (rc != EOK)96 return rc;97 if (!c)98 return EOK;99 return pci_config_space_read_8(sess, PCI_CAP_ID(*c), id);100 }101 54 102 55 /** PCI device communication interface. */ -
uspace/lib/posix/Makefile
r8119363 re768aea 82 82 TEST_SOURCES = \ 83 83 test/main.c \ 84 test/stdio.c \ 85 test/stdlib.c \ 86 test/unistd.c 87 88 EXTRA_TEST_CFLAGS = -Wno-deprecated-declarations 84 test/scanf.c 89 85 90 86 EXPORT_CPPFLAGS = \ -
uspace/lib/posix/include/posix/stdio.h
r8119363 re768aea 48 48 extern int fileno(FILE *); 49 49 50 #define P_tmpdir "/tmp"51 52 50 /* Identifying the Terminal */ 53 51 #undef L_ctermid … … 61 59 FILE *__restrict__ stream); 62 60 61 /* Error Messages */ 62 extern void perror(const char *s); 63 64 /* File Positioning */ 65 typedef struct { 66 off64_t offset; 67 } fpos_t; 68 69 extern int fsetpos(FILE *stream, const fpos_t *pos); 70 extern int fgetpos(FILE *__restrict__ stream, fpos_t *__restrict__ pos); 63 71 extern int fseeko(FILE *stream, off_t offset, int whence); 64 72 extern off_t ftello(FILE *stream); … … 68 76 _HELENOS_PRINTF_ATTRIBUTE(2, 3); 69 77 extern int vdprintf(int fildes, const char *__restrict__ format, va_list ap); 78 extern int sprintf(char *__restrict__ s, const char *__restrict__ format, ...) 79 _HELENOS_PRINTF_ATTRIBUTE(2, 3); 80 extern int vsprintf(char *__restrict__ s, const char *__restrict__ format, va_list ap); 70 81 71 82 /* File Locking */ … … 79 90 80 91 /* Temporary Files */ 92 #undef L_tmpnam 93 #define L_tmpnam PATH_MAX 94 extern char *tmpnam(char *s); 81 95 extern char *tempnam(const char *dir, const char *pfx); 96 extern FILE *tmpfile(void); 82 97 83 98 #endif /* POSIX_STDIO_H_ */ -
uspace/lib/posix/include/posix/stdlib.h
r8119363 re768aea 42 42 #include <_bits/NULL.h> 43 43 44 /* Absolute Value */ 45 extern int abs(int i); 46 extern long labs(long i); 47 extern long long llabs(long long i); 48 44 49 /* Environment Access */ 45 50 extern int putenv(char *string); … … 58 63 59 64 /* Legacy Declarations */ 60 extern char *mktemp(char *tmpl) __attribute__((deprecated));65 extern char *mktemp(char *tmpl); 61 66 extern int bsd_getloadavg(double loadavg[], int nelem); 62 67 -
uspace/lib/posix/include/posix/string.h
r8119363 re768aea 36 36 #ifndef POSIX_STRING_H_ 37 37 #define POSIX_STRING_H_ 38 39 #include "sys/types.h" 40 38 41 /* 39 42 * TODO: not implemented due to missing locale support … … 45 48 46 49 #include <_bits/NULL.h> 47 #include <_bits/size_t.h>48 50 49 #include "libc/mem.h" 51 /* 52 * These are the same as in HelenOS libc. 53 * It would be possible to directly include <str.h> and <mem.h> but 54 * it is better not to pollute POSIX namespace with other functions 55 * defined in that header. 56 * 57 * Because libposix is always linked with libc, providing only these 58 * forward declarations ought to be enough. 59 */ 60 61 /* From mem.h */ 62 // #define bzero(ptr, len) memset((ptr), 0, (len)) 63 extern void *memset(void *, int, size_t) 64 __attribute__((nonnull(1))); 65 extern void *memcpy(void *, const void *, size_t) 66 __attribute__((nonnull(1, 2))); 67 extern void *memmove(void *, const void *, size_t) 68 __attribute__((nonnull(1, 2))); 69 50 70 51 71 /* Copying and Concatenation */ … … 60 80 extern char *strndup(const char *s, size_t n); 61 81 62 /* String Comparison */ 82 /* String/Array Comparison */ 83 extern int memcmp(const void *mem1, const void *mem2, size_t n); 63 84 extern int strcmp(const char *s1, const char *s2); 64 85 extern int strncmp(const char *s1, const char *s2, size_t n); 65 86 66 87 /* Search Functions */ 88 extern void *memchr(const void *mem, int c, size_t n); 67 89 extern char *strchr(const char *s, int c); 68 90 extern char *strrchr(const char *s, int c); … … 100 122 #endif 101 123 124 102 125 #endif // POSIX_STRING_H_ 103 126 -
uspace/lib/posix/src/internal/common.h
r8119363 re768aea 66 66 } 67 67 68 extern aoff64_t posix_pos[ VFS_MAX_OPEN_FILES];68 extern aoff64_t posix_pos[MAX_OPEN_FILES]; 69 69 70 70 #endif /* LIBPOSIX_COMMON_H_ */ -
uspace/lib/posix/src/stdio.c
r8119363 re768aea 2 2 * Copyright (c) 2011 Jiri Zarevucky 3 3 * Copyright (c) 2011 Petr Koupy 4 * Copyright (c) 2018 Jiri Svoboda5 4 * All rights reserved. 6 5 * … … 39 38 40 39 #include <assert.h> 40 41 41 #include <errno.h> 42 #include <stdbool.h> 43 #include <tmpfile.h> 44 45 #include "posix/fcntl.h" 42 46 43 #include "posix/stdlib.h" 47 44 #include "posix/string.h" 48 #include "posix/sys/stat.h"49 45 #include "posix/sys/types.h" 50 46 #include "posix/unistd.h" … … 173 169 174 170 /** 171 * Write error messages to standard error. 172 * 173 * @param s Error message. 174 */ 175 void perror(const char *s) 176 { 177 if (s == NULL || s[0] == '\0') { 178 fprintf(stderr, "%s\n", strerror(errno)); 179 } else { 180 fprintf(stderr, "%s: %s\n", s, strerror(errno)); 181 } 182 } 183 184 /** Restores stream a to position previously saved with fgetpos(). 185 * 186 * @param stream Stream to restore 187 * @param pos Position to restore 188 * @return Zero on success, non-zero (with errno set) on failure 189 */ 190 int fsetpos(FILE *stream, const fpos_t *pos) 191 { 192 return fseek64(stream, pos->offset, SEEK_SET); 193 } 194 195 /** Saves the stream's position for later use by fsetpos(). 196 * 197 * @param stream Stream to save 198 * @param pos Place to store the position 199 * @return Zero on success, non-zero (with errno set) on failure 200 */ 201 int fgetpos(FILE *restrict stream, fpos_t *restrict pos) 202 { 203 off64_t ret = ftell64(stream); 204 if (ret != -1) { 205 pos->offset = ret; 206 return 0; 207 } else { 208 return -1; 209 } 210 } 211 212 /** 175 213 * Reposition a file-position indicator in a stream. 176 214 * … … 282 320 283 321 /** 322 * Print formatted output to the string. 323 * 324 * @param s Output string. 325 * @param format Format description. 326 * @return Either the number of printed characters (excluding null byte) or 327 * negative value on error. 328 */ 329 int sprintf(char *s, const char *restrict format, ...) 330 { 331 va_list list; 332 va_start(list, format); 333 int result = vsprintf(s, format, list); 334 va_end(list); 335 return result; 336 } 337 338 /** 339 * Print formatted output to the string. 340 * 341 * @param s Output string. 342 * @param format Format description. 343 * @param ap Print arguments. 344 * @return Either the number of printed characters (excluding null byte) or 345 * negative value on error. 346 */ 347 int vsprintf(char *s, const char *restrict format, va_list ap) 348 { 349 return vsnprintf(s, INT_MAX, format, ap); 350 } 351 352 /** 284 353 * Acquire file stream for the thread. 285 354 * … … 357 426 } 358 427 359 /** Determine if directory is an 'appropriate' temporary directory. 360 * 361 * @param dir Directory path 362 * @return @c true iff directory is appropriate. 363 */ 364 static bool is_appropriate_tmpdir(const char *dir) 365 { 366 struct stat sbuf; 367 368 /* Must not be NULL */ 369 if (dir == NULL) 370 return false; 371 372 /* Must not be empty */ 373 if (dir[0] == '\0') 374 return false; 375 376 if (stat(dir, &sbuf) != 0) 377 return false; 378 379 /* Must be a directory */ 380 if ((sbuf.st_mode & S_IFMT) != S_IFDIR) 381 return false; 382 383 /* Must be writable */ 384 if (access(dir, W_OK) != 0) 385 return false; 386 387 return true; 388 } 389 390 /** Construct unique file name. 391 * 392 * Never use this function. 428 /** 429 * Get a unique temporary file name (obsolete). 430 * 431 * @param s Buffer for the file name. Must be at least L_tmpnam bytes long. 432 * @return The value of s on success, NULL on failure. 433 */ 434 char *tmpnam(char *s) 435 { 436 assert(L_tmpnam >= strlen("/tmp/tnXXXXXX")); 437 438 static char buffer[L_tmpnam + 1]; 439 if (s == NULL) { 440 s = buffer; 441 } 442 443 strcpy(s, "/tmp/tnXXXXXX"); 444 mktemp(s); 445 446 if (*s == '\0') { 447 /* Errno set by mktemp(). */ 448 return NULL; 449 } 450 451 return s; 452 } 453 454 /** 455 * Get an unique temporary file name with additional constraints (obsolete). 393 456 * 394 457 * @param dir Path to directory, where the file should be created. … … 398 461 char *tempnam(const char *dir, const char *pfx) 399 462 { 400 const char *dpref; 401 char *d; 402 char *buf; 403 int rc; 404 405 d = getenv("TMPDIR"); 406 if (is_appropriate_tmpdir(d)) 407 dpref = d; 408 else if (is_appropriate_tmpdir(dir)) 409 dpref = dir; 410 else if (is_appropriate_tmpdir(P_tmpdir)) 411 dpref = P_tmpdir; 412 else 413 dpref = "/"; 414 415 if (dpref[strlen(dpref) - 1] != '/') 416 rc = asprintf(&buf, "%s/%sXXXXXX", dpref, pfx); 417 else 418 rc = asprintf(&buf, "%s%sXXXXXX", dpref, pfx); 419 420 if (rc < 0) 463 /* Sequence number of the filename. */ 464 static int seq = 0; 465 466 size_t dir_len = strlen(dir); 467 if (dir[dir_len - 1] == '/') { 468 dir_len--; 469 } 470 471 size_t pfx_len = strlen(pfx); 472 if (pfx_len > 5) { 473 pfx_len = 5; 474 } 475 476 char *result = malloc(dir_len + /* slash*/ 1 + 477 pfx_len + /* three-digit seq */ 3 + /* .tmp */ 4 + /* nul */ 1); 478 479 if (result == NULL) { 480 errno = ENOMEM; 421 481 return NULL; 422 423 rc = __tmpfile_templ(buf, false); 424 if (rc != 0) { 425 free(buf); 482 } 483 484 char *res_ptr = result; 485 strncpy(res_ptr, dir, dir_len); 486 res_ptr += dir_len; 487 strncpy(res_ptr, pfx, pfx_len); 488 res_ptr += pfx_len; 489 490 for (; seq < 1000; ++seq) { 491 snprintf(res_ptr, 8, "%03d.tmp", seq); 492 493 int orig_errno = errno; 494 errno = EOK; 495 /* Check if the file exists. */ 496 if (access(result, F_OK) == -1) { 497 if (errno == ENOENT) { 498 errno = orig_errno; 499 break; 500 } else { 501 /* errno set by access() */ 502 return NULL; 503 } 504 } 505 } 506 507 if (seq == 1000) { 508 free(result); 509 errno = EINVAL; 426 510 return NULL; 427 511 } 428 512 429 return buf; 513 return result; 514 } 515 516 /** 517 * Create and open an unique temporary file. 518 * The file is automatically removed when the stream is closed. 519 * 520 * @param dir Path to directory, where the file should be created. 521 * @param pfx Optional prefix up to 5 characters long. 522 * @return Newly allocated unique path for temporary file. NULL on failure. 523 */ 524 FILE *tmpfile(void) 525 { 526 char filename[] = "/tmp/tfXXXXXX"; 527 int fd = mkstemp(filename); 528 if (fd == -1) { 529 /* errno set by mkstemp(). */ 530 return NULL; 531 } 532 533 /* Unlink the created file, so that it's removed on close(). */ 534 unlink(filename); 535 return fdopen(fd, "w+"); 430 536 } 431 537 -
uspace/lib/posix/src/stdlib.c
r8119363 re768aea 38 38 39 39 #include <errno.h> 40 #include <tmpfile.h>41 40 42 41 #include "posix/fcntl.h" … … 50 49 #include "libc/vfs/vfs.h" 51 50 #include "libc/stats.h" 51 52 /** 53 * Integer absolute value. 54 * 55 * @param i Input value. 56 * @return Absolute value of the parameter. 57 */ 58 int abs(int i) 59 { 60 return i < 0 ? -i : i; 61 } 62 63 /** 64 * Long integer absolute value. 65 * 66 * @param i Input value. 67 * @return Absolute value of the parameter. 68 */ 69 long labs(long i) 70 { 71 return i < 0 ? -i : i; 72 } 73 74 /** 75 * Long long integer absolute value. 76 * 77 * @param i Input value. 78 * @return Absolute value of the parameter. 79 */ 80 long long llabs(long long i) 81 { 82 return i < 0 ? -i : i; 83 } 52 84 53 85 /** … … 164 196 int mkstemp(char *tmpl) 165 197 { 166 int tmpl_len; 167 int file; 168 169 tmpl_len = strlen(tmpl); 170 if (tmpl_len < 6) { 171 errno = EINVAL; 172 return -1; 173 } 174 175 char *tptr = tmpl + tmpl_len - 6; 176 if (strcmp(tptr, "XXXXXX") != 0) { 177 errno = EINVAL; 178 return -1; 179 } 180 181 file = __tmpfile_templ(tmpl, true); 182 if (file < 0) { 183 errno = EIO; // XXX could be more specific 184 return -1; 185 } 186 187 return file; 198 int fd = -1; 199 200 char *tptr = tmpl + strlen(tmpl) - 6; 201 202 while (fd < 0) { 203 if (*mktemp(tmpl) == '\0') { 204 /* Errno set by mktemp(). */ 205 return -1; 206 } 207 208 fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); 209 210 if (fd == -1) { 211 /* Restore template to it's original state. */ 212 snprintf(tptr, 7, "XXXXXX"); 213 } 214 } 215 216 return fd; 188 217 } 189 218 … … 198 227 char *mktemp(char *tmpl) 199 228 { 200 int tmpl_len; 201 int rc; 202 203 tmpl_len = strlen(tmpl); 229 int tmpl_len = strlen(tmpl); 204 230 if (tmpl_len < 6) { 205 231 errno = EINVAL; … … 215 241 } 216 242 217 rc = __tmpfile_templ(tmpl, false); 218 if (rc != 0) { 219 errno = EIO; // XXX could be more specific 243 static int seq = 0; 244 245 for (; seq < 1000000; ++seq) { 246 snprintf(tptr, 7, "%06d", seq); 247 248 int orig_errno = errno; 249 errno = 0; 250 /* Check if the file exists. */ 251 if (access(tmpl, F_OK) == -1) { 252 if (errno == ENOENT) { 253 errno = orig_errno; 254 break; 255 } else { 256 /* errno set by access() */ 257 *tmpl = '\0'; 258 return tmpl; 259 } 260 } 261 } 262 263 if (seq == 10000000) { 264 errno = EEXIST; 220 265 *tmpl = '\0'; 221 266 return tmpl; -
uspace/lib/posix/src/stdlib/strtold.c
r8119363 re768aea 52 52 #ifndef HUGE_VALL 53 53 #define HUGE_VALL (+1.0l / +0.0l) 54 #endif 55 56 #ifndef abs 57 #define abs(x) (((x) < 0) ? -(x) : (x)) 54 58 #endif 55 59 -
uspace/lib/posix/src/string.c
r8119363 re768aea 288 288 289 289 return 0; 290 } 291 292 /** 293 * Find byte in memory. 294 * 295 * @param mem Memory area in which to look for the byte. 296 * @param c Byte to look for. 297 * @param n Maximum number of bytes to be inspected. 298 * @return Pointer to the specified byte on success, 299 * NULL pointer otherwise. 300 */ 301 void *memchr(const void *mem, int c, size_t n) 302 { 303 assert(mem != NULL); 304 305 const unsigned char *s = mem; 306 307 for (size_t i = 0; i < n; ++i) { 308 if (s[i] == (unsigned char) c) { 309 return (void *) &s[i]; 310 } 311 } 312 return NULL; 290 313 } 291 314 -
uspace/lib/posix/src/unistd.c
r8119363 re768aea 39 39 #include <errno.h> 40 40 41 #include "posix/dirent.h"42 41 #include "posix/string.h" 43 #include "posix/sys/types.h"44 42 #include "posix/fcntl.h" 45 43 … … 53 51 54 52 // FIXME: replace with a hash table 55 aoff64_t posix_pos[ VFS_MAX_OPEN_FILES];53 aoff64_t posix_pos[MAX_OPEN_FILES]; 56 54 57 55 /* Array of environment variable strings (NAME=VALUE). */ … … 370 368 */ 371 369 int fd = open(path, O_RDONLY); 372 if (fd >= 0) { 373 close(fd); 374 return 0; 375 } 376 DIR *dir = opendir(path); 377 if (dir != NULL) { 378 closedir(dir); 379 return 0; 380 } 381 return -1; 370 if (fd < 0) 371 return -1; 372 close(fd); 373 return 0; 382 374 } else { 383 375 /* Invalid amode argument. */ -
uspace/lib/posix/test/main.c
r8119363 re768aea 1 1 /* 2 * Copyright (c) 201 8 Jiri Svoboda2 * Copyright (c) 2014 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 31 31 PCUT_INIT; 32 32 33 PCUT_IMPORT(stdio); 34 PCUT_IMPORT(stdlib); 35 PCUT_IMPORT(unistd); 33 PCUT_IMPORT(scanf); 36 34 37 35 PCUT_MAIN(); -
uspace/srv/vfs/vfs_file.c
r8119363 re768aea 71 71 fibril_mutex_lock(&vfs_data->lock); 72 72 if (!vfs_data->files) { 73 vfs_data->files = malloc( VFS_MAX_OPEN_FILES * sizeof(vfs_file_t *));73 vfs_data->files = malloc(MAX_OPEN_FILES * sizeof(vfs_file_t *)); 74 74 if (!vfs_data->files) { 75 75 fibril_mutex_unlock(&vfs_data->lock); 76 76 return false; 77 77 } 78 memset(vfs_data->files, 0, VFS_MAX_OPEN_FILES * sizeof(vfs_file_t *));78 memset(vfs_data->files, 0, MAX_OPEN_FILES * sizeof(vfs_file_t *)); 79 79 } 80 80 fibril_mutex_unlock(&vfs_data->lock); … … 90 90 return; 91 91 92 for (i = 0; i < VFS_MAX_OPEN_FILES; i++) {92 for (i = 0; i < MAX_OPEN_FILES; i++) { 93 93 if (vfs_data->files[i]) 94 94 (void) _vfs_fd_free(vfs_data, i); … … 199 199 unsigned int i; 200 200 if (desc) 201 i = VFS_MAX_OPEN_FILES - 1;201 i = MAX_OPEN_FILES - 1; 202 202 else 203 203 i = 0; … … 233 233 i--; 234 234 } else { 235 if (i == VFS_MAX_OPEN_FILES - 1)235 if (i == MAX_OPEN_FILES - 1) 236 236 break; 237 237 … … 261 261 static errno_t _vfs_fd_free_locked(vfs_client_data_t *vfs_data, int fd) 262 262 { 263 if ((fd < 0) || (fd >= VFS_MAX_OPEN_FILES) || !vfs_data->files[fd]) {263 if ((fd < 0) || (fd >= MAX_OPEN_FILES) || !vfs_data->files[fd]) { 264 264 return EBADF; 265 265 } … … 311 311 312 312 fibril_mutex_lock(&VFS_DATA->lock); 313 if ((fd < 0) || (fd >= VFS_MAX_OPEN_FILES)) {313 if ((fd < 0) || (fd >= MAX_OPEN_FILES)) { 314 314 fibril_mutex_unlock(&VFS_DATA->lock); 315 315 return EBADF; … … 342 342 343 343 fibril_mutex_lock(&vfs_data->lock); 344 if ((fd >= 0) && (fd < VFS_MAX_OPEN_FILES)) {344 if ((fd >= 0) && (fd < MAX_OPEN_FILES)) { 345 345 vfs_file_t *file = vfs_data->files[fd]; 346 346 if (file != NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.