source: mainline/uspace/lib/c/include/stdio.h@ 4e6a610

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

Temporary file functions rework. Fix libposix access() not working on directories.

  • Property mode set to 100644
File size: 5.7 KB
RevLine 
[3eddaff]1/*
[df4ed85]2 * Copyright (c) 2005 Martin Decky
[777832e]3 * Copyright (c) 2018 Jiri Svoboda
[3eddaff]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
[fadd381]30/** @addtogroup libc
[b2951e2]31 * @{
32 */
33/** @file
34 */
35
[fadd381]36#ifndef LIBC_STDIO_H_
37#define LIBC_STDIO_H_
[3eddaff]38
[777832e]39#include <offset.h>
[3214a20]40#include <stdarg.h>
[aa492fe]41#include <io/verify.h>
[4e6a610]42#include <_bits/NULL.h>
[1d6dd2a]43#include <_bits/size_t.h>
44#include <_bits/wchar_t.h>
[ed88c8e]45#include <_bits/wint_t.h>
[9ac2013]46
[4e6a610]47/** Forward declaration */
48struct _IO_FILE;
49typedef struct _IO_FILE FILE;
[c23275a]50
[4e6a610]51/** File position */
52typedef struct {
53 off64_t pos;
54} fpos_t;
[c23275a]55
[4e6a610]56#ifndef _HELENOS_SOURCE
57#define _IONBF 0
58#define _IOLBF 1
59#define _IOFBF 2
[c23275a]60#endif
61
[ef8bcc6]62/** Default size for stream I/O buffers */
[db24058]63#define BUFSIZ 4096
[ef8bcc6]64
[4e6a610]65#define EOF (-1)
66
[777832e]67/** Max number of files that is guaranteed to be able to open at the same time */
68#define FOPEN_MAX VFS_MAX_OPEN_FILES
69
[55092672]70/** Recommended size of fixed-size array for holding file names. */
71#define FILENAME_MAX 4096
72
[4e6a610]73/** Length of "/tmp/tmp.XXXXXX" + 1 */
74#define L_tmpnam 16
[04b687b]75
[4e6a610]76#ifndef SEEK_SET
77#define SEEK_SET 0
78#endif
79
80#ifndef SEEK_CUR
81#define SEEK_CUR 1
82#endif
83
84#ifndef SEEK_END
85#define SEEK_END 2
86#endif
87
88/** Minimum number of unique temporary file names */
89#define TMP_MAX 1000000
[777832e]90
[2595dab]91extern FILE *stdin;
92extern FILE *stdout;
93extern FILE *stderr;
94
95/* Character and string input functions */
[55092672]96#define getc fgetc
[2595dab]97extern int fgetc(FILE *);
[c62d2e1]98extern char *fgets(char *, int, FILE *);
[296890f3]99extern char *gets(char *, size_t) __attribute__((deprecated));
[1c1002a]100
[b27a97bb]101extern int getchar(void);
102
[2595dab]103/* Character and string output functions */
[55092672]104#define putc fputc
[ed88c8e]105extern int fputc(int, FILE *);
[2595dab]106extern int fputs(const char *, FILE *);
107
[ed88c8e]108extern int putchar(int);
[ab00d5a]109extern int puts(const char *);
[3eddaff]110
[bd5414e]111extern int ungetc(int, FILE *);
112
[ed88c8e]113extern wint_t fputwc(wchar_t, FILE *);
114extern wint_t putwchar(wchar_t);
115
[2595dab]116/* Formatted string output functions */
[1433ecda]117extern int fprintf(FILE *, const char *, ...)
[09d13c8e]118 _HELENOS_PRINTF_ATTRIBUTE(2, 3);
[2595dab]119extern int vfprintf(FILE *, const char *, va_list);
[3214a20]120
[9ac2013]121extern int printf(const char *, ...)
[09d13c8e]122 _HELENOS_PRINTF_ATTRIBUTE(1, 2);
[ab00d5a]123extern int vprintf(const char *, va_list);
[3214a20]124
[1433ecda]125extern int snprintf(char *, size_t, const char *, ...)
[09d13c8e]126 _HELENOS_PRINTF_ATTRIBUTE(3, 4);
[55092672]127#if defined(_HELENOS_SOURCE) || defined(_GNU_SOURCE)
[a9763c6]128extern int vasprintf(char **, const char *, va_list);
[9ac2013]129extern int asprintf(char **, const char *, ...)
[09d13c8e]130 _HELENOS_PRINTF_ATTRIBUTE(2, 3);
[296890f3]131#endif
[2595dab]132extern int vsnprintf(char *, size_t, const char *, va_list);
[a8e9ab8d]133
[296890f3]134extern int sprintf(char *, const char *, ...)
135 __attribute__((deprecated)) _HELENOS_PRINTF_ATTRIBUTE(2, 3);
136extern int vsprintf(char *, const char *, va_list) __attribute__((deprecated));
137
[5a6c28d1]138/* Formatted input */
139extern int scanf(const char *, ...);
140extern int vscanf(const char *, va_list);
141extern int fscanf(FILE *, const char *, ...);
142extern int vfscanf(FILE *, const char *, va_list);
143extern int sscanf(const char *, const char *, ...);
144extern int vsscanf(const char *, const char *, va_list);
[ed18e14]145
[2595dab]146/* File stream functions */
[04b687b]147extern FILE *fopen(const char *, const char *);
[80bee81]148extern FILE *freopen(const char *, const char *, FILE *);
[04b687b]149extern int fclose(FILE *);
[2595dab]150
[04b687b]151extern size_t fread(void *, size_t, size_t, FILE *);
152extern size_t fwrite(const void *, size_t, size_t, FILE *);
[2595dab]153
[777832e]154extern int fgetpos(FILE *, fpos_t *);
155extern int fsetpos(FILE *, const fpos_t *);
156
[456c086]157extern int fseek(FILE *, long, int);
[080ad7f]158extern void rewind(FILE *);
[456c086]159extern long ftell(FILE *);
[04b687b]160extern int feof(FILE *);
[2595dab]161
162extern int fflush(FILE *);
[04b687b]163extern int ferror(FILE *);
164extern void clearerr(FILE *);
165
[777832e]166extern void perror(const char *);
167
[ef8bcc6]168extern void setvbuf(FILE *, void *, int, size_t);
[7699c21]169extern void setbuf(FILE *, void *);
[ef8bcc6]170
[b942a66]171/* Misc file functions */
172extern int remove(const char *);
[4e6a610]173extern int rename(const char *, const char *);
[b942a66]174
[4e6a610]175extern FILE *tmpfile(void);
176extern char *tmpnam(char *s) __attribute__((deprecated));
[bc1b297]177
178#ifdef _HELENOS_SOURCE
179
180/* Nonstandard extensions. */
181
182enum _buffer_type {
183 /** No buffering */
184 _IONBF,
185 /** Line buffering */
186 _IOLBF,
187 /** Full buffering */
188 _IOFBF
189};
190
191enum _buffer_state {
192 /** Buffer is empty */
193 _bs_empty,
194
195 /** Buffer contains data to be written */
196 _bs_write,
197
198 /** Buffer contains prefetched data for reading */
199 _bs_read
200};
201
202extern int vprintf_size(const char *, va_list);
203extern int printf_size(const char *, ...)
204 _HELENOS_PRINTF_ATTRIBUTE(1, 2);
205extern FILE *fdopen(int, const char *);
206extern int fileno(FILE *);
207
[1c7f381]208#include <offset.h>
209
210extern int fseek64(FILE *, off64_t, int);
211extern off64_t ftell64(FILE *);
212
[bc1b297]213#endif
214
215
[3eddaff]216#endif
[b2951e2]217
[fadd381]218/** @}
[b2951e2]219 */
Note: See TracBrowser for help on using the repository browser.