source: mainline/uspace/lib/c/generic/private/stdio.h@ 52acfab

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 52acfab was bc56f30, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 6 years ago

Make some libc and libposix headers usable in C++

These headers either get included from standard C++ headers,
or are standard themselves, which means any unnamespaced nonstandard
identifiers are a problem. This commit attempts to fix those
issues, and removes hacks previously used in libcpp to work around it.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 * Copyright (c) 2011 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#ifndef _LIBC_PRIVATE_STDIO_H_
36#define _LIBC_PRIVATE_STDIO_H_
37
38#include <adt/list.h>
39#include <stdio.h>
40#include <async.h>
41#include <stddef.h>
42#include <offset.h>
43
44/** Maximum characters that can be pushed back by ungetc() */
45#define UNGETC_MAX 1
46
47/** Stream operations */
48typedef struct {
49 /** Read from stream */
50 size_t (*read)(void *buf, size_t size, size_t nmemb, FILE *stream);
51 /** Write to stream */
52 size_t (*write)(const void *buf, size_t size, size_t nmemb,
53 FILE *stream);
54 /** Flush stream */
55 int (*flush)(FILE *stream);
56} __stream_ops_t;
57
58enum __buffer_state {
59 /** Buffer is empty */
60 _bs_empty,
61
62 /** Buffer contains data to be written */
63 _bs_write,
64
65 /** Buffer contains prefetched data for reading */
66 _bs_read
67};
68
69struct _IO_FILE {
70 /** Linked list pointer. */
71 link_t link;
72
73 /** Stream operations */
74 __stream_ops_t *ops;
75
76 /** Underlying file descriptor. */
77 int fd;
78
79 /** Instance argument */
80 void *arg;
81
82 /** File position. */
83 aoff64_t pos;
84
85 /** Error indicator. */
86 int error;
87
88 /** End-of-file indicator. */
89 int eof;
90
91 /** Session to the file provider */
92 async_sess_t *sess;
93
94 /**
95 * Non-zero if the stream needs sync on fflush(). XXX change
96 * console semantics so that sync is not needed.
97 */
98 int need_sync;
99
100 /** Buffering type */
101 enum __buffer_type btype;
102
103 /** Buffer */
104 uint8_t *buf;
105
106 /** Buffer size */
107 size_t buf_size;
108
109 /** Buffer state */
110 enum __buffer_state buf_state;
111
112 /** Buffer I/O pointer */
113 uint8_t *buf_head;
114
115 /** Points to end of occupied space when in read mode. */
116 uint8_t *buf_tail;
117
118 /** Pushed back characters */
119 uint8_t ungetc_buf[UNGETC_MAX];
120
121 /** Number of pushed back characters */
122 int ungetc_chars;
123};
124
125#endif
126
127/** @}
128 */
Note: See TracBrowser for help on using the repository browser.