source: mainline/uspace/lib/posix/stdio.c@ 491e1ee

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

Unified usage of LIBPOSIX_INTERNAL macro.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (c) 2011 Jiri Zarevucky
3 * Copyright (c) 2011 Petr Koupy
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
36#define LIBPOSIX_INTERNAL
37
38#include <assert.h>
39#include <errno.h>
40
41#include "common.h"
42#include "stdio.h"
43#include "string.h"
44
45/* not the best of solutions, but freopen will eventually
46 * need to be implemented in libc anyway
47 */
48#include "../c/generic/private/stdio.h"
49
50/**
51 *
52 * @param filename
53 * @param mode
54 * @param stream
55 * @return
56 */
57FILE *posix_freopen(
58 const char *restrict filename,
59 const char *restrict mode,
60 FILE *restrict stream)
61{
62 assert(mode != NULL);
63 assert(stream != NULL);
64
65 if (filename == NULL) {
66 // TODO
67
68 /* print error to stderr as well, to avoid hard to find problems
69 * with buggy apps that expect this to work
70 */
71 fprintf(stderr,
72 "ERROR: Application wants to use freopen() to change mode of opened stream.\n"
73 " libposix does not support that yet, the application may function improperly.\n");
74 errno = ENOTSUP;
75 return NULL;
76 }
77
78 FILE* copy = malloc(sizeof(FILE));
79 if (copy == NULL) {
80 errno = ENOMEM;
81 return NULL;
82 }
83 memcpy(copy, stream, sizeof(FILE));
84 fclose(copy); /* copy is now freed */
85
86 copy = fopen(filename, mode); /* open new stream */
87 if (copy == NULL) {
88 /* fopen() sets errno */
89 return NULL;
90 }
91
92 /* move the new stream to the original location */
93 memcpy(stream, copy, sizeof (FILE));
94 free(copy);
95
96 /* update references in the file list */
97 stream->link.next->prev = &stream->link;
98 stream->link.prev->next = &stream->link;
99
100 return stream;
101}
102
103/**
104 *
105 * @param s
106 */
107void posix_perror(const char *s)
108{
109 // TODO
110 not_implemented();
111}
112
113/**
114 *
115 * @param stream
116 * @param offset
117 * @param whence
118 * @return
119 */
120int posix_fseeko(FILE *stream, posix_off_t offset, int whence)
121{
122 // TODO
123 not_implemented();
124}
125
126/**
127 *
128 * @param stream
129 * @return
130 */
131posix_off_t posix_ftello(FILE *stream)
132{
133 // TODO
134 not_implemented();
135}
136
137/** @}
138 */
Note: See TracBrowser for help on using the repository browser.