Ignore:
Timestamp:
May 22, 2019, 4:09:18 PM (5 years ago)
Author:
coas-nagasima
Message:

ファイルディスクリプタ処理を更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_rx/trunk/ntshell/ntshell/util/ntstdio.c

    r337 r387  
    224224        handle->xi = xi;
    225225        handle->xo = xo;
    226         handle->outptr = 0;
    227         handle->len = 0;
    228226        handle->pos = 0;
    229227        handle->option = option;
     
    232230static void _putc(ntstdio_t *handle, char c)
    233231{
    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 
    242232        if (handle->xo) {
    243233                handle->xo(handle, (unsigned char)c);
     
    291281}
    292282
     283struct put_buf_t {
     284        char *outptr;
     285        int len;
     286};
     287
     288static 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
    293297int ntstdio_snprintf(char *buf, int len, const char *fmt, ...)
    294298{
    295299        int result;
    296300        ntstdio_t handle;
     301        struct put_buf_t exinf;
    297302        va_list arp;
    298303        /* Switch destination for memory */
     304        handle.xo = put_buf;
    299305        handle.option = 0;
    300         handle.outptr = buf;
    301         handle.len = len;
    302306        handle.pos = 0;
     307        handle.exinf = &exinf;
     308        exinf.outptr = buf;
     309        exinf.len = len;
     310
    303311        va_start(arp, fmt);
    304312        result = xvprintf(&handle, fmt, arp);
     
    306314
    307315        /* Terminate output string with a \0 */
    308         handle.outptr[handle.pos] = '\0';
     316        buf[handle.pos] = '\0';
    309317        return result;
    310318}
Note: See TracChangeset for help on using the changeset viewer.