Luna/libc/include/stdio.h

174 lines
4.7 KiB
C
Raw Normal View History

/* stdio.h: Standard input/output. */
#ifndef _STDIO_H
#define _STDIO_H
#include <bits/seek.h>
#include <stdarg.h>
#include <sys/types.h>
2023-04-16 20:00:41 +00:00
#define __need_NULL
#include <stddef.h>
typedef struct
{
int _fd;
int _err;
int _eof;
} FILE;
#define EOF -1
2023-03-19 18:19:20 +00:00
extern FILE* stdin;
extern FILE* stdout;
extern FILE* stderr;
2023-03-19 18:19:20 +00:00
#define stdin stdin
#define stdout stdout
#define stderr stderr
2023-05-20 13:36:30 +00:00
#define BUFSIZ 1024
#ifdef __cplusplus
extern "C"
{
#endif
int fflush(FILE*);
2023-03-12 10:15:45 +00:00
/* Open a file and binds a stream to it. */
FILE* fopen(const char* path, const char* mode);
/* Bind a stream to a file descriptor. */
FILE* fdopen(int fd, const char* mode);
2023-06-19 08:46:08 +00:00
/* Change the underlying file and mode of a stream. */
FILE* freopen(const char* path, const char* mode, FILE* stream);
2023-03-12 10:15:45 +00:00
/* Close a file and frees up its stream. */
int fclose(FILE* stream);
2023-03-12 16:38:35 +00:00
/* Return the file descriptor associated with a stream. */
int fileno(FILE* stream);
2023-03-12 10:15:45 +00:00
/* Read arbitrarily sized items from a stream. */
size_t fread(void* buf, size_t size, size_t nmemb, FILE* stream);
/* Write arbitrarily sized items to a stream. */
size_t fwrite(const void* buf, size_t size, size_t nmemb, FILE* stream);
/* Move the file position. Clears the end-of-file indicator on success. */
int fseek(FILE* stream, long offset, int whence);
/* Return the current file position. */
long ftell(FILE* stream);
/* Rewind the file position and clear the error and end-of-file indicators. */
void rewind(FILE* stream);
/* Save the current file position. */
int fgetpos(FILE* stream, fpos_t* pos);
/* Restore a file position. */
int fsetpos(FILE* stream, const fpos_t* pos);
2023-03-12 10:15:45 +00:00
/* Return whether the error indicator was set in stream. */
int ferror(FILE* stream);
2023-03-12 10:15:45 +00:00
/* Return whether the end-of-file indicator was set in stream. */
int feof(FILE* stream);
/* Write a character to stream. */
int fputc(int c, FILE* stream);
/* Write a character to stream. */
int putc(int c, FILE* stream);
/* Write a character to standard output. */
int putchar(int c);
/* Write a string to stream. */
int fputs(const char* str, FILE* stream);
2023-03-23 20:35:09 +00:00
/* Read a character from stream. */
int fgetc(FILE* stream);
/* Read a character from stream. */
int getc(FILE* stream);
/* Read a character from standard input. */
int getchar(void);
2023-03-23 20:35:09 +00:00
/* Read a line from stream. */
char* fgets(char* buf, size_t size, FILE* stream);
2023-05-20 13:36:30 +00:00
/* Read a line from stream and store it in a dynamically-allocated buffer. */
ssize_t getline(char** linep, size_t* n, FILE* stream);
/* Read a line from stream and store it in a dynamically-allocated buffer. */
ssize_t getdelim(char** linep, size_t* n, int delim, FILE* stream);
2023-03-12 10:15:45 +00:00
/* Clear the error and end-of-file indicators in stream. */
void clearerr(FILE* stream);
void setbuf(FILE*, char*);
/* Write formatted output to a file. */
int fprintf(FILE* stream, const char* format, ...);
/* Write formatted output to a file. */
int vfprintf(FILE* stream, const char* format, va_list ap);
/* Write formatted output into a buffer. */
int sprintf(char* buf, const char* format, ...);
/* Write up to max bytes of formatted output into a buffer. */
int snprintf(char* buf, size_t max, const char* format, ...);
/* Write formatted output into a buffer. */
int vsprintf(char* buf, const char* format, va_list ap);
/* Write up to max bytes of formatted output into a buffer. */
int vsnprintf(char* buf, size_t max, const char* format, va_list ap);
/* Write formatted output to standard output. */
int vprintf(const char* format, va_list ap);
2023-01-07 00:49:26 +00:00
/* Write formatted output to standard output. */
int printf(const char* format, ...);
/* Scan formatted input from a string. */
int vsscanf(const char* str, const char* format, va_list ap);
/* Scan formatted input from a string. */
int sscanf(const char* str, const char* format, ...);
/* Scan formatted input from a file. */
int vfscanf(FILE* stream, const char* format, va_list ap);
/* Scan formatted input from a file. */
int fscanf(FILE* stream, const char* format, ...);
/* Scan formatted input from standard input. */
int vscanf(const char* format, va_list ap);
/* Scan formatted input from standard input. */
int scanf(const char* format, ...);
2023-01-07 00:49:26 +00:00
/* Write a string followed by a newline to standard output. */
int puts(const char* s);
2023-01-13 20:08:10 +00:00
/* Write an error message to standard error. */
void perror(const char* s);
/* Remove a file from the filesystem. */
int remove(const char* path);
/* Create a unique temporary file. */
FILE* tmpfile(void);
#ifdef __cplusplus
}
#endif
#endif