[286] | 1 | /*
|
---|
| 2 | * TOPPERS ECHONET Lite Communication Middleware
|
---|
| 3 | *
|
---|
| 4 | * Copyright (C) 2017 Cores Co., Ltd. Japan
|
---|
| 5 | *
|
---|
| 6 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
| 7 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
| 8 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
| 9 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
| 10 | * \¦C±Ìpð¨æѺL̳ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
| 11 | * XR[hÉÜÜêÄ¢é±ÆD
|
---|
| 12 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
| 13 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
| 14 | gip
|
---|
| 15 | * Ò}j
|
---|
| 16 | AÈÇjÉCãLÌì \¦C±Ìpð¨æѺL
|
---|
| 17 | * ̳ÛØKèðfÚ·é±ÆD
|
---|
| 18 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
| 19 | * pÅ«È¢`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
| 20 | * ÆD
|
---|
| 21 | * (a) Äzzɺ¤hL
|
---|
| 22 | gipÒ}j
|
---|
| 23 | AÈÇjÉCãLÌ
|
---|
| 24 | * ì \¦C±Ìpð¨æѺL̳ÛØKèðfÚ·é±ÆD
|
---|
| 25 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
| 26 | * ñ·é±ÆD
|
---|
| 27 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
| 28 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
| 29 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
| 30 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
| 31 | * ÆÓ·é±ÆD
|
---|
| 32 | *
|
---|
| 33 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
| 34 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
| 35 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
| 36 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
[279] | 37 | * ÌÓCðíÈ¢D
|
---|
| 38 | *
|
---|
| 39 | * @(#) $Id: shellif.c 286 2017-05-02 15:25:33Z coas-nagasima $
|
---|
| 40 | */
|
---|
| 41 | #include <setjmp.h>
|
---|
| 42 | #include <sys/socket.h>
|
---|
| 43 | #include <sys/time.h>
|
---|
| 44 | #include <sys/select.h>
|
---|
| 45 | #include <poll.h>
|
---|
| 46 | #include <stdarg.h>
|
---|
| 47 | #include "shellif.h"
|
---|
| 48 | #include "analogin_api.h"
|
---|
| 49 | #include "gpio_api.h"
|
---|
| 50 | #include "i2c_api.h"
|
---|
| 51 | #include "pwmout_api.h"
|
---|
| 52 | #include "rtc_api.h"
|
---|
| 53 | #include "serial_api.h"
|
---|
| 54 | #include "us_ticker_api.h"
|
---|
| 55 | #include "wait_api.h"
|
---|
| 56 | #include "arduino.h"
|
---|
| 57 | #include "usrcmd.h"
|
---|
| 58 | #include <sys/mman.h>
|
---|
| 59 | #include <signal.h>
|
---|
| 60 |
|
---|
| 61 | typedef struct __dirstream DIR;
|
---|
| 62 |
|
---|
| 63 | typedef void (*analogin_init_t)(analogin_t *obj, PinName pin);
|
---|
| 64 | typedef uint16_t (*analogin_read_u16_t)(analogin_t *obj);
|
---|
| 65 | typedef void (*gpio_init_t)(gpio_t *obj, PinName pin);
|
---|
| 66 | typedef void (*gpio_dir_t)(gpio_t *obj, PinDirection direction);
|
---|
| 67 | typedef int (*i2c_start_t)(i2c_t *obj);
|
---|
| 68 | typedef int (*i2c_stop_t)(i2c_t *obj);
|
---|
| 69 | typedef void (*i2c_init_t)(i2c_t *obj, PinName sda, PinName scl);
|
---|
| 70 | typedef int (*i2c_read_t)(i2c_t *obj, int address, char *data, int length, int stop);
|
---|
| 71 | typedef int (*i2c_write_t)(i2c_t *obj, int address, const char *data, int length, int stop);
|
---|
| 72 | typedef int (*i2c_byte_read_t)(i2c_t *obj, int last);
|
---|
| 73 | typedef int (*i2c_byte_write_t)(i2c_t *obj, int data);
|
---|
| 74 | typedef void (*pwmout_free_t)(pwmout_t* obj);
|
---|
| 75 | typedef void (*pwmout_init_t)(pwmout_t* obj, PinName pin);
|
---|
| 76 | typedef void (*pwmout_pulsewidth_us_t)(pwmout_t* obj, int us);
|
---|
| 77 | typedef void (*rtc_init_t)(void);
|
---|
| 78 | typedef void (*rtc_free_t)(void);
|
---|
| 79 | typedef int (*rtc_isenabled_t)(void);
|
---|
| 80 | typedef time_t (*rtc_read_t)(void);
|
---|
| 81 | typedef void (*rtc_write_t)(time_t t);
|
---|
| 82 | typedef void (*serial_baud_t)(serial_t *obj, int baudrate);
|
---|
| 83 | typedef void (*serial_init_t)(serial_t *obj, PinName tx, PinName rx);
|
---|
| 84 | typedef int (*serial_readable_t)(serial_t *obj);
|
---|
| 85 | typedef int (*serial_getc_t)(serial_t *obj);
|
---|
| 86 | typedef void (*serial_putc_t)(serial_t *obj, int c);
|
---|
| 87 | typedef uint32_t (*us_ticker_read_t)(void);
|
---|
| 88 | typedef void (*wait_ms_t)(int ms);
|
---|
| 89 | typedef bool (*SD_begin_t)();
|
---|
| 90 | typedef int (*usrcmd_cd_t)(int argc, char **argv);
|
---|
| 91 | typedef int (*usrcmd_ls_t)(int argc, char **argv);
|
---|
| 92 | typedef int (*usrcmd_cp_t)(int argc, char **argv);
|
---|
| 93 | typedef int (*usrcmd_rm_t)(int argc, char **argv);
|
---|
| 94 | typedef int (*usrcmd_mv_t)(int argc, char **argv);
|
---|
| 95 | typedef int (*usrcmd_mkdir_t)(int argc, char **argv);
|
---|
| 96 | typedef int (*usrcmd_hexdump_t)(int argc, char **argv);
|
---|
| 97 | typedef int (*usrcmd_info_t)(int argc, char **argv);
|
---|
| 98 | typedef int (*usrcmd_exit_t)(int argc, char **argv);
|
---|
| 99 | typedef void(*shell_abort_t)();
|
---|
| 100 | typedef void(*shell_exit_t)(int exitcd);
|
---|
| 101 | typedef int (*shell_kill_t)(int pid, int sig);
|
---|
| 102 | typedef int (*shell_gettimeofday_t)(struct timeval * tp, void * tzvp);
|
---|
| 103 | typedef void (*vsyslog_t)(int priority, const char *format, va_list ap);
|
---|
| 104 | typedef int (*shell_open_t)(const char * path, int flags);
|
---|
| 105 | typedef int (*shell_close_t)(int fd);
|
---|
| 106 | typedef int (*shell_read_t)(int fd, char *data, int len);
|
---|
| 107 | typedef int (*shell_write_t)(int fd, char *data, int len);
|
---|
| 108 | typedef int (*shell_lseek_t)(int fd, int ptr, int dir);
|
---|
| 109 | typedef int (*shell_fstat_t)(int fd, struct stat * st);
|
---|
| 110 | typedef int (*shell_stat_t)(const char *fname, struct stat *st);
|
---|
| 111 | typedef int (*shell_link_t)(void);
|
---|
| 112 | typedef int (*shell_unlink_t)(const char *path);
|
---|
| 113 | typedef int (*shell_isatty_t)(int fd);
|
---|
| 114 | typedef int (*fsync_t)(int fd);
|
---|
| 115 | typedef int (*ftruncate_t)(int fd, off_t length);
|
---|
| 116 | typedef int (*ioctl_t)(int fd, int request, va_list ap);
|
---|
| 117 | typedef int (*tcgetattr_t)(int fd, struct termios *termios_p);
|
---|
| 118 | typedef int (*tcsetattr_t)(int fd, int optional_actions, const struct termios *termios_p);
|
---|
| 119 | typedef int (*shell_rename_t)(const char *oldpath, const char *newpath);
|
---|
| 120 | typedef int (*rmdir_t)(const char *path);
|
---|
| 121 | typedef int (*mkdir_t)(const char *path, mode_t mode);
|
---|
| 122 | typedef int (*chmod_t)(const char *path, mode_t mode);
|
---|
| 123 | typedef char *(*getcwd_t)(char *buf, size_t size);
|
---|
| 124 | typedef int (*chdir_t)(const char *path);
|
---|
| 125 | typedef int (*chroot_t)(const char *path);
|
---|
| 126 | typedef int (*closedir_t)(DIR *dir);
|
---|
| 127 | typedef DIR *(*opendir_t)(const char *path);
|
---|
| 128 | typedef struct dirent *(*readdir_t)(DIR *dir);
|
---|
| 129 | typedef void (*rewinddir_t)(DIR *dir);
|
---|
| 130 | typedef void (*seekdir_t)(DIR *dir, long pos);
|
---|
| 131 | typedef long (*telldir_t)(DIR *dir);
|
---|
| 132 | typedef int (*shell_getpid_t)();
|
---|
| 133 | typedef int (*socket_t)(int family, int type, int protocol);
|
---|
| 134 | typedef int (*bind_t)(int fd, const struct sockaddr *addr, socklen_t len);
|
---|
| 135 | typedef int (*listen_t)(int fd, int backlog);
|
---|
| 136 | typedef int (*connect_t)(int fd, const struct sockaddr *addr, socklen_t len);
|
---|
| 137 | typedef int (*accept_t)(int fd, struct sockaddr *addr, socklen_t *len);
|
---|
| 138 | typedef ssize_t (*send_t)(int fd, const void *buf, size_t len, int flags);
|
---|
| 139 | typedef ssize_t (*sendto_t)(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen);
|
---|
| 140 | typedef ssize_t (*recv_t)(int fd, void *buf, size_t len, int flags);
|
---|
| 141 | typedef ssize_t (*recvfrom_t)(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen);
|
---|
| 142 | typedef int (*shutdown_t)(int fd, int how);
|
---|
| 143 | typedef int (*getsockopt_t)(int fd, int level, int optname, void *optval, socklen_t *optlen);
|
---|
| 144 | typedef int (*setsockopt_t)(int fd, int level, int optname, const void *optval, socklen_t optlen);
|
---|
| 145 | typedef int (*select_t)(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv);
|
---|
| 146 | typedef int (*poll_t)(struct pollfd *fds, nfds_t nfds, int timeout);
|
---|
| 147 | typedef int (*gethostname_t)(char *name, size_t len);
|
---|
| 148 | typedef int (*getnameinfo_t)(const struct sockaddr *sa, socklen_t sl, char *node, socklen_t nodelen, char *serv, socklen_t servlen, int flags);
|
---|
| 149 | typedef int (*getpeername_t)(int fd, struct sockaddr *addr, socklen_t *len);
|
---|
| 150 | typedef int (*getsockname_t)(int fd, struct sockaddr *addr, socklen_t *len);
|
---|
| 151 | typedef int (*socketpair_t)(int family, int type, int protocol, int fd[2]);
|
---|
| 152 |
|
---|
| 153 | void analogin_init(analogin_t *obj, PinName pin)
|
---|
| 154 | {
|
---|
| 155 | __imp_analogin_init(obj, pin);
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | uint16_t analogin_read_u16(analogin_t *obj)
|
---|
| 159 | {
|
---|
| 160 | return __imp_analogin_read_u16(obj);
|
---|
| 161 | }
|
---|
| 162 |
|
---|
| 163 | void gpio_init(gpio_t *obj, PinName pin)
|
---|
| 164 | {
|
---|
| 165 | __imp_gpio_init(obj, pin);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | void gpio_dir(gpio_t *obj, PinDirection direction)
|
---|
| 169 | {
|
---|
| 170 | __imp_gpio_dir(obj, direction);
|
---|
| 171 | }
|
---|
| 172 |
|
---|
| 173 | int i2c_start(i2c_t *obj)
|
---|
| 174 | {
|
---|
| 175 | return __imp_i2c_start(obj);
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | int i2c_stop(i2c_t *obj)
|
---|
| 179 | {
|
---|
| 180 | return __imp_i2c_stop(obj);
|
---|
| 181 | }
|
---|
| 182 |
|
---|
| 183 | void i2c_init(i2c_t *obj, PinName sda, PinName scl)
|
---|
| 184 | {
|
---|
| 185 | __imp_i2c_init(obj, sda, scl);
|
---|
| 186 | }
|
---|
| 187 |
|
---|
| 188 | int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
|
---|
| 189 | {
|
---|
| 190 | return __imp_i2c_read(obj, address, data, length, stop);
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
|
---|
| 194 | {
|
---|
| 195 | return __imp_i2c_write(obj, address, data, length, stop);
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | int i2c_byte_read(i2c_t *obj, int last)
|
---|
| 199 | {
|
---|
| 200 | return __imp_i2c_byte_read(obj, last);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | int i2c_byte_write(i2c_t *obj, int data)
|
---|
| 204 | {
|
---|
| 205 | return __imp_i2c_byte_write(obj, data);
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | void pwmout_free(pwmout_t* obj)
|
---|
| 209 | {
|
---|
| 210 | __imp_pwmout_free(obj);
|
---|
| 211 | }
|
---|
| 212 |
|
---|
| 213 | void pwmout_init(pwmout_t* obj, PinName pin)
|
---|
| 214 | {
|
---|
| 215 | __imp_pwmout_init(obj, pin);
|
---|
| 216 | }
|
---|
| 217 |
|
---|
| 218 | void pwmout_pulsewidth_us(pwmout_t* obj, int us)
|
---|
| 219 | {
|
---|
| 220 | __imp_pwmout_pulsewidth_us(obj, us);
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 | void rtc_init(void)
|
---|
| 224 | {
|
---|
| 225 | __imp_rtc_init();
|
---|
| 226 | }
|
---|
| 227 |
|
---|
| 228 | void rtc_free(void)
|
---|
| 229 | {
|
---|
| 230 | __imp_rtc_free();
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | int rtc_isenabled(void)
|
---|
| 234 | {
|
---|
| 235 | return __imp_rtc_isenabled();
|
---|
| 236 | }
|
---|
| 237 |
|
---|
| 238 | time_t rtc_read(void)
|
---|
| 239 | {
|
---|
| 240 | return __imp_rtc_read();
|
---|
| 241 | }
|
---|
| 242 |
|
---|
| 243 | void rtc_write(time_t t)
|
---|
| 244 | {
|
---|
| 245 | __imp_rtc_write(t);
|
---|
| 246 | }
|
---|
| 247 |
|
---|
| 248 | void serial_baud(serial_t *obj, int baudrate)
|
---|
| 249 | {
|
---|
| 250 | __imp_serial_baud(obj, baudrate);
|
---|
| 251 | }
|
---|
| 252 |
|
---|
| 253 | void serial_init(serial_t *obj, PinName tx, PinName rx)
|
---|
| 254 | {
|
---|
| 255 | __imp_serial_init(obj, tx, rx);
|
---|
| 256 | }
|
---|
| 257 |
|
---|
| 258 | int serial_readable(serial_t *obj)
|
---|
| 259 | {
|
---|
| 260 | return __imp_serial_readable(obj);
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | int serial_getc(serial_t *obj)
|
---|
| 264 | {
|
---|
| 265 | return __imp_serial_getc(obj);
|
---|
| 266 | }
|
---|
| 267 |
|
---|
| 268 | void serial_putc(serial_t *obj, int c)
|
---|
| 269 | {
|
---|
| 270 | __imp_serial_putc(obj, c);
|
---|
| 271 | }
|
---|
| 272 |
|
---|
| 273 | uint32_t us_ticker_read(void)
|
---|
| 274 | {
|
---|
| 275 | return __imp_us_ticker_read();
|
---|
| 276 | }
|
---|
| 277 |
|
---|
| 278 | void wait_ms(int ms)
|
---|
| 279 | {
|
---|
| 280 | __imp_wait_ms(ms);
|
---|
| 281 | }
|
---|
| 282 |
|
---|
| 283 | bool SD_begin()
|
---|
| 284 | {
|
---|
| 285 | return __imp_SD_begin();
|
---|
| 286 | }
|
---|
| 287 |
|
---|
| 288 | int usrcmd_cd(int argc, char **argv)
|
---|
| 289 | {
|
---|
| 290 | return __imp_usrcmd_cd(argc, argv);
|
---|
| 291 | }
|
---|
| 292 |
|
---|
| 293 | int usrcmd_ls(int argc, char **argv)
|
---|
| 294 | {
|
---|
| 295 | return __imp_usrcmd_ls(argc, argv);
|
---|
| 296 | }
|
---|
| 297 |
|
---|
| 298 | int usrcmd_cp(int argc, char **argv)
|
---|
| 299 | {
|
---|
| 300 | return __imp_usrcmd_cp(argc, argv);
|
---|
| 301 | }
|
---|
| 302 |
|
---|
| 303 | int usrcmd_rm(int argc, char **argv)
|
---|
| 304 | {
|
---|
| 305 | return __imp_usrcmd_rm(argc, argv);
|
---|
| 306 | }
|
---|
| 307 |
|
---|
| 308 | int usrcmd_mv(int argc, char **argv)
|
---|
| 309 | {
|
---|
| 310 | return __imp_usrcmd_mv(argc, argv);
|
---|
| 311 | }
|
---|
| 312 |
|
---|
| 313 | int usrcmd_mkdir(int argc, char **argv)
|
---|
| 314 | {
|
---|
| 315 | return __imp_usrcmd_mkdir(argc, argv);
|
---|
| 316 | }
|
---|
| 317 |
|
---|
| 318 | int usrcmd_hexdump(int argc, char **argv)
|
---|
| 319 | {
|
---|
| 320 | return __imp_usrcmd_hexdump(argc, argv);
|
---|
| 321 | }
|
---|
| 322 |
|
---|
| 323 | int usrcmd_info(int argc, char **argv)
|
---|
| 324 | {
|
---|
| 325 | return __imp_usrcmd_info(argc, argv);
|
---|
| 326 | }
|
---|
| 327 |
|
---|
| 328 | int usrcmd_exit(int argc, char **argv)
|
---|
| 329 | {
|
---|
| 330 | return __imp_usrcmd_exit(argc, argv);
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 | void abort()
|
---|
| 334 | {
|
---|
| 335 | __imp_shell_abort();
|
---|
| 336 | }
|
---|
| 337 |
|
---|
| 338 | void _exit(int exitcd)
|
---|
| 339 | {
|
---|
| 340 | __imp_shell_exit(exitcd);
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | int _kill(int pid, int sig)
|
---|
| 344 | {
|
---|
| 345 | return __imp_shell_kill(pid, sig);
|
---|
| 346 | }
|
---|
| 347 |
|
---|
| 348 | int _gettimeofday(struct timeval * tp, void * tzvp)
|
---|
| 349 | {
|
---|
| 350 | return __imp_shell_gettimeofday(tp, tzvp);
|
---|
| 351 | }
|
---|
| 352 |
|
---|
| 353 | void vsyslog(int priority, const char *format, va_list ap)
|
---|
| 354 | {
|
---|
| 355 | __imp_vsyslog(priority, format, ap);
|
---|
| 356 | }
|
---|
| 357 |
|
---|
| 358 | void syslog(int priority, const char *format, ...)
|
---|
| 359 | {
|
---|
| 360 | va_list ap;
|
---|
| 361 | va_start(ap, format);
|
---|
| 362 | vsyslog(priority, format, ap);
|
---|
| 363 | va_end(ap);
|
---|
| 364 | }
|
---|
| 365 |
|
---|
| 366 | int _open(const char * path, int flags)
|
---|
| 367 | {
|
---|
| 368 | return __imp_shell_open(path, flags);
|
---|
| 369 | }
|
---|
| 370 |
|
---|
| 371 | int _close(int fd)
|
---|
| 372 | {
|
---|
| 373 | return __imp_shell_close(fd);
|
---|
| 374 | }
|
---|
| 375 |
|
---|
| 376 | int _read(int fd, char *data, int len)
|
---|
| 377 | {
|
---|
| 378 | return __imp_shell_read(fd, data, len);
|
---|
| 379 | }
|
---|
| 380 |
|
---|
| 381 | int _write(int fd, char *data, int len)
|
---|
| 382 | {
|
---|
| 383 | return __imp_shell_write(fd, data, len);
|
---|
| 384 | }
|
---|
| 385 |
|
---|
| 386 | int _lseek(int fd, int ptr, int dir)
|
---|
| 387 | {
|
---|
| 388 | return __imp_shell_lseek(fd, ptr, dir);
|
---|
| 389 | }
|
---|
| 390 |
|
---|
| 391 | int _fstat(int fd, struct stat * st)
|
---|
| 392 | {
|
---|
| 393 | return __imp_shell_fstat(fd, st);
|
---|
| 394 | }
|
---|
| 395 |
|
---|
| 396 | int _stat(const char *fname, struct stat *st)
|
---|
| 397 | {
|
---|
| 398 | return __imp_shell_stat(fname, st);
|
---|
| 399 | }
|
---|
| 400 |
|
---|
| 401 | int _link(void)
|
---|
| 402 | {
|
---|
| 403 | return __imp_shell_link();
|
---|
| 404 | }
|
---|
| 405 |
|
---|
| 406 | int _unlink(const char *path)
|
---|
| 407 | {
|
---|
| 408 | return __imp_shell_unlink(path);
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | int _isatty(int fd)
|
---|
| 412 | {
|
---|
| 413 | return __imp_shell_isatty(fd);
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | int fsync(int fd)
|
---|
| 417 | {
|
---|
| 418 | return __imp_fsync(fd);
|
---|
| 419 | }
|
---|
| 420 |
|
---|
| 421 | int ftruncate(int fd, off_t length)
|
---|
| 422 | {
|
---|
| 423 | return __imp_ftruncate(fd, length);
|
---|
| 424 | }
|
---|
| 425 |
|
---|
| 426 | int ioctl(int fd, int request, ...)
|
---|
| 427 | {
|
---|
| 428 | int result;
|
---|
| 429 | va_list ap;
|
---|
| 430 | va_start(ap, request);
|
---|
| 431 | result = __imp_ioctl(fd, request, ap);
|
---|
| 432 | va_end(ap);
|
---|
| 433 | return result;
|
---|
| 434 | }
|
---|
| 435 |
|
---|
| 436 | int tcgetattr(int fd, struct termios *termios_p)
|
---|
| 437 | {
|
---|
| 438 | return __imp_tcgetattr(fd, termios_p);
|
---|
| 439 | }
|
---|
| 440 |
|
---|
| 441 | int tcsetattr(int fd, int optional_actions, const struct termios *termios_p)
|
---|
| 442 | {
|
---|
| 443 | return __imp_tcsetattr(fd, optional_actions, termios_p);
|
---|
| 444 | }
|
---|
| 445 |
|
---|
| 446 | int _rename(const char *oldpath, const char *newpath)
|
---|
| 447 | {
|
---|
| 448 | return __imp_shell_rename(oldpath, newpath);
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 | int rmdir(const char *path)
|
---|
| 452 | {
|
---|
| 453 | return __imp_rmdir(path);
|
---|
| 454 | }
|
---|
| 455 |
|
---|
| 456 | int mkdir(const char *path, mode_t mode)
|
---|
| 457 | {
|
---|
| 458 | return __imp_mkdir(path, mode);
|
---|
| 459 | }
|
---|
| 460 |
|
---|
| 461 | int chmod(const char *path, mode_t mode)
|
---|
| 462 | {
|
---|
| 463 | return __imp_chmod(path, mode);
|
---|
| 464 | }
|
---|
| 465 |
|
---|
| 466 | char *getcwd(char *buf, size_t size)
|
---|
| 467 | {
|
---|
| 468 | return __imp_getcwd(buf, size);
|
---|
| 469 | }
|
---|
| 470 |
|
---|
| 471 | int chdir(const char *path)
|
---|
| 472 | {
|
---|
| 473 | return __imp_chdir(path);
|
---|
| 474 | }
|
---|
| 475 |
|
---|
| 476 | int chroot(const char *path)
|
---|
| 477 | {
|
---|
| 478 | return __imp_chroot(path);
|
---|
| 479 | }
|
---|
| 480 |
|
---|
| 481 | int closedir(DIR *dir)
|
---|
| 482 | {
|
---|
| 483 | return __imp_closedir(dir);
|
---|
| 484 | }
|
---|
| 485 |
|
---|
| 486 | DIR *opendir(const char *path)
|
---|
| 487 | {
|
---|
| 488 | return __imp_opendir(path);
|
---|
| 489 | }
|
---|
| 490 |
|
---|
| 491 | struct dirent *readdir(DIR *dir)
|
---|
| 492 | {
|
---|
| 493 | return __imp_readdir(dir);
|
---|
| 494 | }
|
---|
| 495 |
|
---|
| 496 | void rewinddir(DIR *dir)
|
---|
| 497 | {
|
---|
| 498 | __imp_rewinddir(dir);
|
---|
| 499 | }
|
---|
| 500 |
|
---|
| 501 | void seekdir(DIR *dir, long pos)
|
---|
| 502 | {
|
---|
| 503 | __imp_seekdir(dir, pos);
|
---|
| 504 | }
|
---|
| 505 |
|
---|
| 506 | long telldir(DIR *dir)
|
---|
| 507 | {
|
---|
| 508 | return __imp_telldir(dir);
|
---|
| 509 | }
|
---|
| 510 |
|
---|
| 511 | int _getpid()
|
---|
| 512 | {
|
---|
| 513 | return __imp_shell_getpid();
|
---|
| 514 | }
|
---|
| 515 |
|
---|
| 516 | int socket(int family, int type, int protocol)
|
---|
| 517 | {
|
---|
| 518 | return __imp_socket(family, type, protocol);
|
---|
| 519 | }
|
---|
| 520 |
|
---|
| 521 | int bind(int fd, const struct sockaddr *addr, socklen_t len)
|
---|
| 522 | {
|
---|
| 523 | return __imp_bind(fd, addr, len);
|
---|
| 524 | }
|
---|
| 525 |
|
---|
| 526 | int listen(int fd, int backlog)
|
---|
| 527 | {
|
---|
| 528 | return __imp_listen(fd, backlog);
|
---|
| 529 | }
|
---|
| 530 |
|
---|
| 531 | int connect(int fd, const struct sockaddr *addr, socklen_t len)
|
---|
| 532 | {
|
---|
| 533 | return __imp_connect(fd, addr, len);
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | int accept(int fd, struct sockaddr *addr, socklen_t *len)
|
---|
| 537 | {
|
---|
| 538 | return __imp_accept(fd, addr, len);
|
---|
| 539 | }
|
---|
| 540 |
|
---|
| 541 | ssize_t send(int fd, const void *buf, size_t len, int flags)
|
---|
| 542 | {
|
---|
| 543 | return __imp_send(fd, buf, len, flags);
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen)
|
---|
| 547 | {
|
---|
| 548 | return __imp_sendto(fd, buf, len, flags, addr, alen);
|
---|
| 549 | }
|
---|
| 550 |
|
---|
| 551 | ssize_t recv(int fd, void *buf, size_t len, int flags)
|
---|
| 552 | {
|
---|
| 553 | return __imp_recv(fd, buf, len, flags);
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | ssize_t recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr *addr, socklen_t *alen)
|
---|
| 557 | {
|
---|
| 558 | return __imp_recvfrom(fd, buf, len, flags, addr, alen);
|
---|
| 559 | }
|
---|
| 560 |
|
---|
| 561 | int shutdown(int fd, int how)
|
---|
| 562 | {
|
---|
| 563 | return __imp_shutdown(fd, how);
|
---|
| 564 | }
|
---|
| 565 |
|
---|
| 566 | int getsockopt(int fd, int level, int optname, void *optval, socklen_t *optlen)
|
---|
| 567 | {
|
---|
| 568 | return __imp_getsockopt(fd, level, optname, optval, optlen);
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
|
---|
| 572 | {
|
---|
| 573 | return __imp_setsockopt(fd, level, optname, optval, optlen);
|
---|
| 574 | }
|
---|
| 575 |
|
---|
| 576 | int select(int n, fd_set *rfds, fd_set *wfds, fd_set *efds, struct timeval *tv)
|
---|
| 577 | {
|
---|
| 578 | return __imp_select(n, rfds, wfds, efds, tv);
|
---|
| 579 | }
|
---|
| 580 |
|
---|
| 581 | int poll(struct pollfd *fds, nfds_t nfds, int timeout)
|
---|
| 582 | {
|
---|
| 583 | return __imp_poll(fds, nfds, timeout);
|
---|
| 584 | }
|
---|
| 585 |
|
---|
| 586 | unsigned if_nametoindex(const char *name)
|
---|
| 587 | {
|
---|
| 588 | return 1;
|
---|
| 589 | }
|
---|
| 590 |
|
---|
| 591 | int gethostname(char *name, size_t len)
|
---|
| 592 | {
|
---|
| 593 | return __imp_gethostname(name, len);
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | int getnameinfo(const struct sockaddr *sa, socklen_t sl,
|
---|
| 597 | char *node, socklen_t nodelen,
|
---|
| 598 | char *serv, socklen_t servlen,
|
---|
| 599 | int flags)
|
---|
| 600 | {
|
---|
| 601 | return __imp_getnameinfo(sa, sl, node, nodelen, serv, servlen, flags);
|
---|
| 602 | }
|
---|
| 603 |
|
---|
| 604 | int getpeername(int fd, struct sockaddr *addr, socklen_t *len)
|
---|
| 605 | {
|
---|
| 606 | return __imp_getpeername(fd, addr, len);
|
---|
| 607 | }
|
---|
| 608 |
|
---|
| 609 | int getsockname(int fd, struct sockaddr *addr, socklen_t *len)
|
---|
| 610 | {
|
---|
| 611 | return __imp_getsockname(fd, addr, len);
|
---|
| 612 | }
|
---|
| 613 |
|
---|
| 614 | int socketpair(int family, int type, int protocol, int fd[2])
|
---|
| 615 | {
|
---|
| 616 | return __imp_socketpair(family, type, protocol, fd);
|
---|
| 617 | }
|
---|
| 618 |
|
---|
| 619 | char *basename(char *s)
|
---|
| 620 | {
|
---|
| 621 | size_t i, j;
|
---|
| 622 | if (!s || !*s) return ".";
|
---|
| 623 | i = strlen(s) - 1;
|
---|
| 624 | for (j = 0; j <= i; j++) if (s[j] == ':') { s = &s[j + 1]; i -= j; break; }
|
---|
| 625 | for (; i&&s[i] == '/'; i--) s[i] = 0;
|
---|
| 626 | for (; i&&s[i - 1] != '/'; i--);
|
---|
| 627 | return s + i;
|
---|
| 628 | }
|
---|
| 629 |
|
---|
| 630 | char *dirname(char *_s)
|
---|
| 631 | {
|
---|
| 632 | char *s = _s;
|
---|
| 633 | size_t i, j;
|
---|
| 634 | if (!s || !*s) return ".";
|
---|
| 635 | i = strlen(s) - 1;
|
---|
| 636 | for (j = 0; j <= i; j++) if (s[j] == ':') { s = &s[j + 1]; i -= j; break; }
|
---|
| 637 | for (; s[i] == '/'; i--) if (!i) return (s == _s) ? "/" : _s;
|
---|
| 638 | for (; s[i] != '/'; i--) if (!i) return (s == _s) ? "." : _s;
|
---|
| 639 | for (; s[i] == '/'; i--) if (!i) if (s == _s) return "/"; else break;
|
---|
| 640 | s[i + 1] = 0;
|
---|
| 641 | return _s;
|
---|
| 642 | }
|
---|
| 643 |
|
---|
| 644 | char *realpath(const char *filename, char *resolved)
|
---|
| 645 | {
|
---|
| 646 | char *path = getcwd(resolved, 256);
|
---|
| 647 |
|
---|
| 648 | if (path != NULL)
|
---|
| 649 | strcat(path, filename);
|
---|
| 650 |
|
---|
| 651 | return path;
|
---|
| 652 | }
|
---|
| 653 |
|
---|
| 654 | uint32_t htonl(uint32_t n)
|
---|
| 655 | {
|
---|
| 656 | return (n >> 24) | ((n >> 8) & 0xFF00) | ((n << 8) & 0xFF0000) | (n << 24);
|
---|
| 657 | }
|
---|
| 658 |
|
---|
| 659 | uint32_t ntohl(uint32_t n)
|
---|
| 660 | {
|
---|
| 661 | return (n >> 24) | ((n >> 8) & 0xFF00) | ((n << 8) & 0xFF0000) | (n << 24);
|
---|
| 662 | }
|
---|
| 663 |
|
---|
| 664 | uint16_t htons(uint16_t n)
|
---|
| 665 | {
|
---|
| 666 | return ((n >> 8) & 0xFF) | ((n << 8) & 0xFF00);
|
---|
| 667 | }
|
---|
| 668 |
|
---|
| 669 | uint16_t ntohs(uint16_t n)
|
---|
| 670 | {
|
---|
| 671 | return ((n >> 8) & 0xFF) | ((n << 8) & 0xFF00);
|
---|
| 672 | }
|
---|
| 673 |
|
---|
| 674 | int mprotect(void *addr, size_t len, int prot)
|
---|
| 675 | {
|
---|
| 676 | return 0;
|
---|
| 677 | }
|
---|
| 678 |
|
---|
| 679 | int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
|
---|
| 680 | {
|
---|
| 681 | return 0;
|
---|
| 682 | }
|
---|
| 683 |
|
---|
| 684 | unsigned int Utf8_to_Utf16(const char *src, int *code_size)
|
---|
| 685 | {
|
---|
| 686 | int i;
|
---|
| 687 | unsigned int uc = 0;
|
---|
| 688 | unsigned char len = 0;
|
---|
| 689 |
|
---|
| 690 | len = 0;
|
---|
| 691 | if ((src[0] & 0x80) == 0) { uc = src[0] & 0x7F; len = 0; }
|
---|
| 692 | else if ((src[0] & 0xE0) == 0xC0) { uc = src[0] & 0x1F; len = 1; }
|
---|
| 693 | else if ((src[0] & 0xF0) == 0xE0) { uc = src[0] & 0x0F; len = 2; }
|
---|
| 694 | else if ((src[0] & 0xF8) == 0xF0) { uc = src[0] & 0x07; len = 3; }
|
---|
| 695 | else if ((src[0] & 0xFC) == 0xF8) { uc = src[0] & 0x03; len = 4; }
|
---|
| 696 | else if ((src[0] & 0xFE) == 0xFC) { uc = src[0] & 0x01; len = 5; }
|
---|
| 697 |
|
---|
| 698 | i = 1;
|
---|
| 699 | while ((i <= len) && ((src[i] & 0xC0) == 0x80)) {
|
---|
| 700 | uc = (uc << 6) | (src[i] & 0x3F);
|
---|
| 701 | i++;
|
---|
| 702 | }
|
---|
| 703 |
|
---|
| 704 | //Áï¶Ýè
|
---|
| 705 | *code_size = i;
|
---|
| 706 |
|
---|
| 707 | //»óA2oCgÀè
|
---|
| 708 | return uc;
|
---|
| 709 | }
|
---|
| 710 |
|
---|
| 711 | int bs_char_count(char *str, int pos)
|
---|
| 712 | {
|
---|
| 713 | int num = 1, local_pos = pos;
|
---|
| 714 | char *c;
|
---|
| 715 |
|
---|
| 716 | while (1) {
|
---|
| 717 | c = str + local_pos;
|
---|
| 718 |
|
---|
| 719 | if ((*c & 0x80) != 0x80)
|
---|
| 720 | return num;
|
---|
| 721 |
|
---|
| 722 | if (((*c & 0xE0) == 0xC0) && (num == 2)) {
|
---|
| 723 | return num;
|
---|
| 724 | }
|
---|
| 725 | else if (((*c & 0xF0) == 0xE0) && (num == 3)) {
|
---|
| 726 | return num;
|
---|
| 727 | }
|
---|
| 728 | else if (((*c & 0xF8) == 0xF0) && (num == 4)) {
|
---|
| 729 | return num;
|
---|
| 730 | }
|
---|
| 731 | else if (((*c & 0xFC) == 0xF8) && (num == 5)) {
|
---|
| 732 | return num;
|
---|
| 733 | }
|
---|
| 734 | else if (((*c & 0xFE) == 0xFC) && (num == 6)) {
|
---|
| 735 | return num;
|
---|
| 736 | }
|
---|
| 737 | else {
|
---|
| 738 | if (local_pos > 0) {
|
---|
| 739 | local_pos--;
|
---|
| 740 | num++;
|
---|
| 741 | }
|
---|
| 742 | else
|
---|
| 743 | return 0;
|
---|
| 744 | }
|
---|
| 745 | }
|
---|
| 746 |
|
---|
| 747 | return 0;
|
---|
| 748 | }
|
---|