/*
 * stdio.h
 *
 * Copyright (C) 2017 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _STDIO_H_
#define _STDIO_H_

#include <stdlib.h>
#include <stdarg.h>

#define EOF -1

#define getc(s) fgetc(s)
#define getchar() fgetc(stdin)
#define putc(c, s) fputc(c, s)
#define putchar(c) fputc(c, stdout)

#define getc_unlocked(s) fgetc_unlocked(s)
#define getchar_unlocked() fgetc_unlocked(stdin)
#define putc_unlocked(c, s) fputc_unlocked(c, s)
#define putchar_unlocked(c) fputc(c, stdout)

struct __crt_file;
typedef struct __crt_file FILE;

extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;

int fgetc(FILE *stream);
int fputc(int c, FILE *stream);
char *fgets(char *s, int size, FILE *stream);
int fputs(const char *s, FILE *stream);
int ungetc(int c, FILE *stream);
char *gets(char *s);
int puts(const char *s);

int fgetc_unlocked(FILE *stream);
int fputc_unlocked(int c, FILE *stream);
char *fgets_unlocked(char *s, int size, FILE *stream);
int fputs_unlocked(const char *s, FILE *stream);

FILE *fopen(const char *pathname, const char *mode);
FILE *fdopen(int fd, const char *mode);
FILE *fmemopen(void *buf, size_t size, const char *mode);
int fclose(FILE *stream);

#define BUFSIZ 4096
#define _IOFBF 0
#define _IOLBF 1
#define _IONBF 2

int setvbuf(FILE *stream, char *buf, int mode, size_t size);
void setbuf(FILE *stream, char *buf);
void setbuffer(FILE *stream, char *buf, size_t size);
void setlinebuf(FILE *stream);

int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int dprintf(int fd, const char *format, ...);
int sprintf(char *str, const char *format, ...);
int snprintf(char *str, size_t size, const char *format, ...);
int vprintf(const char *format, va_list ap);
int vfprintf(FILE *stream, const char *format, va_list ap);
int vdprintf(int fd, const char *format, va_list ap);
int vsprintf(char *str, const char *format, va_list ap);
int vsnprintf(char *str, size_t size, const char *format, va_list ap);


#endif
