Subversion Repositories HelenOS

Rev

Rev 4377 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4377 Rev 4692
Line 35... Line 35...
35
#ifndef LIBC_STDIO_H_
35
#ifndef LIBC_STDIO_H_
36
#define LIBC_STDIO_H_
36
#define LIBC_STDIO_H_
37
 
37
 
38
#include <sys/types.h>
38
#include <sys/types.h>
39
#include <stdarg.h>
39
#include <stdarg.h>
-
 
40
#include <string.h>
-
 
41
#include <adt/list.h>
40
 
42
 
41
#define EOF (-1)
43
#define EOF  (-1)
42
 
44
 
43
#include <string.h>
45
/** Default size for stream I/O buffers */
44
#include <io/stream.h>
46
#define BUFSIZ  4096
45
 
47
 
46
#define DEBUG(fmt, ...) \
48
#define DEBUG(fmt, ...) \
47
{ \
49
    { \
48
    char buf[256]; \
50
        char _buf[256]; \
49
    int n; \
-
 
50
    n = snprintf(buf, sizeof(buf), fmt, ##__VA_ARGS__); \
51
        int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \
51
    if (n > 0) \
52
        if (_n > 0) \
52
        (void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, str_size(buf)); \
53
            (void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) _buf, str_size(_buf)); \
-
 
54
    }
-
 
55
 
-
 
56
#ifndef SEEK_SET
-
 
57
    #define SEEK_SET  0
-
 
58
    #define SEEK_CUR  1
-
 
59
    #define SEEK_END  2
-
 
60
#endif
-
 
61
 
-
 
62
enum _buffer_type {
-
 
63
    /** No buffering */
-
 
64
    _IONBF,
-
 
65
    /** Line buffering */
-
 
66
    _IOLBF,
-
 
67
    /** Full buffering */
-
 
68
    _IOFBF
53
}
69
};
54
 
70
 
55
typedef struct {
71
typedef struct {
-
 
72
    /** Linked list pointer. */
-
 
73
    link_t link;
-
 
74
   
56
    /** Underlying file descriptor. */
75
    /** Underlying file descriptor. */
57
    int fd;
76
    int fd;
58
 
77
   
59
    /** Error indicator. */
78
    /** Error indicator. */
60
    int error;
79
    int error;
61
 
80
   
62
    /** End-of-file indicator. */
81
    /** End-of-file indicator. */
63
    int eof;
82
    int eof;
-
 
83
   
-
 
84
    /** Klog indicator */
-
 
85
    int klog;
-
 
86
   
-
 
87
    /** Phone to the file provider */
-
 
88
    int phone;
-
 
89
 
-
 
90
    /** Buffering type */
-
 
91
    enum _buffer_type btype;
-
 
92
    /** Buffer */
-
 
93
    uint8_t *buf;
-
 
94
    /** Buffer size */
-
 
95
    size_t buf_size;
-
 
96
    /** Buffer I/O pointer */
-
 
97
    uint8_t *buf_head;
64
} FILE;
98
} FILE;
65
 
99
 
-
 
100
extern FILE *stdin;
-
 
101
extern FILE *stdout;
66
extern FILE *stdin, *stdout, *stderr;
102
extern FILE *stderr;
-
 
103
 
-
 
104
/* Character and string input functions */
-
 
105
extern int fgetc(FILE *);
-
 
106
extern char *fgets(char *, size_t, FILE *);
67
 
107
 
68
extern int getchar(void);
108
extern int getchar(void);
-
 
109
extern char *gets(char *, size_t);
69
 
110
 
-
 
111
/* Character and string output functions */
-
 
112
extern int fputc(wchar_t, FILE *);
-
 
113
extern int fputs(const char *, FILE *);
-
 
114
 
-
 
115
extern int putchar(wchar_t);
70
extern int puts(const char *);
116
extern int puts(const char *);
71
extern int putchar(int);
-
 
72
extern int fflush(FILE *);
-
 
73
 
117
 
74
extern int printf(const char *, ...);
118
/* Formatted string output functions */
75
extern int asprintf(char **, const char *, ...);
119
extern int fprintf(FILE *, const char*, ...);
76
extern int sprintf(char *, const char *, ...);
120
extern int vfprintf(FILE *, const char *, va_list);
77
extern int snprintf(char *, size_t , const char *, ...);
-
 
78
 
121
 
-
 
122
extern int printf(const char *, ...);
79
extern int vprintf(const char *, va_list);
123
extern int vprintf(const char *, va_list);
80
extern int vsprintf(char *, const char *, va_list);
-
 
81
extern int vsnprintf(char *, size_t, const char *, va_list);
-
 
82
 
124
 
-
 
125
extern int snprintf(char *, size_t , const char *, ...);
83
extern int rename(const char *, const char *);
126
extern int asprintf(char **, const char *, ...);
-
 
127
extern int vsnprintf(char *, size_t, const char *, va_list);
84
 
128
 
-
 
129
/* File stream functions */
85
extern FILE *fopen(const char *, const char *);
130
extern FILE *fopen(const char *, const char *);
-
 
131
extern FILE *fdopen(int, const char *);
86
extern int fclose(FILE *);
132
extern int fclose(FILE *);
-
 
133
 
87
extern size_t fread(void *, size_t, size_t, FILE *);
134
extern size_t fread(void *, size_t, size_t, FILE *);
88
extern size_t fwrite(const void *, size_t, size_t, FILE *);
135
extern size_t fwrite(const void *, size_t, size_t, FILE *);
-
 
136
 
-
 
137
extern int fseek(FILE *, long, int);
-
 
138
extern void rewind(FILE *);
-
 
139
extern int ftell(FILE *);
89
extern int feof(FILE *);
140
extern int feof(FILE *);
-
 
141
 
-
 
142
extern int fflush(FILE *);
90
extern int ferror(FILE *);
143
extern int ferror(FILE *);
91
extern void clearerr(FILE *);
144
extern void clearerr(FILE *);
92
 
145
 
93
extern int fgetc(FILE *);
-
 
94
extern int fputc(int, FILE *);
-
 
95
extern int fputs(const char *, FILE *);
-
 
96
 
-
 
97
extern int fprintf(FILE *, const char *, ...);
-
 
98
extern int vfprintf(FILE *, const char *, va_list);
146
extern void setvbuf(FILE *, void *, int, size_t);
99
 
147
 
100
#define getc fgetc
-
 
101
#define putc fputc
148
/* Misc file functions */
102
 
-
 
103
extern int fseek(FILE *, long, int);
149
extern int rename(const char *, const char *);
104
 
-
 
105
#ifndef SEEK_SET
-
 
106
    #define SEEK_SET    0
-
 
107
    #define SEEK_CUR    1
-
 
108
    #define SEEK_END    2
-
 
109
#endif
-
 
110
 
150
 
111
#endif
151
#endif
112
 
152
 
113
/** @}
153
/** @}
114
 */
154
 */