source: mainline/uspace/lib/c/generic/io/io.c@ bde5c04

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bde5c04 was 8e3498b, checked in by Jiri Svoboda <jiri@…>, 8 years ago

vfs_read/write() should return error code separately from number of bytes transferred.

  • Property mode set to 100644
File size: 17.6 KB
Line 
1/*
2 * Copyright (c) 2005 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/** @file
33 */
34
35#include <stdio.h>
36#include <assert.h>
37#include <str.h>
38#include <errno.h>
39#include <stdbool.h>
40#include <stdlib.h>
41#include <async.h>
42#include <io/kio.h>
43#include <vfs/vfs.h>
44#include <vfs/vfs_sess.h>
45#include <vfs/inbox.h>
46#include <ipc/loc.h>
47#include <adt/list.h>
48#include "../private/io.h"
49#include "../private/stdio.h"
50
51static void _ffillbuf(FILE *stream);
52static void _fflushbuf(FILE *stream);
53
54static FILE stdin_null = {
55 .fd = -1,
56 .pos = 0,
57 .error = true,
58 .eof = true,
59 .kio = false,
60 .sess = NULL,
61 .btype = _IONBF,
62 .buf = NULL,
63 .buf_size = 0,
64 .buf_head = NULL,
65 .buf_tail = NULL,
66 .buf_state = _bs_empty
67};
68
69static FILE stdout_kio = {
70 .fd = -1,
71 .pos = 0,
72 .error = false,
73 .eof = false,
74 .kio = true,
75 .sess = NULL,
76 .btype = _IOLBF,
77 .buf = NULL,
78 .buf_size = BUFSIZ,
79 .buf_head = NULL,
80 .buf_tail = NULL,
81 .buf_state = _bs_empty
82};
83
84static FILE stderr_kio = {
85 .fd = -1,
86 .pos = 0,
87 .error = false,
88 .eof = false,
89 .kio = true,
90 .sess = NULL,
91 .btype = _IONBF,
92 .buf = NULL,
93 .buf_size = 0,
94 .buf_head = NULL,
95 .buf_tail = NULL,
96 .buf_state = _bs_empty
97};
98
99FILE *stdin = NULL;
100FILE *stdout = NULL;
101FILE *stderr = NULL;
102
103static LIST_INITIALIZE(files);
104
105void __stdio_init(void)
106{
107 /* The first three standard file descriptors are assigned for compatibility.
108 * This will probably be removed later.
109 */
110
111 int infd = inbox_get("stdin");
112 if (infd >= 0) {
113 int stdinfd = vfs_clone(infd, -1, false);
114 assert(stdinfd == 0);
115 vfs_open(stdinfd, MODE_READ);
116 stdin = fdopen(stdinfd, "r");
117 } else {
118 stdin = &stdin_null;
119 list_append(&stdin->link, &files);
120 }
121
122 int outfd = inbox_get("stdout");
123 if (outfd >= 0) {
124 int stdoutfd = vfs_clone(outfd, -1, false);
125 assert(stdoutfd <= 1);
126 while (stdoutfd < 1)
127 stdoutfd = vfs_clone(outfd, -1, false);
128 vfs_open(stdoutfd, MODE_APPEND);
129 stdout = fdopen(stdoutfd, "a");
130 } else {
131 stdout = &stdout_kio;
132 list_append(&stdout->link, &files);
133 }
134
135 int errfd = inbox_get("stderr");
136 if (errfd >= 0) {
137 int stderrfd = vfs_clone(errfd, -1, false);
138 assert(stderrfd <= 2);
139 while (stderrfd < 2)
140 stderrfd = vfs_clone(errfd, -1, false);
141 vfs_open(stderrfd, MODE_APPEND);
142 stderr = fdopen(stderrfd, "a");
143 } else {
144 stderr = &stderr_kio;
145 list_append(&stderr->link, &files);
146 }
147}
148
149void __stdio_done(void)
150{
151 while (!list_empty(&files)) {
152 FILE *file = list_get_instance(list_first(&files), FILE, link);
153 fclose(file);
154 }
155}
156
157static bool parse_mode(const char *fmode, int *mode, bool *create, bool *truncate)
158{
159 /* Parse mode except first character. */
160 const char *mp = fmode;
161 if (*mp++ == 0) {
162 errno = EINVAL;
163 return false;
164 }
165
166 if ((*mp == 'b') || (*mp == 't'))
167 mp++;
168
169 bool plus;
170 if (*mp == '+') {
171 mp++;
172 plus = true;
173 } else
174 plus = false;
175
176 if (*mp != 0) {
177 errno = EINVAL;
178 return false;
179 }
180
181 *create = false;
182 *truncate = false;
183
184 /* Parse first character of fmode and determine mode for vfs_open(). */
185 switch (fmode[0]) {
186 case 'r':
187 *mode = plus ? MODE_READ | MODE_WRITE : MODE_READ;
188 break;
189 case 'w':
190 *mode = plus ? MODE_READ | MODE_WRITE : MODE_WRITE;
191 *create = true;
192 if (!plus)
193 *truncate = true;
194 break;
195 case 'a':
196 /* TODO: a+ must read from beginning, append to the end. */
197 if (plus) {
198 errno = ENOTSUP;
199 return false;
200 }
201
202 *mode = MODE_APPEND | (plus ? MODE_READ | MODE_WRITE : MODE_WRITE);
203 *create = true;
204 break;
205 default:
206 errno = EINVAL;
207 return false;
208 }
209
210 return true;
211}
212
213/** Set stream buffer. */
214void setvbuf(FILE *stream, void *buf, int mode, size_t size)
215{
216 stream->btype = mode;
217 stream->buf = buf;
218 stream->buf_size = size;
219 stream->buf_head = stream->buf;
220 stream->buf_tail = stream->buf;
221 stream->buf_state = _bs_empty;
222}
223
224/** Set stream buffer.
225 *
226 * When @p buf is NULL, the stream is set as unbuffered, otherwise
227 * full buffering is enabled.
228 */
229void setbuf(FILE *stream, void *buf)
230{
231 if (buf == NULL) {
232 setvbuf(stream, NULL, _IONBF, BUFSIZ);
233 } else {
234 setvbuf(stream, buf, _IOFBF, BUFSIZ);
235 }
236}
237
238static void _setvbuf(FILE *stream)
239{
240 /* FIXME: Use more complex rules for setting buffering options. */
241
242 switch (stream->fd) {
243 case 1:
244 setvbuf(stream, NULL, _IOLBF, BUFSIZ);
245 break;
246 case 0:
247 case 2:
248 setvbuf(stream, NULL, _IONBF, 0);
249 break;
250 default:
251 setvbuf(stream, NULL, _IOFBF, BUFSIZ);
252 }
253}
254
255/** Allocate stream buffer. */
256static int _fallocbuf(FILE *stream)
257{
258 assert(stream->buf == NULL);
259
260 stream->buf = malloc(stream->buf_size);
261 if (stream->buf == NULL) {
262 errno = ENOMEM;
263 return EOF;
264 }
265
266 stream->buf_head = stream->buf;
267 stream->buf_tail = stream->buf;
268 return 0;
269}
270
271/** Open a stream.
272 *
273 * @param path Path of the file to open.
274 * @param mode Mode string, (r|w|a)[b|t][+].
275 *
276 */
277FILE *fopen(const char *path, const char *fmode)
278{
279 int mode;
280 bool create;
281 bool truncate;
282
283 if (!parse_mode(fmode, &mode, &create, &truncate))
284 return NULL;
285
286 /* Open file. */
287 FILE *stream = malloc(sizeof(FILE));
288 if (stream == NULL) {
289 errno = ENOMEM;
290 return NULL;
291 }
292
293 int flags = WALK_REGULAR;
294 if (create)
295 flags |= WALK_MAY_CREATE;
296 int file = vfs_lookup(path, flags);
297 if (file < 0) {
298 errno = file;
299 free(stream);
300 return NULL;
301 }
302
303 int rc = vfs_open(file, mode);
304 if (rc != EOK) {
305 errno = rc;
306 vfs_put(file);
307 free(stream);
308 return NULL;
309 }
310
311 if (truncate) {
312 rc = vfs_resize(file, 0);
313 if (rc != EOK) {
314 errno = rc;
315 vfs_put(file);
316 free(stream);
317 return NULL;
318 }
319 }
320
321 stream->fd = file;
322 stream->pos = 0;
323 stream->error = false;
324 stream->eof = false;
325 stream->kio = false;
326 stream->sess = NULL;
327 stream->need_sync = false;
328 _setvbuf(stream);
329 stream->ungetc_chars = 0;
330
331 list_append(&stream->link, &files);
332
333 return stream;
334}
335
336FILE *fdopen(int fd, const char *mode)
337{
338 /* Open file. */
339 FILE *stream = malloc(sizeof(FILE));
340 if (stream == NULL) {
341 errno = ENOMEM;
342 return NULL;
343 }
344
345 stream->fd = fd;
346 stream->pos = 0;
347 stream->error = false;
348 stream->eof = false;
349 stream->kio = false;
350 stream->sess = NULL;
351 stream->need_sync = false;
352 _setvbuf(stream);
353 stream->ungetc_chars = 0;
354
355 list_append(&stream->link, &files);
356
357 return stream;
358}
359
360
361static int _fclose_nofree(FILE *stream)
362{
363 int rc = 0;
364
365 fflush(stream);
366
367 if (stream->sess != NULL)
368 async_hangup(stream->sess);
369
370 if (stream->fd >= 0)
371 rc = vfs_put(stream->fd);
372
373 list_remove(&stream->link);
374
375 if (rc != 0) {
376 /* errno was set by close() */
377 return EOF;
378 }
379
380 return 0;
381}
382
383int fclose(FILE *stream)
384{
385 int rc = _fclose_nofree(stream);
386
387 if ((stream != &stdin_null)
388 && (stream != &stdout_kio)
389 && (stream != &stderr_kio))
390 free(stream);
391
392 return rc;
393}
394
395FILE *freopen(const char *path, const char *mode, FILE *stream)
396{
397 FILE *nstr;
398
399 if (path == NULL) {
400 /* Changing mode is not supported */
401 return NULL;
402 }
403
404 (void) _fclose_nofree(stream);
405 nstr = fopen(path, mode);
406 if (nstr == NULL) {
407 free(stream);
408 return NULL;
409 }
410
411 list_remove(&nstr->link);
412 *stream = *nstr;
413 list_append(&stream->link, &files);
414
415 free(nstr);
416
417 return stream;
418}
419
420/** Read from a stream (unbuffered).
421 *
422 * @param buf Destination buffer.
423 * @param size Size of each record.
424 * @param nmemb Number of records to read.
425 * @param stream Pointer to the stream.
426 *
427 * @return Number of elements successfully read. On error this is less than
428 * nmemb, stream error indicator is set and errno is set.
429 */
430static size_t _fread(void *buf, size_t size, size_t nmemb, FILE *stream)
431{
432 int rc;
433 size_t nread;
434
435 if (size == 0 || nmemb == 0)
436 return 0;
437
438 rc = vfs_read(stream->fd, &stream->pos, buf, size * nmemb, &nread);
439 if (rc != EOK) {
440 errno = rc;
441 stream->error = true;
442 } else if (nread == 0) {
443 stream->eof = true;
444 }
445
446 return (nread / size);
447}
448
449/** Write to a stream (unbuffered).
450 *
451 * @param buf Source buffer.
452 * @param size Size of each record.
453 * @param nmemb Number of records to write.
454 * @param stream Pointer to the stream.
455 *
456 * @return Number of elements successfully written. On error this is less than
457 * nmemb, stream error indicator is set and errno is set.
458 */
459static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
460{
461 int rc;
462 size_t nwritten;
463
464 if (size == 0 || nmemb == 0)
465 return 0;
466
467 if (stream->kio) {
468 rc = kio_write(buf, size * nmemb, &nwritten);
469 if (rc != EOK) {
470 stream->error = true;
471 nwritten = 0;
472 }
473 } else {
474 rc = vfs_write(stream->fd, &stream->pos, buf, size * nmemb,
475 &nwritten);
476 if (rc != EOK) {
477 errno = rc;
478 stream->error = true;
479 }
480 }
481
482 if (nwritten > 0)
483 stream->need_sync = true;
484
485 return (nwritten / size);
486}
487
488/** Read some data in stream buffer.
489 *
490 * On error, stream error indicator is set and errno is set.
491 */
492static void _ffillbuf(FILE *stream)
493{
494 int rc;
495 size_t nread;
496
497 stream->buf_head = stream->buf_tail = stream->buf;
498
499 rc = vfs_read(stream->fd, &stream->pos, stream->buf, stream->buf_size,
500 &nread);
501 if (rc != EOK) {
502 errno = rc;
503 stream->error = true;
504 return;
505 }
506
507 if (nread == 0) {
508 stream->eof = true;
509 return;
510 }
511
512 stream->buf_head += nread;
513 stream->buf_state = _bs_read;
514}
515
516/** Write out stream buffer, do not sync stream. */
517static void _fflushbuf(FILE *stream)
518{
519 size_t bytes_used;
520
521 if ((!stream->buf) || (stream->btype == _IONBF) || (stream->error))
522 return;
523
524 bytes_used = stream->buf_head - stream->buf_tail;
525
526 /* If buffer has prefetched read data, we need to seek back. */
527 if (bytes_used > 0 && stream->buf_state == _bs_read)
528 stream->pos -= bytes_used;
529
530 /* If buffer has unwritten data, we need to write them out. */
531 if (bytes_used > 0 && stream->buf_state == _bs_write) {
532 (void) _fwrite(stream->buf_tail, 1, bytes_used, stream);
533 /* On error stream error indicator and errno are set by _fwrite */
534 if (stream->error)
535 return;
536 }
537
538 stream->buf_head = stream->buf;
539 stream->buf_tail = stream->buf;
540 stream->buf_state = _bs_empty;
541}
542
543/** Read from a stream.
544 *
545 * @param dest Destination buffer.
546 * @param size Size of each record.
547 * @param nmemb Number of records to read.
548 * @param stream Pointer to the stream.
549 *
550 */
551size_t fread(void *dest, size_t size, size_t nmemb, FILE *stream)
552{
553 uint8_t *dp;
554 size_t bytes_left;
555 size_t now;
556 size_t data_avail;
557 size_t total_read;
558 size_t i;
559
560 if (size == 0 || nmemb == 0)
561 return 0;
562
563 bytes_left = size * nmemb;
564 total_read = 0;
565 dp = (uint8_t *) dest;
566
567 /* Bytes from ungetc() buffer */
568 while (stream->ungetc_chars > 0 && bytes_left > 0) {
569 *dp++ = stream->ungetc_buf[--stream->ungetc_chars];
570 ++total_read;
571 --bytes_left;
572 }
573
574 /* If not buffered stream, read in directly. */
575 if (stream->btype == _IONBF) {
576 total_read += _fread(dest, 1, bytes_left, stream);
577 return total_read / size;
578 }
579
580 /* Make sure no data is pending write. */
581 if (stream->buf_state == _bs_write)
582 _fflushbuf(stream);
583
584 /* Perform lazy allocation of stream buffer. */
585 if (stream->buf == NULL) {
586 if (_fallocbuf(stream) != 0)
587 return 0; /* Errno set by _fallocbuf(). */
588 }
589
590 while ((!stream->error) && (!stream->eof) && (bytes_left > 0)) {
591 if (stream->buf_head == stream->buf_tail)
592 _ffillbuf(stream);
593
594 if (stream->error || stream->eof) {
595 /* On error errno was set by _ffillbuf() */
596 break;
597 }
598
599 data_avail = stream->buf_head - stream->buf_tail;
600
601 if (bytes_left > data_avail)
602 now = data_avail;
603 else
604 now = bytes_left;
605
606 for (i = 0; i < now; i++) {
607 dp[i] = stream->buf_tail[i];
608 }
609
610 dp += now;
611 stream->buf_tail += now;
612 bytes_left -= now;
613 total_read += now;
614 }
615
616 return (total_read / size);
617}
618
619
620/** Write to a stream.
621 *
622 * @param buf Source buffer.
623 * @param size Size of each record.
624 * @param nmemb Number of records to write.
625 * @param stream Pointer to the stream.
626 *
627 */
628size_t fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
629{
630 uint8_t *data;
631 size_t bytes_left;
632 size_t now;
633 size_t buf_free;
634 size_t total_written;
635 size_t i;
636 uint8_t b;
637 bool need_flush;
638
639 if (size == 0 || nmemb == 0)
640 return 0;
641
642 /* If not buffered stream, write out directly. */
643 if (stream->btype == _IONBF) {
644 now = _fwrite(buf, size, nmemb, stream);
645 fflush(stream);
646 return now;
647 }
648
649 /* Make sure buffer contains no prefetched data. */
650 if (stream->buf_state == _bs_read)
651 _fflushbuf(stream);
652
653 /* Perform lazy allocation of stream buffer. */
654 if (stream->buf == NULL) {
655 if (_fallocbuf(stream) != 0)
656 return 0; /* Errno set by _fallocbuf(). */
657 }
658
659 data = (uint8_t *) buf;
660 bytes_left = size * nmemb;
661 total_written = 0;
662 need_flush = false;
663
664 while ((!stream->error) && (bytes_left > 0)) {
665 buf_free = stream->buf_size - (stream->buf_head - stream->buf);
666 if (bytes_left > buf_free)
667 now = buf_free;
668 else
669 now = bytes_left;
670
671 for (i = 0; i < now; i++) {
672 b = data[i];
673 stream->buf_head[i] = b;
674
675 if ((b == '\n') && (stream->btype == _IOLBF))
676 need_flush = true;
677 }
678
679 data += now;
680 stream->buf_head += now;
681 buf_free -= now;
682 bytes_left -= now;
683 total_written += now;
684 stream->buf_state = _bs_write;
685
686 if (buf_free == 0) {
687 /* Only need to drain buffer. */
688 _fflushbuf(stream);
689 if (!stream->error)
690 need_flush = false;
691 }
692 }
693
694 if (need_flush)
695 fflush(stream);
696
697 return (total_written / size);
698}
699
700int fputc(wchar_t c, FILE *stream)
701{
702 char buf[STR_BOUNDS(1)];
703 size_t sz = 0;
704
705 if (chr_encode(c, buf, &sz, STR_BOUNDS(1)) == EOK) {
706 size_t wr = fwrite(buf, 1, sz, stream);
707
708 if (wr < sz)
709 return EOF;
710
711 return (int) c;
712 }
713
714 return EOF;
715}
716
717int putchar(wchar_t c)
718{
719 return fputc(c, stdout);
720}
721
722int fputs(const char *str, FILE *stream)
723{
724 (void) fwrite(str, str_size(str), 1, stream);
725 if (ferror(stream))
726 return EOF;
727 return 0;
728}
729
730int puts(const char *str)
731{
732 return fputs(str, stdout);
733}
734
735int fgetc(FILE *stream)
736{
737 char c;
738
739 /* This could be made faster by only flushing when needed. */
740 if (stdout)
741 fflush(stdout);
742 if (stderr)
743 fflush(stderr);
744
745 if (fread(&c, sizeof(char), 1, stream) < sizeof(char))
746 return EOF;
747
748 return (int) c;
749}
750
751char *fgets(char *str, int size, FILE *stream)
752{
753 int c;
754 int idx;
755
756 idx = 0;
757 while (idx < size - 1) {
758 c = fgetc(stream);
759 if (c == EOF)
760 break;
761
762 str[idx++] = c;
763
764 if (c == '\n')
765 break;
766 }
767
768 if (ferror(stream))
769 return NULL;
770
771 if (idx == 0)
772 return NULL;
773
774 str[idx] = '\0';
775 return str;
776}
777
778int getchar(void)
779{
780 return fgetc(stdin);
781}
782
783int ungetc(int c, FILE *stream)
784{
785 if (c == EOF)
786 return EOF;
787
788 if (stream->ungetc_chars >= UNGETC_MAX)
789 return EOF;
790
791 stream->ungetc_buf[stream->ungetc_chars++] =
792 (uint8_t)c;
793
794 stream->eof = false;
795 return (uint8_t)c;
796}
797
798int fseek(FILE *stream, long offset, int whence)
799{
800 int rc;
801
802 if (stream->error)
803 return -1;
804
805 _fflushbuf(stream);
806 if (stream->error) {
807 /* errno was set by _fflushbuf() */
808 return -1;
809 }
810
811 stream->ungetc_chars = 0;
812
813 struct stat st;
814 switch (whence) {
815 case SEEK_SET:
816 stream->pos = offset;
817 break;
818 case SEEK_CUR:
819 stream->pos += offset;
820 break;
821 case SEEK_END:
822 rc = vfs_stat(stream->fd, &st);
823 if (rc != EOK) {
824 errno = rc;
825 stream->error = true;
826 return -1;
827 }
828 stream->pos = st.size + offset;
829 break;
830 }
831
832 stream->eof = false;
833 return 0;
834}
835
836long ftell(FILE *stream)
837{
838 /* The native position is too large for the C99-ish interface. */
839 if (stream->pos - stream->ungetc_chars > LONG_MAX)
840 return EOF;
841
842 if (stream->error)
843 return EOF;
844
845 _fflushbuf(stream);
846 if (stream->error) {
847 /* errno was set by _fflushbuf() */
848 return EOF;
849 }
850
851 return stream->pos - stream->ungetc_chars;
852}
853
854void rewind(FILE *stream)
855{
856 (void) fseek(stream, 0, SEEK_SET);
857}
858
859int fflush(FILE *stream)
860{
861 if (stream->error)
862 return EOF;
863
864 _fflushbuf(stream);
865 if (stream->error) {
866 /* errno was set by _fflushbuf() */
867 return EOF;
868 }
869
870 if (stream->kio) {
871 kio_update();
872 return 0;
873 }
874
875 if ((stream->fd >= 0) && (stream->need_sync)) {
876 int rc;
877
878 /**
879 * Better than syncing always, but probably still not the
880 * right thing to do.
881 */
882 stream->need_sync = false;
883 rc = vfs_sync(stream->fd);
884 if (rc != EOK) {
885 errno = rc;
886 return EOF;
887 }
888
889 return 0;
890 }
891
892 return 0;
893}
894
895int feof(FILE *stream)
896{
897 return stream->eof;
898}
899
900int ferror(FILE *stream)
901{
902 return stream->error;
903}
904
905void clearerr(FILE *stream)
906{
907 stream->eof = false;
908 stream->error = false;
909}
910
911int fileno(FILE *stream)
912{
913 if (stream->kio) {
914 errno = EBADF;
915 return EOF;
916 }
917
918 return stream->fd;
919}
920
921async_sess_t *vfs_fsession(FILE *stream, iface_t iface)
922{
923 if (stream->fd >= 0) {
924 if (stream->sess == NULL)
925 stream->sess = vfs_fd_session(stream->fd, iface);
926
927 return stream->sess;
928 }
929
930 return NULL;
931}
932
933int vfs_fhandle(FILE *stream, int *handle)
934{
935 if (stream->fd >= 0) {
936 *handle = stream->fd;
937 return EOK;
938 }
939
940 return ENOENT;
941}
942
943/** @}
944 */
Note: See TracBrowser for help on using the repository browser.