PageRenderTime 31ms CodeModel.GetById 13ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 1ms

/uspace/lib/posix/include/posix/stdio.h

https://gitlab.com/vhelen/vhelen
C Header | 222 lines | 115 code | 40 blank | 67 comment | 0 complexity | 72c3cd22bd44c89192f4194f665ac9e1 MD5 | raw file
  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 Standard buffered input/output.
 34 */
 35
 36#ifndef POSIX_STDIO_H_
 37#define POSIX_STDIO_H_
 38
 39#ifndef __POSIX_DEF__
 40#define __POSIX_DEF__(x) x
 41/* DEBUG macro does not belong to POSIX stdio.h. Its unconditional
 42 * definition in the native stdio.h causes unexpected behaviour of
 43 * applications which uses their own DEBUG macro (e.g. debugging
 44 * output is printed even if not desirable). */
 45#undef DEBUG
 46#endif
 47
 48#include "stddef.h"
 49#include "unistd.h"
 50#include "libc/io/verify.h"
 51#include "sys/types.h"
 52#include "stdarg.h"
 53#include "limits.h"
 54
 55/*
 56 * These are the same as in HelenOS libc.
 57 * It would be possible to directly include <stdio.h> but
 58 * it is better not to pollute POSIX namespace with other functions
 59 * defined in that header.
 60 *
 61 * Because libposix is always linked with libc, providing only these
 62 * forward declarations ought to be enough.
 63 */
 64#define EOF (-1)
 65
 66/** Size of buffers used in stdio header. */
 67#define BUFSIZ  4096
 68
 69/** Maximum size in bytes of the longest filename. */
 70#define FILENAME_MAX 4096
 71
 72typedef struct _IO_FILE FILE;
 73
 74#ifndef LIBPOSIX_INTERNAL
 75	enum _buffer_type {
 76		/** No buffering */
 77		_IONBF,
 78		/** Line buffering */
 79		_IOLBF,
 80		/** Full buffering */
 81		_IOFBF
 82	};
 83#endif
 84
 85extern FILE *stdin;
 86extern FILE *stdout;
 87extern FILE *stderr;
 88
 89extern int fgetc(FILE *);
 90extern char *fgets(char *, int, FILE *);
 91
 92extern int getchar(void);
 93extern char *gets(char *, size_t);
 94
 95extern int fputc(wchar_t, FILE *);
 96extern int fputs(const char *, FILE *);
 97
 98extern int putchar(wchar_t);
 99extern int puts(const char *);
