2011-08-05 08:25:00 -04:00
|
|
|
/******************************************************************************
|
|
|
|
|
|
|
|
COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2011.
|
|
|
|
|
|
|
|
This file is part of LibMaxsi.
|
|
|
|
|
|
|
|
LibMaxsi 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.
|
|
|
|
|
|
|
|
LibMaxsi 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.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with LibMaxsi. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
stdio.h
|
|
|
|
Standard buffered input/output.
|
|
|
|
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _STDIO_H
|
|
|
|
#define _STDIO_H 1
|
|
|
|
|
|
|
|
#include <features.h>
|
2012-02-24 11:34:50 -05:00
|
|
|
#include <sortix/seek.h>
|
2011-08-05 08:25:00 -04:00
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
|
|
|
|
@include(off_t.h)
|
|
|
|
@include(size_t.h)
|
|
|
|
@include(ssize_t.h)
|
|
|
|
@include(va_list.h)
|
|
|
|
@include(NULL.h)
|
|
|
|
|
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-23 22:08:10 -05:00
|
|
|
@include(FILE.h)
|
|
|
|
|
|
|
|
struct _fpos_t;
|
|
|
|
typedef struct _fpos_t fpos_t;
|
|
|
|
|
2011-08-05 08:25:00 -04:00
|
|
|
/* TODO: Implement L_ctermid */
|
|
|
|
#if __POSIX_OBSOLETE <= 200801
|
|
|
|
/* TODO: Implement L_tmpnam */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
|
|
|
|
/* FILENAME_MAX, FOPEN_MAX, TMP_MAX are not defined because libmaxsi and Sortix
|
|
|
|
do not have these restrictions. */
|
|
|
|
|
|
|
|
/* Default path prefix for `tempnam' and `tmpnam'. */
|
|
|
|
#if __POSIX_OBSOLETE <= 200801
|
|
|
|
#define P_tmpdir "/tmp"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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-23 22:08:10 -05:00
|
|
|
extern void clearerr(FILE* stream);
|
|
|
|
extern int fclose(FILE* stream);
|
2011-12-29 19:23:00 -05:00
|
|
|
extern FILE* fdopen(int fildes, const char* mode);
|
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-23 22:08:10 -05:00
|
|
|
extern int feof(FILE* stream);
|
|
|
|
extern int ferror(FILE* stream);
|
|
|
|
extern int fflush(FILE* stream);
|
|
|
|
extern int fileno(FILE* stream);
|
2011-12-29 18:55:59 -05:00
|
|
|
extern int fgetc(FILE* stream);
|
2011-12-29 19:23:00 -05:00
|
|
|
extern FILE* fopen(const char* restrict filename, const char* restrict mode);
|
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-23 22:08:10 -05:00
|
|
|
extern int fprintf(FILE* restrict stream, const char* restrict format, ...);
|
2011-12-29 18:55:59 -05:00
|
|
|
extern int fputc(int c, FILE* stream);
|
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-23 22:08:10 -05:00
|
|
|
extern size_t fread(void* restrict ptr, size_t size, size_t nitems, FILE* restrict stream);
|
|
|
|
extern int fseek(FILE* stream, long offset, int whence);
|
2011-12-29 19:23:00 -05:00
|
|
|
extern int fseeko(FILE* stream, off_t offset, int whence);
|
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-23 22:08:10 -05:00
|
|
|
extern long ftell(FILE* stream);
|
2011-12-29 19:23:00 -05:00
|
|
|
extern off_t ftello(FILE* stream);
|
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-23 22:08:10 -05:00
|
|
|
extern size_t fwrite(const void* restrict ptr, size_t size, size_t nitems, FILE* restrict stream);
|
2011-12-29 19:03:24 -05:00
|
|
|
extern int getc(FILE* stream);
|
2011-12-29 19:06:27 -05:00
|
|
|
extern int getchar(void);
|
2012-02-12 19:07:02 -05:00
|
|
|
extern ssize_t getdelim(char** restrict lineptr, size_t* restrict n, int delimiter, FILE* restrict stream);
|
|
|
|
extern ssize_t getline(char** restrict lineptr, size_t* restrict n, FILE* restrict stream);
|
2011-11-26 05:00:45 -05:00
|
|
|
extern void perror(const char* s);
|
2011-08-05 08:25:00 -04:00
|
|
|
extern int printf(const char* restrict format, ...);
|
2011-12-29 19:03:24 -05:00
|
|
|
extern int putc(int c, FILE* stream);
|
2011-12-29 19:06:27 -05:00
|
|
|
extern int putchar(int c);
|
2012-02-12 19:07:02 -05:00
|
|
|
extern int puts(const char* str);
|
2011-12-29 19:11:33 -05:00
|
|
|
extern int remove(const char* path);
|
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-23 22:08:10 -05:00
|
|
|
extern void rewind(FILE* stream);
|
2012-01-08 18:31:42 -05:00
|
|
|
extern int snprintf(char* restrict s, size_t n, const char* restrict format, ...);
|
2012-02-12 19:07:02 -05:00
|
|
|
extern char* sortix_gets(void);
|
|
|
|
extern int sortix_puts(const char* str);
|
2012-01-08 18:31:42 -05:00
|
|
|
extern int sprintf(char* restrict s, const char* restrict format, ...);
|
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-23 22:08:10 -05:00
|
|
|
extern int vfprintf(FILE* restrict stream, const char* restrict format, va_list ap);
|
|
|
|
extern int vprintf(const char* restrict format, va_list ap);
|
2012-01-08 18:31:42 -05:00
|
|
|
extern int vsnprintf(char* restrict, size_t, const char* restrict, va_list);
|
|
|
|
extern int vsprintf(char* restrict s, const char* restrict format, va_list ap);
|
2011-08-05 08:25:00 -04:00
|
|
|
|
|
|
|
/* TODO: These are not implemented in libmaxsi/sortix yet. */
|
2012-02-11 12:50:12 -05:00
|
|
|
#if defined(__SORTIX_SHOW_UNIMPLEMENTED)
|
2011-08-05 08:25:00 -04:00
|
|
|
extern char* ctermid(char* s);
|
|
|
|
extern char* fgets(char* restrict s, int n, FILE* restrict stream);
|
|
|
|
extern FILE *fmemopen(void* restrict buf, size_t size, const char* restrict mode);
|
|
|
|
extern FILE* freopen(const char* restrict filename, const char *restrict mode, FILE* restrict stream);
|
|
|
|
extern FILE* open_memstream(char** bufp, size_t* sizep);
|
|
|
|
extern FILE* popen(const char* command, const char* mode);
|
|
|
|
extern FILE* tmpfile(void);
|
|
|
|
extern int dprintf(int fildes, const char* restrict format, ...);
|
|
|
|
extern int fgetpos(FILE* restrict stream, fpos_t* restrict pos);
|
|
|
|
extern int fputs(const char* restrict s, FILE* restrict stream);
|
|
|
|
extern int fscanf(FILE* restrict stream, const char* restrict format, ... );
|
|
|
|
extern int fsetpos(FILE* stream, const fpos_t* pos);
|
|
|
|
extern int ftrylockfile(FILE* file);
|
|
|
|
extern int getchar_unlocked(void);
|
|
|
|
extern int getc_unlocked(FILE* stream);
|
|
|
|
extern int pclose(FILE* steam);
|
|
|
|
extern int putchar_unlocked(int c);
|
|
|
|
extern int putc_unlocked(int c, FILE* steam);
|
|
|
|
extern int rename(const char* oldname, const char* newname);
|
|
|
|
extern int renameat(int oldfd, const char* oldname, int newfd, const char* newname);
|
|
|
|
extern int scanf(const char* restrict format, ...);
|
|
|
|
extern int setvbuf(FILE* restrict stream, char* restrict buf, int type, size_t size);
|
|
|
|
extern int sscanf(const char* restrict s, const char* restrict format, ...);
|
|
|
|
extern int ungetc(int c, FILE* stream);
|
|
|
|
extern int vdprintf(int fildes, const char* restrict format, va_list ap);
|
|
|
|
extern int vfscanf(FILE* restrict stream, const char* restrict format, va_list arg);
|
|
|
|
extern int vscanf(const char* restrict format, va_list arg);
|
|
|
|
extern int vsscanf(const char* restrict s, const char* restrict format, va_list arg);
|
|
|
|
extern void flockfile(FILE* file);
|
|
|
|
extern void funlockfile(FILE* file);
|
|
|
|
extern void setbuf(FILE* restrict stream, char* restrict buf);
|
|
|
|
|
|
|
|
#if __POSIX_OBSOLETE <= 200801
|
|
|
|
extern char* tmpnam(char* s);
|
|
|
|
extern char* tempnam(const char* dir, const char* pfx);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2012-02-11 12:50:12 -05:00
|
|
|
#if defined(_SORTIX_SOURCE)
|
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-23 22:08:10 -05:00
|
|
|
void fregister(FILE* fp);
|
|
|
|
void funregister(FILE* fp);
|
|
|
|
FILE* fnewfile(void);
|
|
|
|
int fcloseall(void);
|
|
|
|
#endif
|
|
|
|
|
2012-02-12 19:07:02 -05:00
|
|
|
#if __SORTIX_STDLIB_REDIRECTS
|
|
|
|
inline char* gets(void) { return sortix_gets(); }
|
|
|
|
#else
|
|
|
|
/* traditional gets(3) is no longer POSIX, hence removed. */
|
|
|
|
#endif
|
|
|
|
|
2011-08-05 08:25:00 -04:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif
|