// Copyright (c) 2025, Zak Fenton // Zak Fenton's libc is licensed under the Mulan PSL v2. You can use this // software according to the terms and conditions of the Mulan PSL v2. // You may obtain a copy of Mulan PSL v2 at: // http://license.coscl.org.cn/MulanPSL2 // THIS SOFTWARE IS PROVIDED ON AN “AS IS” BASIS, WITHOUT warranties of // any kind, either express or implied, including but not limited to // non-infringement, merchantability or fit for a particular purpose. // See the Mulan PSL v2 for more details. #ifndef _LIBC_STDIO_H #define _LIBC_STDIO_H #include #include #ifdef LIBC_OOP // Theoretical OOP version of FILE, this would be ideal for C+OOP apps // This is split into FILE (base class for interoperable stream objects) // and _libc_FILE (the default FILE implementation using system file // descriptors) // Class hierarchy doesn't exist yet... //#import @interface Resource { } @end /* The extensible FILE base type. */ @interface FILE : Resource { FILE* backend; } -(id) init; @end /* The subclass of FILE which works over an OS file descriptor. */ @interface _libc_FILE : FILE { int fd; int ungot; // Character pushed back or -1 int eof; } @end #else // Simplified data structure, only intended for bootstrapping (does not // provide complex buffering or overloading) struct _libc_FILE_internals { int fd; int ungot; // Character pushed back or -1 int eof; }; typedef struct _libc_FILE_internals FILE; #endif #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 extern FILE* stderr; extern FILE* stdin; extern FILE* stdout; #define EOF ((int)-1) #ifdef _ZCC #define _LIBC_PRINTF_CALLCONV __classic_call #else #define _LIBC_PRINTF_CALLCONV #endif int _LIBC_PRINTF_CALLCONV printf(const char* fmt, ...); int _LIBC_PRINTF_CALLCONV sprintf(char *buf, const char* fmt, ...); int _LIBC_PRINTF_CALLCONV snprintf(char *buf, size_t n, const char* fmt, ...); int _LIBC_PRINTF_CALLCONV dprintf(int fd, const char* fmt, ...); int _LIBC_PRINTF_CALLCONV fprintf(FILE* f, const char* fmt, ...); int _LIBC_PRINTF_CALLCONV vfprintf(FILE* f, const char* fmt, va_list list); int _LIBC_PRINTF_CALLCONV vsnprintf(char* str, size_t n, const char* fmt, va_list list); // These are non-standard, but the other *printf functions need to be implemented somehow, // so fnprintf/vfnprintf just use a callback function for output of n bytes of string output. typedef int(*_libc_fnprintf_fn_t)(const char* str, int n, void* udata); int _LIBC_PRINTF_CALLCONV _libc_fnprintf(_libc_fnprintf_fn_t fn, void* udata, const char* fmt, ...); int _LIBC_PRINTF_CALLCONV _libc_vfnprintf(_libc_fnprintf_fn_t fn, void* udata, const char* fmt, va_list list); FILE* fopen(const char* name, const char* mode); FILE* freopen(const char* name, const char* mode, FILE* f); int fclose(FILE* f); int fflush(FILE* f); long fread(void* buffer, long size, long count, FILE* f); long fwrite(void* buffer, long size, long count, FILE* f); char* fgets(char*, int, FILE*); int fputs(const char*, FILE*); int fputc(int, FILE*); int feof(FILE* f); void perror(const char*); int putc(int c, FILE* f); int putchar(int c); int getc(FILE* f); int ungetc(int c, FILE* f); int fseek(FILE* f, long offset, int wh); #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 long ftell(FILE* f); long getline(char** linevar, long *nvar, FILE* f); /* From ifndef at top of file: */ #endif