Changeset 433 for EcnlProtoTool/trunk/ntshell/ntshell
- Timestamp:
- Jul 5, 2020, 9:26:49 PM (4 years ago)
- Location:
- EcnlProtoTool/trunk/ntshell/ntshell
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.c
r424 r433 789 789 } 790 790 791 int usrcmd_date(int argc, char **argv) 792 { 793 int ret; 794 struct timespec tp; 795 char buf[30]; 796 797 ret = shell_clock_gettime(CLOCK_REALTIME, &tp); 798 if (ret != 0) { 799 ntstdio_printf(&ntstdio, "clock_gettime error %d", ret); 800 return 0; 801 } 802 803 memset(buf, 0, sizeof(buf)); 804 if (ctime_r(&tp.tv_sec, buf) == NULL) { 805 ntstdio_printf(&ntstdio, "ctime_r error"); 806 return 0; 807 } 808 809 /* 改行コードの削除 */ 810 ret = ntlibc_strlen(buf); 811 buf[ret - 1] = '\0'; 812 813 ntstdio_printf(&ntstdio, "%s .%09ld\n", buf, tp.tv_nsec); 814 return 0; 815 } 816 791 817 int usrcmd_info(int argc, char **argv) 792 818 { -
EcnlProtoTool/trunk/ntshell/ntshell/usrcmd.h
r331 r433 50 50 int usrcmd_mkdir(int argc, char **argv); 51 51 int usrcmd_hexdump(int argc, char **argv); 52 int usrcmd_date(int argc, char **argv); 52 53 53 54 int usrcmd_help(int argc, char **argv); -
EcnlProtoTool/trunk/ntshell/ntshell/util/ntstdio.c
r331 r433 186 186 */ 187 187 value = (flag & FLAG_SIZE_LONG_INT) ? va_arg(arp, long) 188 : (flag & FLAG_SIZE_HALF_INT) ? ((d == 'D') ? (long) va_arg(arp, short) : (long)va_arg(arp, unsigned short))188 : (flag & FLAG_SIZE_HALF_INT) ? ((d == 'D') ? (long)((short)va_arg(arp, int)) : (long)((unsigned short)va_arg(arp, unsigned int))) 189 189 : ((d == 'D') ? (long)va_arg(arp, int) : (long)va_arg(arp, unsigned int)); 190 190 if ((d == 'D') && (value & 0x80000000)) { … … 224 224 handle->xi = xi; 225 225 handle->xo = xo; 226 handle->outptr = 0;227 handle->len = 0;228 226 handle->pos = 0; 229 227 handle->option = option; … … 232 230 static void _putc(ntstdio_t *handle, char c) 233 231 { 234 if (handle->outptr) {235 if ((handle->pos + 1) >= handle->len)236 return;237 handle->outptr[handle->pos] = (unsigned char)c;238 handle->pos++;239 return;240 }241 242 232 if (handle->xo) { 243 233 handle->xo(handle, (unsigned char)c); … … 291 281 } 292 282 283 struct put_buf_t { 284 char *outptr; 285 int len; 286 }; 287 288 static void put_buf(struct ntstdio_t *handle, unsigned char c) 289 { 290 struct put_buf_t *put_buf = (struct put_buf_t *)handle->exinf; 291 if ((handle->pos + 1) >= put_buf->len) 292 return; 293 put_buf->outptr[handle->pos] = (char)c; 294 handle->pos++; 295 } 296 293 297 int ntstdio_snprintf(char *buf, int len, const char *fmt, ...) 294 298 { 295 299 int result; 296 300 ntstdio_t handle; 301 struct put_buf_t exinf; 297 302 va_list arp; 298 303 /* Switch destination for memory */ 304 handle.xo = put_buf; 299 305 handle.option = 0; 300 handle.outptr = buf;301 handle.len = len;302 306 handle.pos = 0; 307 handle.exinf = &exinf; 308 exinf.outptr = buf; 309 exinf.len = len; 310 303 311 va_start(arp, fmt); 304 312 result = xvprintf(&handle, fmt, arp); … … 306 314 307 315 /* Terminate output string with a \0 */ 308 handle.outptr[handle.pos] = '\0';316 buf[handle.pos] = '\0'; 309 317 return result; 310 318 } -
EcnlProtoTool/trunk/ntshell/ntshell/util/ntstdio.h
r331 r433 67 67 #define NTSTDIO_OPTION_LF_CR (1 << 3) 68 68 69 struct ntstdio_t; 69 70 typedef unsigned char (*NTSTDIO_XI)(struct ntstdio_t *handle); 70 71 typedef void (*NTSTDIO_XO)(struct ntstdio_t *handle, unsigned char c); … … 73 74 NTSTDIO_XI xi; 74 75 NTSTDIO_XO xo; 75 char *outptr;76 int len;77 76 int pos; 78 77 unsigned int option; 78 void *exinf; 79 79 } ntstdio_t; 80 80
Note:
See TracChangeset
for help on using the changeset viewer.