Subversion Repositories HelenOS

Rev

Rev 4327 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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