2 * (C) GraÅžvydas "notaz" Ignotas, 2008-2010
4 * This work is licensed under the terms of any of these licenses
6 * - GNU GPL, version 2 or later.
7 * - GNU LGPL, version 2.1 or later.
8 * See the COPYING file in the top-level directory.
21 #include "../common/plat.h"
24 int plat_is_dir(const char *path)
27 if ((dir = opendir(path))) {
34 int plat_get_root_dir(char *dst, int len)
38 ret = readlink("/proc/self/exe", dst, len - 1);
45 for (j = strlen(dst); j > 0; j--)
55 /* Wiz has a borked gettimeofday().. */
56 #define plat_get_ticks_ms plat_get_ticks_ms_good
57 #define plat_get_ticks_us plat_get_ticks_us_good
60 unsigned int plat_get_ticks_ms(void)
65 gettimeofday(&tv, NULL);
67 ret = (unsigned)tv.tv_sec * 1000;
68 /* approximate /= 1000 */
69 ret += ((unsigned)tv.tv_usec * 4195) >> 22;
74 unsigned int plat_get_ticks_us(void)
79 gettimeofday(&tv, NULL);
81 ret = (unsigned)tv.tv_sec * 1000000;
82 ret += (unsigned)tv.tv_usec;
87 void plat_sleep_ms(int ms)
92 int plat_wait_event(int *fds_hnds, int count, int timeout_ms)
94 struct timeval tv, *timeout = NULL;
95 int i, ret, fdmax = -1;
98 if (timeout_ms >= 0) {
99 tv.tv_sec = timeout_ms / 1000;
100 tv.tv_usec = (timeout_ms % 1000) * 1000;
105 for (i = 0; i < count; i++) {
106 if (fds_hnds[i] > fdmax) fdmax = fds_hnds[i];
107 FD_SET(fds_hnds[i], &fdset);
110 ret = select(fdmax + 1, &fdset, NULL, NULL, timeout);
113 perror("plat_wait_event: select failed");
119 return -1; /* timeout */
122 for (i = 0; i < count; i++)
123 if (FD_ISSET(fds_hnds[i], &fdset))
129 void *plat_mmap(unsigned long addr, size_t size)
134 ret = mmap(req, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
135 if (ret == MAP_FAILED)
138 printf("warning: mmaped to %p, requested %p\n", ret, req);
143 void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
147 ret = mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE);
148 if (ret == MAP_FAILED)
151 printf("warning: mremap moved: %p -> %p\n", ptr, ret);
156 void plat_munmap(void *ptr, size_t size)
162 void lprintf(const char *fmt, ...)