2012-07-31 14:16:03 +02:00
|
|
|
/*******************************************************************************
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2013-01-14 22:58:07 +01:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2013-07-10 15:26:01 +02:00
|
|
|
This file is part of the Sortix C Library.
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2013-07-10 15:26:01 +02:00
|
|
|
The Sortix C Library is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2013-07-10 15:26:01 +02:00
|
|
|
The Sortix C Library is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2013-07-10 15:26:01 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2013-07-10 15:26:01 +02:00
|
|
|
stdio.h
|
|
|
|
Standard buffered input/output.
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2012-07-31 14:16:03 +02:00
|
|
|
*******************************************************************************/
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2013-07-20 14:10:06 +02:00
|
|
|
#ifndef INCLUDE_STDIO_H
|
|
|
|
#define INCLUDE_STDIO_H
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2013-10-13 13:04:27 +02:00
|
|
|
#include <sys/cdefs.h>
|
2013-09-23 16:37:33 +02:00
|
|
|
|
|
|
|
#include <sys/__/types.h>
|
|
|
|
|
2012-02-24 17:34:50 +01:00
|
|
|
#include <sortix/seek.h>
|
2012-05-28 16:58:25 +02:00
|
|
|
#if __STRICT_ANSI__
|
|
|
|
#define __need___va_list
|
|
|
|
#endif
|
|
|
|
#include <stdarg.h>
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2014-01-18 16:21:46 +01:00
|
|
|
#if defined(__is_sortix_libc)
|
2013-10-01 15:33:53 +02:00
|
|
|
#include <FILE.h>
|
|
|
|
#endif
|
|
|
|
|
2011-08-05 14:25:00 +02:00
|
|
|
__BEGIN_DECLS
|
|
|
|
|
2013-12-27 01:44:03 +01:00
|
|
|
#ifndef __off_t_defined
|
|
|
|
#define __off_t_defined
|
|
|
|
typedef __off_t off_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __size_t_defined
|
|
|
|
#define __size_t_defined
|
|
|
|
#define __need_size_t
|
|
|
|
#include <stddef.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __ssize_t_defined
|
|
|
|
#define __ssize_t_defined
|
|
|
|
typedef __ssize_t ssize_t;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef NULL
|
|
|
|
#define __need_NULL
|
|
|
|
#include <stddef.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __FILE_defined
|
|
|
|
#define __FILE_defined
|
|
|
|
typedef struct FILE FILE;
|
|
|
|
#define FILE FILE
|
|
|
|
#endif
|
Implemented large parts of the stdio(3), including fprintf.
Made FILE an interface to various backends. This allows application writers
to override the standard FILE API functions with their own backends. This
is highly unportable - it'd be nice if a real standard existed for this.
glibc already does something like this internally, but AFAIK you can't hook
into it.
Added fdopen(3), fopen(3), fregister(3), funregister(3), fread(3),
fwrite(3), fseek(3), clearerr(3), ferror(3), feof(3), rewind(3), ftell(3),
fflush(3), fclose(3), fileno(3), fnewline(3), fcloseall(3), memset(3),
stdio(3), vfprintf(3), fprintf(3), and vprintf(3).
Added a file-descriptor backend to the FILE API.
fd's {0, 1, 2} are now initialized as stdin, stdout, and stderr when the
standard library initializes.
fcloseall(3) is now called on exit(3).
decl/intn_t_.h now @include(size_t.h) instead of declaring it itself.
Added <stdint.h>.
The following programs now flush stdout: cat(1), clear(1), editor(1),
init(1), mxsh(1).
printf(3) is now hooked up against vprintf(3), while Maxsi::PrintF
remains using the system call, for now.
2011-12-24 04:08:10 +01:00
|
|
|
|
2013-04-22 00:29:58 +02:00
|
|
|
typedef off_t fpos_t;
|
Implemented large parts of the stdio(3), including fprintf.
Made FILE an interface to various backends. This allows application writers
to override the standard FILE API functions with their own backends. This
is highly unportable - it'd be nice if a real standard existed for this.
glibc already does something like this internally, but AFAIK you can't hook
into it.
Added fdopen(3), fopen(3), fregister(3), funregister(3), fread(3),
fwrite(3), fseek(3), clearerr(3), ferror(3), feof(3), rewind(3), ftell(3),
fflush(3), fclose(3), fileno(3), fnewline(3), fcloseall(3), memset(3),
stdio(3), vfprintf(3), fprintf(3), and vprintf(3).
Added a file-descriptor backend to the FILE API.
fd's {0, 1, 2} are now initialized as stdin, stdout, and stderr when the
standard library initializes.
fcloseall(3) is now called on exit(3).
decl/intn_t_.h now @include(size_t.h) instead of declaring it itself.
Added <stdint.h>.
The following programs now flush stdout: cat(1), clear(1), editor(1),
init(1), mxsh(1).
printf(3) is now hooked up against vprintf(3), while Maxsi::PrintF
remains using the system call, for now.
2011-12-24 04:08:10 +01:00
|
|
|
|
2011-08-05 14:25:00 +02:00
|
|
|
/* TODO: Implement L_ctermid */
|
2013-04-22 11:37:29 +02:00
|
|
|
#define L_tmpnam 128
|
2011-08-05 14:25:00 +02:00
|
|
|
|
|
|
|
/* The possibilities for the third argument to `setvbuf'. */
|
|
|
|
#define _IOFBF 0 /* Fully buffered. */
|
|
|
|
#define _IOLBF 1 /* Line buffered. */
|
|
|
|
#define _IONBF 2 /* No buffering. */
|
|
|
|
|
|
|
|
#define EOF (-1)
|
|
|
|
|
2012-09-29 00:53:50 +02:00
|
|
|
/* FILENAME_MAX, FOPEN_MAX, TMP_MAX are not defined because libc and Sortix
|
2011-08-05 14:25:00 +02:00
|
|
|
do not have these restrictions. */
|
|
|
|
|
|
|
|
/* Default path prefix for `tempnam' and `tmpnam'. */
|
|
|
|
#define P_tmpdir "/tmp"
|
|
|
|
|
2013-10-01 15:33:53 +02:00
|
|
|
/* Size of <stdio.h> buffers. */
|
|
|
|
#define BUFSIZ 8192UL
|
|
|
|
|
2011-08-05 14:25:00 +02:00
|
|
|
extern FILE* stdin;
|
|
|
|
extern FILE* stdout;
|
|
|
|
extern FILE* stderr;
|
|
|
|
|
|
|
|
/* C89/C99 say they're macros. Make them happy. */
|
|
|
|
#define stdin stdin
|
|
|
|
#define stdout stdout
|
|
|
|
#define stderr stderr
|
|
|
|
|
2013-09-23 00:47:26 +02:00
|
|
|
void clearerr(FILE* stream);
|
|
|
|
int dprintf(int fildes, const char* __restrict format, ...);
|
|
|
|
int fclose(FILE* stream);
|
|
|
|
FILE* fdopen(int fildes, const char* mode);
|
|
|
|
int feof(FILE* stream);
|
|
|
|
int ferror(FILE* stream);
|
|
|
|
int fflush(FILE* stream);
|
|
|
|
int fileno(FILE* stream);
|
|
|
|
int fgetc(FILE* stream);
|
|
|
|
int fgetpos(FILE* __restrict stream, fpos_t* __restrict pos);
|
|
|
|
char* fgets(char* __restrict s, int n, FILE* __restrict stream);
|
|
|
|
void flockfile(FILE* file);
|
|
|
|
FILE* fopen(const char* __restrict filename, const char* __restrict mode);
|
|
|
|
int fprintf(FILE* __restrict stream, const char* __restrict format, ...);
|
|
|
|
int fputc(int c, FILE* stream);
|
|
|
|
int fputs(const char* __restrict s, FILE* __restrict stream);
|
|
|
|
size_t fread(void* __restrict ptr, size_t size, size_t nitems, FILE* __restrict stream);
|
|
|
|
FILE* freopen(const char* __restrict filename, const char *__restrict mode, FILE* __restrict stream);
|
|
|
|
int fscanf(FILE* __restrict stream, const char* __restrict format, ... );
|
|
|
|
int fseek(FILE* stream, long offset, int whence);
|
|
|
|
int fseeko(FILE* stream, off_t offset, int whence);
|
|
|
|
int fsetpos(FILE* stream, const fpos_t* pos);
|
|
|
|
long ftell(FILE* stream);
|
|
|
|
off_t ftello(FILE* stream);
|
|
|
|
int ftrylockfile(FILE* file);
|
|
|
|
void funlockfile(FILE* file);
|
|
|
|
size_t fwrite(const void* __restrict ptr, size_t size, size_t nitems, FILE* __restrict stream);
|
|
|
|
int getc(FILE* stream);
|
|
|
|
int getchar(void);
|
|
|
|
ssize_t getdelim(char** __restrict lineptr, size_t* __restrict n, int delimiter, FILE* __restrict stream);
|
|
|
|
ssize_t getline(char** __restrict lineptr, size_t* __restrict n, FILE* __restrict stream);
|
|
|
|
int pclose(FILE* steam);
|
|
|
|
void perror(const char* s);
|
|
|
|
FILE* popen(const char* command, const char* mode);
|
|
|
|
int printf(const char* __restrict format, ...);
|
|
|
|
int putc(int c, FILE* stream);
|
|
|
|
int putchar(int c);
|
|
|
|
int puts(const char* str);
|
|
|
|
int removeat(int dirrfd, const char* path);
|
|
|
|
int remove(const char* path);
|
|
|
|
int renameat(int oldfd, const char* oldname, int newfd, const char* newname);
|
|
|
|
int rename(const char* oldname, const char* newname);
|
|
|
|
void rewind(FILE* stream);
|
|
|
|
int snprintf(char* __restrict s, size_t n, const char* __restrict format, ...);
|
|
|
|
void setbuf(FILE* __restrict stream, char* __restrict buf);
|
|
|
|
int setvbuf(FILE* __restrict stream, char* __restrict buf, int type, size_t size);
|
|
|
|
char* sortix_gets(void);
|
|
|
|
int sortix_puts(const char* str);
|
|
|
|
int sprintf(char* __restrict s, const char* __restrict format, ...);
|
|
|
|
int scanf(const char* __restrict format, ...);
|
|
|
|
int sscanf(const char* __restrict s, const char* __restrict format, ...);
|
|
|
|
FILE* tmpfile(void);
|
|
|
|
char* tmpnam(char* s);
|
|
|
|
int ungetc(int c, FILE* stream);
|
|
|
|
int vdprintf(int fildes, const char* __restrict format, __gnuc_va_list ap);
|
|
|
|
int vfprintf(FILE* __restrict stream, const char* __restrict format, __gnuc_va_list ap);
|
|
|
|
int vfscanf(FILE* __restrict stream, const char* __restrict format, __gnuc_va_list arg);
|
|
|
|
int vprintf(const char* __restrict format, __gnuc_va_list ap);
|
|
|
|
int vscanf(const char* __restrict format, __gnuc_va_list arg);
|
|
|
|
int vsnprintf(char* __restrict, size_t, const char* __restrict, __gnuc_va_list);
|
|
|
|
int vsprintf(char* __restrict s, const char* __restrict format, __gnuc_va_list ap);
|
|
|
|
int vsscanf(const char* __restrict s, const char* __restrict format, __gnuc_va_list arg);
|
2011-08-05 14:25:00 +02:00
|
|
|
|
2012-09-29 00:53:50 +02:00
|
|
|
/* TODO: These are not implemented in sortix libc yet. */
|
2013-09-23 16:57:22 +02:00
|
|
|
#if 0
|
2013-09-23 00:47:26 +02:00
|
|
|
char* ctermid(char* s);
|
|
|
|
FILE *fmemopen(void* __restrict buf, size_t size, const char* __restrict mode);
|
|
|
|
FILE* open_memstream(char** bufp, size_t* sizep);
|
|
|
|
int getchar_unlocked(void);
|
|
|
|
int getc_unlocked(FILE* stream);
|
|
|
|
int putchar_unlocked(int c);
|
|
|
|
int putc_unlocked(int c, FILE* steam);
|
2011-08-05 14:25:00 +02:00
|
|
|
#endif
|
|
|
|
|
2012-02-11 18:50:12 +01:00
|
|
|
#if defined(_SORTIX_SOURCE)
|
2012-03-12 00:38:48 +01:00
|
|
|
#include <stdio_ext.h>
|
|
|
|
#define fbufsize __fbufsize
|
|
|
|
#define freading __freading
|
|
|
|
#define fwriting __fwriting
|
|
|
|
#define freadable __freadable
|
|
|
|
#define fwritable __fwritable
|
|
|
|
#define flbf __flbf
|
|
|
|
#define fpurge __fpurge
|
|
|
|
#define fpending __fpending
|
|
|
|
#define flushlbf _flushlbf
|
|
|
|
#define fsetlocking __fsetlocking
|
2012-12-08 21:14:29 +01:00
|
|
|
int fflush_stop_reading(FILE* fp);
|
|
|
|
int fflush_stop_writing(FILE* fp);
|
2013-03-20 22:12:20 +01:00
|
|
|
void fdeletefile(FILE* fp);
|
2012-03-12 00:53:14 +01:00
|
|
|
void fseterr(FILE* fp);
|
Implemented large parts of the stdio(3), including fprintf.
Made FILE an interface to various backends. This allows application writers
to override the standard FILE API functions with their own backends. This
is highly unportable - it'd be nice if a real standard existed for this.
glibc already does something like this internally, but AFAIK you can't hook
into it.
Added fdopen(3), fopen(3), fregister(3), funregister(3), fread(3),
fwrite(3), fseek(3), clearerr(3), ferror(3), feof(3), rewind(3), ftell(3),
fflush(3), fclose(3), fileno(3), fnewline(3), fcloseall(3), memset(3),
stdio(3), vfprintf(3), fprintf(3), and vprintf(3).
Added a file-descriptor backend to the FILE API.
fd's {0, 1, 2} are now initialized as stdin, stdout, and stderr when the
standard library initializes.
fcloseall(3) is now called on exit(3).
decl/intn_t_.h now @include(size_t.h) instead of declaring it itself.
Added <stdint.h>.
The following programs now flush stdout: cat(1), clear(1), editor(1),
init(1), mxsh(1).
printf(3) is now hooked up against vprintf(3), while Maxsi::PrintF
remains using the system call, for now.
2011-12-24 04:08:10 +01:00
|
|
|
void fregister(FILE* fp);
|
2013-03-20 22:12:20 +01:00
|
|
|
void fresetfile(FILE* fp);
|
Implemented large parts of the stdio(3), including fprintf.
Made FILE an interface to various backends. This allows application writers
to override the standard FILE API functions with their own backends. This
is highly unportable - it'd be nice if a real standard existed for this.
glibc already does something like this internally, but AFAIK you can't hook
into it.
Added fdopen(3), fopen(3), fregister(3), funregister(3), fread(3),
fwrite(3), fseek(3), clearerr(3), ferror(3), feof(3), rewind(3), ftell(3),
fflush(3), fclose(3), fileno(3), fnewline(3), fcloseall(3), memset(3),
stdio(3), vfprintf(3), fprintf(3), and vprintf(3).
Added a file-descriptor backend to the FILE API.
fd's {0, 1, 2} are now initialized as stdin, stdout, and stderr when the
standard library initializes.
fcloseall(3) is now called on exit(3).
decl/intn_t_.h now @include(size_t.h) instead of declaring it itself.
Added <stdint.h>.
The following programs now flush stdout: cat(1), clear(1), editor(1),
init(1), mxsh(1).
printf(3) is now hooked up against vprintf(3), while Maxsi::PrintF
remains using the system call, for now.
2011-12-24 04:08:10 +01:00
|
|
|
void funregister(FILE* fp);
|
|
|
|
FILE* fnewfile(void);
|
2013-03-20 19:01:35 +01:00
|
|
|
int fsetdefaultbuf(FILE* fp);
|
Implemented large parts of the stdio(3), including fprintf.
Made FILE an interface to various backends. This allows application writers
to override the standard FILE API functions with their own backends. This
is highly unportable - it'd be nice if a real standard existed for this.
glibc already does something like this internally, but AFAIK you can't hook
into it.
Added fdopen(3), fopen(3), fregister(3), funregister(3), fread(3),
fwrite(3), fseek(3), clearerr(3), ferror(3), feof(3), rewind(3), ftell(3),
fflush(3), fclose(3), fileno(3), fnewline(3), fcloseall(3), memset(3),
stdio(3), vfprintf(3), fprintf(3), and vprintf(3).
Added a file-descriptor backend to the FILE API.
fd's {0, 1, 2} are now initialized as stdin, stdout, and stderr when the
standard library initializes.
fcloseall(3) is now called on exit(3).
decl/intn_t_.h now @include(size_t.h) instead of declaring it itself.
Added <stdint.h>.
The following programs now flush stdout: cat(1), clear(1), editor(1),
init(1), mxsh(1).
printf(3) is now hooked up against vprintf(3), while Maxsi::PrintF
remains using the system call, for now.
2011-12-24 04:08:10 +01:00
|
|
|
int fcloseall(void);
|
2013-03-20 22:12:20 +01:00
|
|
|
int fshutdown(FILE* fp);
|
2012-05-21 12:52:27 +02:00
|
|
|
int fpipe(FILE* pipes[2]);
|
2012-07-31 14:16:03 +02:00
|
|
|
/* Internally used by standard library. */
|
2013-09-22 23:43:16 +02:00
|
|
|
#if defined(__is_sortix_libc)
|
2012-07-31 14:16:03 +02:00
|
|
|
extern FILE* _firstfile;
|
|
|
|
#endif
|
Implemented large parts of the stdio(3), including fprintf.
Made FILE an interface to various backends. This allows application writers
to override the standard FILE API functions with their own backends. This
is highly unportable - it'd be nice if a real standard existed for this.
glibc already does something like this internally, but AFAIK you can't hook
into it.
Added fdopen(3), fopen(3), fregister(3), funregister(3), fread(3),
fwrite(3), fseek(3), clearerr(3), ferror(3), feof(3), rewind(3), ftell(3),
fflush(3), fclose(3), fileno(3), fnewline(3), fcloseall(3), memset(3),
stdio(3), vfprintf(3), fprintf(3), and vprintf(3).
Added a file-descriptor backend to the FILE API.
fd's {0, 1, 2} are now initialized as stdin, stdout, and stderr when the
standard library initializes.
fcloseall(3) is now called on exit(3).
decl/intn_t_.h now @include(size_t.h) instead of declaring it itself.
Added <stdint.h>.
The following programs now flush stdout: cat(1), clear(1), editor(1),
init(1), mxsh(1).
printf(3) is now hooked up against vprintf(3), while Maxsi::PrintF
remains using the system call, for now.
2011-12-24 04:08:10 +01:00
|
|
|
#endif
|
|
|
|
|
2012-09-22 21:09:33 +02:00
|
|
|
#if defined(_SORTIX_SOURCE) || defined(_WANT_SORTIX_VPRINTF_CALLBACK)
|
2013-09-23 00:47:26 +02:00
|
|
|
size_t vprintf_callback(size_t (*callback)(void*, const char*, size_t),
|
|
|
|
void* user,
|
|
|
|
const char* __restrict format,
|
|
|
|
__gnuc_va_list ap);
|
2012-09-22 21:09:33 +02:00
|
|
|
#endif
|
|
|
|
|
2011-08-05 14:25:00 +02:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|