Changeset a35b458 in mainline for uspace/lib/c/generic/io
- Timestamp:
- 2018-03-02T20:10:49Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- Location:
- uspace/lib/c/generic/io
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/asprintf.c
r3061bc1 ra35b458 58 58 NULL 59 59 }; 60 60 61 61 return printf_core(fmt, &ps, args); 62 62 } … … 68 68 int ret = vprintf_size(fmt, args); 69 69 va_end(args); 70 70 71 71 return ret; 72 72 } … … 88 88 int ret = vprintf_size(fmt, args2); 89 89 va_end(args2); 90 90 91 91 if (ret > 0) { 92 92 *strp = malloc(STR_BOUNDS(ret) + 1); 93 93 if (*strp == NULL) 94 94 return -1; 95 95 96 96 vsnprintf(*strp, STR_BOUNDS(ret) + 1, fmt, args); 97 97 } 98 98 99 99 return ret; 100 100 } … … 115 115 int ret = vasprintf(strp, fmt, args); 116 116 va_end(args); 117 117 118 118 return ret; 119 119 } -
uspace/lib/c/generic/io/chargrid.c
r3061bc1 ra35b458 57 57 sizeof(chargrid_t) + cols * rows * sizeof(charfield_t); 58 58 chargrid_t *scrbuf; 59 59 60 60 if ((flags & CHARGRID_FLAG_SHARED) == CHARGRID_FLAG_SHARED) { 61 61 scrbuf = (chargrid_t *) as_area_create(AS_AREA_ANY, size, … … 69 69 return NULL; 70 70 } 71 71 72 72 scrbuf->size = size; 73 73 scrbuf->flags = flags; … … 75 75 scrbuf->rows = rows; 76 76 scrbuf->cursor_visible = false; 77 77 78 78 scrbuf->attrs.type = CHAR_ATTR_STYLE; 79 79 scrbuf->attrs.val.style = STYLE_NORMAL; 80 80 81 81 scrbuf->top_row = 0; 82 82 chargrid_clear(scrbuf); 83 83 84 84 return scrbuf; 85 85 } … … 107 107 scrbuf->top_row = (scrbuf->top_row + 1) % scrbuf->rows; 108 108 chargrid_clear_row(scrbuf, scrbuf->row); 109 109 110 110 return scrbuf->rows; 111 111 } 112 112 113 113 return 2; 114 114 } … … 122 122 return chargrid_update_rows(scrbuf); 123 123 } 124 124 125 125 return 1; 126 126 } … … 144 144 assert(scrbuf->col < scrbuf->cols); 145 145 assert(scrbuf->row < scrbuf->rows); 146 146 147 147 charfield_t *field = 148 148 chargrid_charfield_at(scrbuf, scrbuf->col, scrbuf->row); 149 149 150 150 field->ch = ch; 151 151 field->attrs = scrbuf->attrs; 152 152 field->flags |= CHAR_FLAG_DIRTY; 153 153 154 154 if (update) { 155 155 scrbuf->col++; 156 156 return chargrid_update_cols(scrbuf); 157 157 } 158 158 159 159 return 1; 160 160 } … … 173 173 assert(scrbuf->col < scrbuf->cols); 174 174 assert(scrbuf->row < scrbuf->rows); 175 175 176 176 scrbuf->col = 0; 177 177 scrbuf->row++; 178 178 179 179 return chargrid_update_rows(scrbuf); 180 180 } … … 194 194 assert(scrbuf->col < scrbuf->cols); 195 195 assert(scrbuf->row < scrbuf->rows); 196 196 197 197 sysarg_t spaces = tab_size - scrbuf->cols % tab_size; 198 198 sysarg_t flush = 1; 199 199 200 200 for (sysarg_t i = 0; i < spaces; i++) 201 201 flush += chargrid_putchar(scrbuf, ' ', true) - 1; 202 202 203 203 return flush; 204 204 } … … 220 220 assert(scrbuf->col < scrbuf->cols); 221 221 assert(scrbuf->row < scrbuf->rows); 222 222 223 223 if ((scrbuf->col == 0) && (scrbuf->row == 0)) 224 224 return 0; 225 225 226 226 if (scrbuf->col == 0) { 227 227 scrbuf->col = scrbuf->cols - 1; 228 228 scrbuf->row--; 229 229 230 230 chargrid_putchar(scrbuf, ' ', false); 231 231 return 2; 232 232 } 233 233 234 234 scrbuf->col--; 235 235 chargrid_putchar(scrbuf, ' ', false); … … 249 249 scrbuf->data[pos].flags = CHAR_FLAG_DIRTY; 250 250 } 251 251 252 252 scrbuf->col = 0; 253 253 scrbuf->row = 0; … … 284 284 assert(col); 285 285 assert(row); 286 286 287 287 *col = scrbuf->col; 288 288 *row = scrbuf->row; … … 305 305 charfield_t *field = 306 306 chargrid_charfield_at(scrbuf, col, row); 307 307 308 308 field->ch = 0; 309 309 field->attrs = scrbuf->attrs; -
uspace/lib/c/generic/io/console.c
r3061bc1 ra35b458 48 48 if (!ctrl) 49 49 return NULL; 50 50 51 51 ctrl->input_sess = vfs_fsession(ifile, INTERFACE_CONSOLE); 52 52 if (!ctrl->input_sess) { … … 54 54 return NULL; 55 55 } 56 56 57 57 ctrl->output_sess = vfs_fsession(ofile, INTERFACE_CONSOLE); 58 58 if (!ctrl->output_sess) { … … 60 60 return NULL; 61 61 } 62 62 63 63 ctrl->input = ifile; 64 64 ctrl->output = ofile; 65 65 ctrl->input_aid = 0; 66 66 67 67 return ctrl; 68 68 } … … 95 95 errno_t rc = async_req_0_2(exch, CONSOLE_GET_SIZE, cols, rows); 96 96 async_exchange_end(exch); 97 97 98 98 return rc; 99 99 } … … 134 134 errno_t rc = async_req_0_1(exch, CONSOLE_GET_COLOR_CAP, ccap); 135 135 async_exchange_end(exch); 136 136 137 137 return rc; 138 138 } … … 143 143 errno_t rc = async_req_0_2(exch, CONSOLE_GET_POS, col, row); 144 144 async_exchange_end(exch); 145 145 146 146 return rc; 147 147 } … … 183 183 if (ctrl->input_aid == 0) { 184 184 ipc_call_t result; 185 185 186 186 async_exch_t *exch = async_exchange_begin(ctrl->input_sess); 187 187 aid_t aid = async_send_0(exch, CONSOLE_GET_EVENT, &result); 188 188 async_exchange_end(exch); 189 189 190 190 errno_t rc; 191 191 async_wait_for(aid, &rc); 192 192 193 193 if (rc != EOK) { 194 194 errno = rc; 195 195 return false; 196 196 } 197 197 198 198 rc = console_ev_decode(&result, event); 199 199 if (rc != EOK) { … … 204 204 errno_t retval; 205 205 async_wait_for(ctrl->input_aid, &retval); 206 206 207 207 ctrl->input_aid = 0; 208 208 209 209 if (retval != EOK) { 210 210 errno = retval; 211 211 return false; 212 212 } 213 213 214 214 errno_t rc = console_ev_decode(&ctrl->input_call, event); 215 215 if (rc != EOK) { … … 218 218 } 219 219 } 220 220 221 221 return true; 222 222 } … … 227 227 struct timeval t0; 228 228 gettimeofday(&t0, NULL); 229 229 230 230 if (ctrl->input_aid == 0) { 231 231 async_exch_t *exch = async_exchange_begin(ctrl->input_sess); … … 234 234 async_exchange_end(exch); 235 235 } 236 236 237 237 errno_t retval; 238 238 errno_t rc = async_wait_timeout(ctrl->input_aid, &retval, *timeout); … … 242 242 return false; 243 243 } 244 244 245 245 ctrl->input_aid = 0; 246 246 247 247 if (retval != EOK) { 248 248 errno = retval; 249 249 return false; 250 250 } 251 251 252 252 rc = console_ev_decode(&ctrl->input_call, event); 253 253 if (rc != EOK) { … … 255 255 return false; 256 256 } 257 257 258 258 /* Update timeout */ 259 259 struct timeval t1; 260 260 gettimeofday(&t1, NULL); 261 261 *timeout -= tv_sub_diff(&t1, &t0); 262 262 263 263 return true; 264 264 } -
uspace/lib/c/generic/io/input.c
r3061bc1 ra35b458 61 61 errno_t rc = async_create_callback_port(exch, INTERFACE_INPUT_CB, 0, 0, 62 62 input_cb_conn, input, &port); 63 63 64 64 async_exchange_end(exch); 65 65 … … 88 88 errno_t rc = async_req_0_0(exch, INPUT_ACTIVATE); 89 89 async_exchange_end(exch); 90 90 91 91 return rc; 92 92 } -
uspace/lib/c/generic/io/io.c
r3061bc1 ra35b458 119 119 list_append(&stdin->link, &files); 120 120 } 121 121 122 122 int outfd = inbox_get("stdout"); 123 123 if (outfd >= 0) { … … 133 133 list_append(&stdout->link, &files); 134 134 } 135 135 136 136 int errfd = inbox_get("stderr"); 137 137 if (errfd >= 0) { … … 165 165 return false; 166 166 } 167 167 168 168 if ((*mp == 'b') || (*mp == 't')) 169 169 mp++; 170 170 171 171 bool plus; 172 172 if (*mp == '+') { … … 175 175 } else 176 176 plus = false; 177 177 178 178 if (*mp != 0) { 179 179 errno = EINVAL; … … 183 183 *create = false; 184 184 *truncate = false; 185 185 186 186 /* Parse first character of fmode and determine mode for vfs_open(). */ 187 187 switch (fmode[0]) { … … 209 209 return false; 210 210 } 211 211 212 212 return true; 213 213 } … … 241 241 { 242 242 /* FIXME: Use more complex rules for setting buffering options. */ 243 243 244 244 switch (stream->fd) { 245 245 case 1: … … 259 259 { 260 260 assert(stream->buf == NULL); 261 261 262 262 stream->buf = malloc(stream->buf_size); 263 263 if (stream->buf == NULL) { … … 265 265 return EOF; 266 266 } 267 267 268 268 stream->buf_head = stream->buf; 269 269 stream->buf_tail = stream->buf; … … 285 285 if (!parse_mode(fmode, &mode, &create, &truncate)) 286 286 return NULL; 287 287 288 288 /* Open file. */ 289 289 FILE *stream = malloc(sizeof(FILE)); … … 311 311 return NULL; 312 312 } 313 313 314 314 if (truncate) { 315 315 rc = vfs_resize(file, 0); … … 331 331 _setvbuf(stream); 332 332 stream->ungetc_chars = 0; 333 333 334 334 list_append(&stream->link, &files); 335 335 336 336 return stream; 337 337 } … … 345 345 return NULL; 346 346 } 347 347 348 348 stream->fd = fd; 349 349 stream->pos = 0; … … 355 355 _setvbuf(stream); 356 356 stream->ungetc_chars = 0; 357 357 358 358 list_append(&stream->link, &files); 359 359 360 360 return stream; 361 361 } … … 365 365 { 366 366 errno_t rc = 0; 367 367 368 368 fflush(stream); 369 369 370 370 if (stream->sess != NULL) 371 371 async_hangup(stream->sess); 372 372 373 373 if (stream->fd >= 0) 374 374 rc = vfs_put(stream->fd); 375 375 376 376 list_remove(&stream->link); 377 377 378 378 if (rc != EOK) { 379 379 errno = rc; 380 380 return EOF; 381 381 } 382 382 383 383 return 0; 384 384 } … … 387 387 { 388 388 int rc = _fclose_nofree(stream); 389 389 390 390 if ((stream != &stdin_null) 391 391 && (stream != &stdout_kio) 392 392 && (stream != &stderr_kio)) 393 393 free(stream); 394 394 395 395 return rc; 396 396 } … … 399 399 { 400 400 FILE *nstr; 401 401 402 402 if (path == NULL) { 403 403 /* Changing mode is not supported */ 404 404 return NULL; 405 405 } 406 406 407 407 (void) _fclose_nofree(stream); 408 408 nstr = fopen(path, mode); … … 411 411 return NULL; 412 412 } 413 413 414 414 list_remove(&nstr->link); 415 415 *stream = *nstr; 416 416 list_append(&stream->link, &files); 417 417 418 418 free(nstr); 419 419 420 420 return stream; 421 421 } … … 659 659 return 0; /* Errno set by _fallocbuf(). */ 660 660 } 661 661 662 662 data = (uint8_t *) buf; 663 663 bytes_left = size * nmemb; 664 664 total_written = 0; 665 665 need_flush = false; 666 666 667 667 while ((!stream->error) && (bytes_left > 0)) { 668 668 buf_free = stream->buf_size - (stream->buf_head - stream->buf); … … 671 671 else 672 672 now = bytes_left; 673 673 674 674 for (i = 0; i < now; i++) { 675 675 b = data[i]; 676 676 stream->buf_head[i] = b; 677 677 678 678 if ((b == '\n') && (stream->btype == _IOLBF)) 679 679 need_flush = true; 680 680 } 681 681 682 682 data += now; 683 683 stream->buf_head += now; … … 686 686 total_written += now; 687 687 stream->buf_state = _bs_write; 688 688 689 689 if (buf_free == 0) { 690 690 /* Only need to drain buffer. */ … … 697 697 if (need_flush) 698 698 fflush(stream); 699 699 700 700 return (total_written / size); 701 701 } … … 705 705 char buf[STR_BOUNDS(1)]; 706 706 size_t sz = 0; 707 707 708 708 if (chr_encode(c, buf, &sz, STR_BOUNDS(1)) == EOK) { 709 709 size_t wr = fwrite(buf, 1, sz, stream); 710 710 711 711 if (wr < sz) 712 712 return EOF; 713 713 714 714 return (int) c; 715 715 } 716 716 717 717 return EOF; 718 718 } … … 739 739 { 740 740 char c; 741 741 742 742 /* This could be made faster by only flushing when needed. */ 743 743 if (stdout) … … 745 745 if (stderr) 746 746 fflush(stderr); 747 747 748 748 if (fread(&c, sizeof(char), 1, stream) < sizeof(char)) 749 749 return EOF; 750 750 751 751 return (int) c; 752 752 } … … 841 841 if (stream->error) 842 842 return EOF; 843 843 844 844 _fflushbuf(stream); 845 845 if (stream->error) { … … 876 876 if (stream->error) 877 877 return EOF; 878 878 879 879 _fflushbuf(stream); 880 880 if (stream->error) { … … 882 882 return EOF; 883 883 } 884 884 885 885 if (stream->kio) { 886 886 kio_update(); 887 887 return 0; 888 888 } 889 889 890 890 if ((stream->fd >= 0) && (stream->need_sync)) { 891 891 errno_t rc; … … 904 904 return 0; 905 905 } 906 906 907 907 return 0; 908 908 } … … 930 930 return EOF; 931 931 } 932 932 933 933 return stream->fd; 934 934 } … … 939 939 if (stream->sess == NULL) 940 940 stream->sess = vfs_fd_session(stream->fd, iface); 941 941 942 942 return stream->sess; 943 943 } 944 944 945 945 return NULL; 946 946 } … … 952 952 return EOK; 953 953 } 954 954 955 955 return ENOENT; 956 956 } -
uspace/lib/c/generic/io/kio.c
r3061bc1 ra35b458 46 46 { 47 47 errno_t rc = (errno_t) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) buf, size); 48 48 49 49 if (rc == EOK) 50 50 *nwritten = size; … … 73 73 va_list args; 74 74 va_start(args, fmt); 75 75 76 76 int ret = kio_vprintf(fmt, args); 77 77 78 78 va_end(args); 79 79 80 80 return ret; 81 81 } … … 84 84 { 85 85 size_t wr; 86 86 87 87 wr = 0; 88 88 (void) kio_write(str, size, &wr); … … 95 95 size_t chars = 0; 96 96 size_t wr; 97 97 98 98 while (offset < size) { 99 99 char buf[STR_BOUNDS(1)]; 100 100 size_t sz = 0; 101 101 102 102 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK) 103 103 kio_write(buf, sz, &wr); 104 104 105 105 chars++; 106 106 offset += sizeof(wchar_t); 107 107 } 108 108 109 109 return chars; 110 110 } … … 125 125 NULL 126 126 }; 127 127 128 128 return printf_core(fmt, &ps, ap); 129 129 } -
uspace/lib/c/generic/io/output.c
r3061bc1 ra35b458 45 45 errno_t ret = async_req_0_0(exch, OUTPUT_YIELD); 46 46 async_exchange_end(exch); 47 47 48 48 return ret; 49 49 } … … 54 54 errno_t ret = async_req_0_0(exch, OUTPUT_CLAIM); 55 55 async_exchange_end(exch); 56 56 57 57 return ret; 58 58 } … … 63 63 errno_t ret = async_req_0_2(exch, OUTPUT_GET_DIMENSIONS, maxx, maxy); 64 64 async_exchange_end(exch); 65 65 66 66 return ret; 67 67 } … … 70 70 { 71 71 async_exch_t *exch = async_exchange_begin(sess); 72 72 73 73 sysarg_t rv; 74 74 errno_t ret = async_req_0_1(exch, OUTPUT_GET_CAPS, &rv); 75 75 76 76 async_exchange_end(exch); 77 77 78 78 if (ret == EOK) 79 79 *ccaps = (console_caps_t) rv; 80 80 81 81 return ret; 82 82 } … … 86 86 { 87 87 async_exch_t *exch = async_exchange_begin(sess); 88 88 89 89 ipc_call_t answer; 90 90 aid_t req = async_send_0(exch, OUTPUT_FRONTBUF_CREATE, &answer); 91 91 errno_t rc = async_share_out_start(exch, frontbuf, AS_AREA_READ 92 92 | AS_AREA_WRITE | AS_AREA_CACHEABLE); 93 93 94 94 async_exchange_end(exch); 95 95 96 96 errno_t ret; 97 97 async_wait_for(req, &ret); 98 98 99 99 if ((rc != EOK) || (ret != EOK)) 100 100 return 0; 101 101 102 102 return (frontbuf_handle_t) IPC_GET_ARG1(answer); 103 103 } … … 108 108 errno_t ret = async_req_1_0(exch, OUTPUT_SET_STYLE, style); 109 109 async_exchange_end(exch); 110 110 111 111 return ret; 112 112 } … … 117 117 errno_t ret = async_req_1_0(exch, OUTPUT_CURSOR_UPDATE, frontbuf); 118 118 async_exchange_end(exch); 119 119 120 120 return ret; 121 121 } … … 126 126 errno_t ret = async_req_1_0(exch, OUTPUT_UPDATE, frontbuf); 127 127 async_exchange_end(exch); 128 128 129 129 return ret; 130 130 } … … 137 137 cols, rows); 138 138 async_exchange_end(exch); 139 139 140 140 return ret; 141 141 } -
uspace/lib/c/generic/io/printf.c
r3061bc1 ra35b458 48 48 va_list args; 49 49 va_start(args, fmt); 50 50 51 51 int ret = vfprintf(stream, fmt, args); 52 52 53 53 va_end(args); 54 54 55 55 return ret; 56 56 } … … 67 67 va_list args; 68 68 va_start(args, fmt); 69 69 70 70 int ret = vprintf(fmt, args); 71 71 72 72 va_end(args); 73 73 74 74 return ret; 75 75 } -
uspace/lib/c/generic/io/printf_core.c
r3061bc1 ra35b458 211 211 if (str == NULL) 212 212 return printf_putnchars(nullstr, str_size(nullstr), ps); 213 213 214 214 return ps->str_write((void *) str, str_size(str), ps->data); 215 215 } … … 227 227 if (!ascii_check(ch)) 228 228 return ps->str_write((void *) &invalch, 1, ps->data); 229 229 230 230 return ps->str_write(&ch, 1, ps->data); 231 231 } … … 243 243 if (!chr_check(ch)) 244 244 return ps->str_write((void *) &invalch, 1, ps->data); 245 245 246 246 return ps->wstr_write(&ch, sizeof(wchar_t), ps->data); 247 247 } … … 269 269 } 270 270 } 271 271 272 272 if (printf_putchar(ch, ps) > 0) 273 273 counter++; 274 274 275 275 while (--width > 0) { 276 276 /* … … 281 281 counter++; 282 282 } 283 283 284 284 return (int) (counter); 285 285 } … … 307 307 } 308 308 } 309 309 310 310 if (printf_putwchar(ch, ps) > 0) 311 311 counter++; 312 312 313 313 while (--width > 0) { 314 314 /* … … 319 319 counter++; 320 320 } 321 321 322 322 return (int) (counter); 323 323 } … … 337 337 if (str == NULL) 338 338 return printf_putstr(nullstr, ps); 339 339 340 340 size_t strw = str_length(str); 341 341 … … 343 343 if ((precision == 0) || (precision > strw)) 344 344 precision = strw; 345 345 346 346 /* Left padding */ 347 347 size_t counter = 0; … … 353 353 } 354 354 } 355 355 356 356 /* Part of @a str fitting into the alloted space. */ 357 357 int retval; … … 386 386 if (str == NULL) 387 387 return printf_putstr(nullstr, ps); 388 388 389 389 size_t strw = wstr_length(str); 390 390 … … 392 392 if ((precision == 0) || (precision > strw)) 393 393 precision = strw; 394 394 395 395 /* Left padding */ 396 396 size_t counter = 0; … … 402 402 } 403 403 } 404 404 405 405 /* Part of @a wstr fitting into the alloted space. */ 406 406 int retval; … … 408 408 if ((retval = printf_wputnchars(str, size, ps)) < 0) 409 409 return -counter; 410 410 411 411 counter += retval; 412 412 413 413 /* Right padding */ 414 414 while (width-- > 0) { … … 440 440 precision = 0; 441 441 } 442 442 443 443 const char *digits; 444 444 if (flags & __PRINTF_FLAG_BIGCHARS) … … 446 446 else 447 447 digits = digits_small; 448 448 449 449 char data[PRINT_NUMBER_BUFFER_SIZE]; 450 450 char *ptr = &data[PRINT_NUMBER_BUFFER_SIZE - 1]; 451 451 452 452 /* Size of number with all prefixes and signs */ 453 453 int size = 0; 454 454 455 455 /* Put zero at end of string */ 456 456 *ptr-- = 0; 457 457 458 458 if (num == 0) { 459 459 *ptr-- = '0'; … … 465 465 } while (num /= base); 466 466 } 467 467 468 468 /* Size of plain number */ 469 469 int number_size = size; 470 470 471 471 /* 472 472 * Collect the sum of all prefixes/signs/etc. to calculate padding and … … 487 487 } 488 488 } 489 489 490 490 char sgn = 0; 491 491 if (flags & __PRINTF_FLAG_SIGNED) { … … 501 501 } 502 502 } 503 503 504 504 if (flags & __PRINTF_FLAG_LEFTALIGNED) 505 505 flags &= ~__PRINTF_FLAG_ZEROPADDED; 506 506 507 507 /* 508 508 * If the number is left-aligned or precision is specified then … … 513 513 precision = width - size + number_size; 514 514 } 515 515 516 516 /* Print leading spaces */ 517 517 if (number_size > precision) { … … 519 519 precision = number_size; 520 520 } 521 521 522 522 width -= precision + size - number_size; 523 523 size_t counter = 0; 524 524 525 525 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { 526 526 while (width-- > 0) { … … 529 529 } 530 530 } 531 531 532 532 /* Print sign */ 533 533 if (sgn) { … … 535 535 counter++; 536 536 } 537 537 538 538 /* Print prefix */ 539 539 if (flags & __PRINTF_FLAG_PREFIX) { … … 568 568 } 569 569 } 570 570 571 571 /* Print leading zeroes */ 572 572 precision -= number_size; … … 575 575 counter++; 576 576 } 577 577 578 578 /* Print the number itself */ 579 579 int retval; 580 580 if ((retval = printf_putstr(++ptr, ps)) > 0) 581 581 counter += retval; 582 582 583 583 /* Print trailing spaces */ 584 584 585 585 while (width-- > 0) { 586 586 if (printf_putchar(' ', ps) == 1) 587 587 counter++; 588 588 } 589 589 590 590 return ((int) counter); 591 591 } … … 601 601 const int str_len = 3; 602 602 const char *str; 603 603 604 604 if (flags & __PRINTF_FLAG_BIGCHARS) { 605 605 str = val.is_infinity ? "INF" : "NAN"; … … 624 624 if ((ret = ps->str_write(&sign, 1, ps->data)) < 0) 625 625 return -1; 626 626 627 627 counter += ret; 628 628 } … … 630 630 if ((ret = ps->str_write(str, str_len, ps->data)) < 0) 631 631 return -1; 632 632 633 633 counter += ret; 634 634 … … 751 751 if ((ret = ps->str_write(&sign, 1, ps->data)) < 0) 752 752 return -1; 753 753 754 754 counter += ret; 755 755 } … … 783 783 784 784 counter += ret; 785 785 786 786 /* Print the decimal point and the fractional part. */ 787 787 if (has_decimal_pt) { … … 790 790 if ((ret = ps->str_write(&ch, 1, ps->data)) < 0) 791 791 return -1; 792 792 793 793 counter += ret; 794 794 … … 885 885 /* Let the implementation figure out the proper precision. */ 886 886 val_str.len = double_to_short_str(val, buf, buf_size, &val_str.dec_exp); 887 887 888 888 /* Precision needed for the last significant digit. */ 889 889 precision = max(0, -val_str.dec_exp); … … 903 903 if ((ret = ps->str_write(&exp_ch, 1, ps->data)) < 0) 904 904 return -1; 905 905 906 906 counter += ret; 907 907 … … 915 915 /* Print the exponent. */ 916 916 exp_val = abs(exp_val); 917 917 918 918 char exp_str[4] = { 0 }; 919 919 … … 921 921 exp_str[1] = '0' + (exp_val % 100) / 10 ; 922 922 exp_str[2] = '0' + (exp_val % 10); 923 923 924 924 int exp_len = (exp_str[0] == '0') ? 2 : 3; 925 925 const char *exp_str_start = &exp_str[3] - exp_len; … … 981 981 if ((ret = ps->str_write(&sign, 1, ps->data)) < 0) 982 982 return -1; 983 983 984 984 counter += ret; 985 985 } … … 1004 1004 if ((ret = ps->str_write(&ch, 1, ps->data)) < 0) 1005 1005 return -1; 1006 1006 1007 1007 counter += ret; 1008 1008 … … 1104 1104 /* Let the implementation figure out the proper precision. */ 1105 1105 val_str.len = double_to_short_str(val, buf, buf_size, &val_str.dec_exp); 1106 1106 1107 1107 /* Use all produced digits. */ 1108 1108 precision = val_str.len - 1; … … 1223 1223 precision = (precision < 0) ? 6 : precision; 1224 1224 return print_double_fixed(g, precision, width, flags, ps); 1225 1225 1226 1226 case 'E': 1227 1227 flags |= __PRINTF_FLAG_BIGCHARS; … … 1230 1230 precision = (precision < 0) ? 6 : precision; 1231 1231 return print_double_scientific(g, precision, width, flags, ps); 1232 1232 1233 1233 case 'G': 1234 1234 flags |= __PRINTF_FLAG_BIGCHARS; … … 1236 1236 case 'g': 1237 1237 return print_double_generic(g, precision, width, flags, ps); 1238 1238 1239 1239 default: 1240 1240 assert(false); … … 1337 1337 size_t nxt = 0; /* Index of the next character from fmt */ 1338 1338 size_t j = 0; /* Index to the first not printed nonformating character */ 1339 1339 1340 1340 size_t counter = 0; /* Number of characters printed */ 1341 1341 int retval; /* Return values from nested functions */ 1342 1342 1343 1343 while (true) { 1344 1344 i = nxt; 1345 1345 wchar_t uc = str_decode(fmt, &nxt, STR_NO_LIMIT); 1346 1346 1347 1347 if (uc == 0) 1348 1348 break; 1349 1349 1350 1350 /* Control character */ 1351 1351 if (uc == '%') { … … 1359 1359 counter += retval; 1360 1360 } 1361 1361 1362 1362 j = i; 1363 1363 1364 1364 /* Parse modifiers */ 1365 1365 uint32_t flags = 0; 1366 1366 bool end = false; 1367 1367 1368 1368 do { 1369 1369 i = nxt; … … 1390 1390 }; 1391 1391 } while (!end); 1392 1392 1393 1393 /* Width & '*' operator */ 1394 1394 int width = 0; … … 1397 1397 width *= 10; 1398 1398 width += uc - '0'; 1399 1399 1400 1400 i = nxt; 1401 1401 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); … … 1416 1416 } 1417 1417 } 1418 1418 1419 1419 /* Precision and '*' operator */ 1420 1420 int precision = -1; … … 1427 1427 precision *= 10; 1428 1428 precision += uc - '0'; 1429 1429 1430 1430 i = nxt; 1431 1431 uc = str_decode(fmt, &nxt, STR_NO_LIMIT); … … 1446 1446 } 1447 1447 } 1448 1448 1449 1449 qualifier_t qualifier; 1450 1450 1451 1451 switch (uc) { 1452 1452 case 't': … … 1495 1495 qualifier = PrintfQualifierInt; 1496 1496 } 1497 1497 1498 1498 unsigned int base = 10; 1499 1499 1500 1500 switch (uc) { 1501 1501 /* … … 1504 1504 case 's': 1505 1505 precision = max(0, precision); 1506 1506 1507 1507 if (qualifier == PrintfQualifierLong) 1508 1508 retval = print_wstr(va_arg(ap, wchar_t *), width, precision, flags, ps); 1509 1509 else 1510 1510 retval = print_str(va_arg(ap, char *), width, precision, flags, ps); 1511 1511 1512 1512 if (retval < 0) { 1513 1513 counter = -counter; 1514 1514 goto out; 1515 1515 } 1516 1516 1517 1517 counter += retval; 1518 1518 j = nxt; … … 1523 1523 else 1524 1524 retval = print_char(va_arg(ap, unsigned int), width, flags, ps); 1525 1525 1526 1526 if (retval < 0) { 1527 1527 counter = -counter; 1528 1528 goto out; 1529 1529 }; 1530 1530 1531 1531 counter += retval; 1532 1532 j = nxt; 1533 1533 goto next_char; 1534 1534 1535 1535 /* 1536 1536 * Floating point values … … 1544 1544 retval = print_double(va_arg(ap, double), uc, precision, 1545 1545 width, flags, ps); 1546 1546 1547 1547 if (retval < 0) { 1548 1548 counter = -counter; 1549 1549 goto out; 1550 1550 } 1551 1551 1552 1552 counter += retval; 1553 1553 j = nxt; 1554 1554 goto next_char; 1555 1555 1556 1556 /* 1557 1557 * Integer values … … 1585 1585 base = 16; 1586 1586 break; 1587 1587 1588 1588 /* Percentile itself */ 1589 1589 case '%': 1590 1590 j = i; 1591 1591 goto next_char; 1592 1592 1593 1593 /* 1594 1594 * Bad formatting. … … 1601 1601 goto next_char; 1602 1602 } 1603 1603 1604 1604 /* Print integers */ 1605 1605 size_t size; 1606 1606 uint64_t number; 1607 1607 1608 1608 switch (qualifier) { 1609 1609 case PrintfQualifierByte: … … 1645 1645 goto out; 1646 1646 } 1647 1647 1648 1648 if ((retval = print_number(number, width, precision, 1649 1649 base, flags, ps)) < 0) { … … 1651 1651 goto out; 1652 1652 } 1653 1653 1654 1654 counter += retval; 1655 1655 j = nxt; … … 1658 1658 ; 1659 1659 } 1660 1660 1661 1661 if (i > j) { 1662 1662 if ((retval = printf_putnchars(&fmt[j], i - j, ps)) < 0) { … … 1667 1667 counter += retval; 1668 1668 } 1669 1669 1670 1670 out: 1671 1671 return ((int) counter); -
uspace/lib/c/generic/io/snprintf.c
r3061bc1 ra35b458 50 50 va_list args; 51 51 va_start(args, fmt); 52 52 53 53 int ret = vsnprintf(str, size, fmt, args); 54 54 55 55 va_end(args); 56 56 57 57 return ret; 58 58 } -
uspace/lib/c/generic/io/vprintf.c
r3061bc1 ra35b458 52 52 size_t offset = 0; 53 53 size_t chars = 0; 54 54 55 55 while (offset < size) { 56 56 if (fputc(str[chars], (FILE *) stream) <= 0) 57 57 break; 58 58 59 59 chars++; 60 60 offset += sizeof(wchar_t); 61 61 } 62 62 63 63 return chars; 64 64 } … … 80 80 stream 81 81 }; 82 82 83 83 /* 84 84 * Prevent other threads to execute printf_core() 85 85 */ 86 86 fibril_mutex_lock(&printf_mutex); 87 87 88 88 int ret = printf_core(fmt, &ps, ap); 89 89 90 90 fibril_mutex_unlock(&printf_mutex); 91 91 92 92 return ret; 93 93 } -
uspace/lib/c/generic/io/vsnprintf.c
r3061bc1 ra35b458 65 65 { 66 66 size_t left = data->size - data->len; 67 67 68 68 if (left == 0) 69 69 return ((int) size); 70 70 71 71 if (left == 1) { 72 72 /* We have only one free byte left in buffer … … 77 77 return ((int) size); 78 78 } 79 79 80 80 if (left <= size) { 81 81 /* We do not have enough space for the whole string … … 84 84 */ 85 85 size_t index = 0; 86 86 87 87 while (index < size) { 88 88 wchar_t uc = str_decode(str, &index, size); 89 89 90 90 if (chr_encode(uc, data->dst, &data->len, data->size - 1) != EOK) 91 91 break; 92 92 } 93 93 94 94 /* Put trailing zero at end, but not count it 95 95 * into data->len so it could be rewritten next time 96 96 */ 97 97 data->dst[data->len] = 0; 98 98 99 99 return ((int) size); 100 100 } 101 101 102 102 /* Buffer is big enough to print the whole string */ 103 103 memcpy((void *)(data->dst + data->len), (void *) str, size); 104 104 data->len += size; 105 105 106 106 /* Put trailing zero at end, but not count it 107 107 * into data->len so it could be rewritten next time 108 108 */ 109 109 data->dst[data->len] = 0; 110 110 111 111 return ((int) size); 112 112 } … … 132 132 { 133 133 size_t index = 0; 134 134 135 135 while (index < (size / sizeof(wchar_t))) { 136 136 size_t left = data->size - data->len; 137 137 138 138 if (left == 0) 139 139 return ((int) size); 140 140 141 141 if (left == 1) { 142 142 /* We have only one free byte left in buffer … … 147 147 return ((int) size); 148 148 } 149 149 150 150 if (chr_encode(str[index], data->dst, &data->len, data->size - 1) != EOK) 151 151 break; 152 152 153 153 index++; 154 154 } 155 155 156 156 /* Put trailing zero at end, but not count it 157 157 * into data->len so it could be rewritten next time 158 158 */ 159 159 data->dst[data->len] = 0; 160 160 161 161 return ((int) size); 162 162 } … … 174 174 &data 175 175 }; 176 176 177 177 /* Print 0 at end of string - fix the case that nothing will be printed */ 178 178 if (size > 0) 179 179 str[0] = 0; 180 180 181 181 /* vsnprintf_write ensures that str will be terminated by zero. */ 182 182 return printf_core(fmt, &ps, ap); -
uspace/lib/c/generic/io/window.c
r3061bc1 ra35b458 46 46 errno_t ret = async_req_1_2(exch, WINDOW_REGISTER, flags, in, out); 47 47 async_exchange_end(exch); 48 48 49 49 return ret; 50 50 } … … 96 96 { 97 97 async_exch_t *exch = async_exchange_begin(sess); 98 98 99 99 ipc_call_t answer; 100 100 aid_t req = async_send_5(exch, WINDOW_RESIZE, x, y, width, height, 101 101 (sysarg_t) placement_flags, &answer); 102 102 103 103 errno_t rc = async_share_out_start(exch, cells, AS_AREA_READ | AS_AREA_CACHEABLE); 104 104 105 105 async_exchange_end(exch); 106 106 107 107 errno_t ret; 108 108 async_wait_for(req, &ret); 109 109 110 110 if (rc != EOK) 111 111 return rc; 112 112 else if (ret != EOK) 113 113 return ret; 114 114 115 115 return EOK; 116 116 }
Note:
See TracChangeset
for help on using the changeset viewer.