100
101extern int fprintf(FILE *, const char*, ...) PRINTF_ATTRIBUTE(2, 3);
102extern int vfprintf(FILE *, const char *, va_list);
103
104extern int printf(const char *, ...) PRINTF_ATTRIBUTE(1, 2);
105extern int vprintf(const char *, va_list);
106
107extern int snprintf(char *, size_t , const char *, ...) PRINTF_ATTRIBUTE(3, 4);
108#ifdef _GNU_SOURCE
109extern int vasprintf(char **, const char *, va_list);
110extern int asprintf(char **, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
111#endif
112extern int vsnprintf(char *, size_t, const char *, va_list);
113
114extern FILE *fopen(const char *, const char *);
115extern FILE *fdopen(int, const char *);
116extern int fclose(FILE *);
117
118extern size_t fread(void *, size_t, size_t, FILE *);
119extern size_t fwrite(const void *, size_t, size_t, FILE *);
120
121extern void rewind(FILE *);
122extern int feof(FILE *);
123extern int fileno(FILE *);
124
125extern int fflush(FILE *);
126extern int ferror(FILE *);
127extern void clearerr(FILE *);
128
129extern void setvbuf(FILE *, void *, int, size_t);
130extern void setbuf(FILE *, void *);
131
132/* POSIX specific stuff. */
133
134/* Identifying the Terminal */
135#undef L_ctermid
136#define L_ctermid PATH_MAX
137extern char *__POSIX_DEF__(ctermid)(char *s);
138
139/* Error Recovery */
140extern void __POSIX_DEF__(clearerr)(FILE *stream);
141
142/* Input/Output */
143#undef putc
144#define putc fputc
145extern int __POSIX_DEF__(fputs)(const char *restrict s, FILE *restrict stream);
146#undef getc
147#define getc fgetc
148extern int __POSIX_DEF__(ungetc)(int c, FILE *stream);
149extern ssize_t __POSIX_DEF__(getdelim)(char **restrict lineptr, size_t *restrict n,
150    int delimiter, FILE *restrict stream);
151extern ssize_t __POSIX_DEF__(getline)(char **restrict lineptr, size_t *restrict n,
152    FILE *restrict stream);
153
154/* Opening Streams */
155extern FILE *__POSIX_DEF__(freopen)(const char *restrict filename,
156    const char *restrict mode, FILE *restrict stream);
157
158/* Error Messages */
159extern void __POSIX_DEF__(perror)(const char *s);
160
161/* File Positioning */
162typedef struct {
163	off64_t offset;
164} __POSIX_DEF__(fpos_t);
165
166extern int __POSIX_DEF__(fsetpos)(FILE *stream, const __POSIX_DEF__(fpos_t) *pos);
167extern int __POSIX_DEF__(fgetpos)(FILE *restrict stream, __POSIX_DEF__(fpos_t) *restrict pos);
168extern int __POSIX_DEF__(fseek)(FILE *stream, long offset, int whence);
169extern int __POSIX_DEF__(fseeko)(FILE *stream, __POSIX_DEF__(off_t) offset, int whence);
170extern long __POSIX_DEF__(ftell)(FILE *stream);
171extern __POSIX_DEF__(off_t) __POSIX_DEF__(ftello)(FILE *stream);
172
173/* Flushing Buffers */
174extern int __POSIX_DEF__(fflush)(FILE *stream);
175
176/* Formatted Output */
177extern int __POSIX_DEF__(dprintf)(int fildes, const char *restrict format, ...)
178    PRINTF_ATTRIBUTE(2, 3);
179extern int __POSIX_DEF__(vdprintf)(int fildes, const char *restrict format, va_list ap);
180extern int __POSIX_DEF__(sprintf)(char *restrict s, const char *restrict format, ...)
181    PRINTF_ATTRIBUTE(2, 3);
182extern int __POSIX_DEF__(vsprintf)(char *restrict s, const char *restrict format, va_list ap);
183
184/* Formatted Input */
185extern int __POSIX_DEF__(fscanf)(
186    FILE *restrict stream, const char *restrict format, ...);
187extern int __POSIX_DEF__(vfscanf)(
188    FILE *restrict stream, const char *restrict format, va_list arg);
189extern int __POSIX_DEF__(scanf)(const char *restrict format, ...);
190extern int __POSIX_DEF__(vscanf)(const char *restrict format, va_list arg);
191extern int __POSIX_DEF__(sscanf)(
192    const char *restrict s, const char *restrict format, ...);
193extern int __POSIX_DEF__(vsscanf)(
194    const char *restrict s, const char *restrict format, va_list arg);
195
196/* File Locking */
197extern void __POSIX_DEF__(flockfile)(FILE *file);
198extern int __POSIX_DEF__(ftrylockfile)(FILE *file);
199extern void __POSIX_DEF__(funlockfile)(FILE *file);
200extern int __POSIX_DEF__(getc_unlocked)(FILE *stream);
201extern int __POSIX_DEF__(getchar_unlocked)(void);
202extern int __POSIX_DEF__(putc_unlocked)(int c, FILE *stream);
203extern int __POSIX_DEF__(putchar_unlocked)(int c);
204
205/* Deleting Files */
206extern int __POSIX_DEF__(remove)(const char *path);
207
208/* Renaming Files */
209extern int __POSIX_DEF__(rename)(const char *oldname, const char *newname);
210
211/* Temporary Files */
212#undef L_tmpnam
213#define L_tmpnam PATH_MAX
214extern char *__POSIX_DEF__(tmpnam)(char *s);
215extern char *__POSIX_DEF__(tempnam)(const char *dir, const char *pfx);
216extern FILE *__POSIX_DEF__(tmpfile)(void);
217
218
219#endif /* POSIX_STDIO_H_ */
220
221/** @}
222 */