source: mainline/uspace/lib/posix/stdio.c@ e64b55a

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e64b55a was 823a929, checked in by Petr Koupy <petr.koupy@…>, 14 years ago

Added function stubs (binutils compile-time dependencies).

  • Property mode set to 100644
File size: 4.3 KB
RevLine 
[09b0b1fb]1/*
2 * Copyright (c) 2011 Jiri Zarevucky
[4f4b4e7]3 * Copyright (c) 2011 Petr Koupy
[09b0b1fb]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30/** @addtogroup libposix
31 * @{
32 */
33/** @file
34 */
35
[491e1ee]36#define LIBPOSIX_INTERNAL
[09b0b1fb]37
[ab547063]38#include <assert.h>
[4f4b4e7]39#include <errno.h>
40
[9b1503e]41#include "internal/common.h"
[09b0b1fb]42#include "stdio.h"
[ab547063]43#include "string.h"
[4f4b4e7]44
[ab547063]45/* not the best of solutions, but freopen will eventually
[4f4b4e7]46 * need to be implemented in libc anyway
47 */
[ab547063]48#include "../c/generic/private/stdio.h"
[09b0b1fb]49
[59f799b]50/**
51 *
52 * @param c
53 * @param stream
54 * @return
55 */
56int posix_ungetc(int c, FILE *stream)
57{
58 // TODO
59 not_implemented();
60}
61
[4f4b4e7]62/**
63 *
64 * @param filename
65 * @param mode
66 * @param stream
67 * @return
68 */
69FILE *posix_freopen(
70 const char *restrict filename,
71 const char *restrict mode,
72 FILE *restrict stream)
[09b0b1fb]73{
[ab547063]74 assert(mode != NULL);
75 assert(stream != NULL);
76
77 if (filename == NULL) {
78 // TODO
79
80 /* print error to stderr as well, to avoid hard to find problems
[4f4b4e7]81 * with buggy apps that expect this to work
82 */
83 fprintf(stderr,
84 "ERROR: Application wants to use freopen() to change mode of opened stream.\n"
85 " libposix does not support that yet, the application may function improperly.\n");
[ab547063]86 errno = ENOTSUP;
87 return NULL;
88 }
89
90 FILE* copy = malloc(sizeof(FILE));
91 if (copy == NULL) {
92 errno = ENOMEM;
93 return NULL;
94 }
95 memcpy(copy, stream, sizeof(FILE));
[4f4b4e7]96 fclose(copy); /* copy is now freed */
[ab547063]97
[4f4b4e7]98 copy = fopen(filename, mode); /* open new stream */
[ab547063]99 if (copy == NULL) {
100 /* fopen() sets errno */
101 return NULL;
102 }
103
104 /* move the new stream to the original location */
105 memcpy(stream, copy, sizeof (FILE));
106 free(copy);
107
108 /* update references in the file list */
109 stream->link.next->prev = &stream->link;
110 stream->link.prev->next = &stream->link;
111
112 return stream;
[09b0b1fb]113}
114
[4f4b4e7]115/**
116 *
117 * @param s
118 */
[09b0b1fb]119void posix_perror(const char *s)
120{
121 // TODO
122 not_implemented();
123}
124
[b08ef1fd]125/**
126 *
127 * @param stream
128 * @param offset
129 * @param whence
130 * @return
131 */
132int posix_fseeko(FILE *stream, posix_off_t offset, int whence)
133{
134 // TODO
135 not_implemented();
136}
137
138/**
139 *
140 * @param stream
141 * @return
142 */
143posix_off_t posix_ftello(FILE *stream)
144{
145 // TODO
146 not_implemented();
147}
148
[59f799b]149/**
150 *
151 * @param s
152 * @param format
153 * @param ...
154 * @return
155 */
156int posix_sprintf(char *s, const char *format, ...)
157{
158 // TODO
159 not_implemented();
160}
161
[823a929]162/**
163 *
164 * @param s
165 * @param format
166 * @param ...
167 * @return
168 */
169int posix_vsprintf(char *s, const char *format, va_list ap)
170{
171 // TODO: low priority, just a compile-time dependency of binutils
172 not_implemented();
173}
174
[59f799b]175/**
176 *
177 * @param s
178 * @param format
179 * @param ...
180 * @return
181 */
182int posix_sscanf(const char *s, const char *format, ...)
183{
184 // TODO
185 not_implemented();
186}
187
[823a929]188/**
189 *
190 * @param path
191 * @return
192 */
193int posix_remove(const char *path)
194{
195 // TODO: low priority, just a compile-time dependency of binutils
196 not_implemented();
197}
198
199/**
200 *
201 * @param s
202 * @return
203 */
204char *posix_tmpnam(char *s)
205{
206 // TODO: low priority, just a compile-time dependency of binutils
207 not_implemented();
208}
209
[09b0b1fb]210/** @}
211 */
Note: See TracBrowser for help on using the repository browser.