syslinux-3.08-2 sources from FC4
[bootcd.git] / syslinux / com32 / include / stdio.h
1 /*
2  * stdio.h
3  */
4
5 #ifndef _STDIO_H
6 #define _STDIO_H
7
8 #include <klibc/extern.h>
9 #include <stdarg.h>
10 #include <stddef.h>
11
12 /* This structure doesn't really exist, but it gives us something
13    to define FILE * with */
14 struct _IO_file;
15 typedef struct _IO_file FILE;
16
17 #ifndef EOF
18 # define EOF (-1)
19 #endif
20
21 #ifndef BUFSIZ
22 # define BUFSIZ 4096
23 #endif
24
25 #define SEEK_SET 0
26 #define SEEK_CUR 1
27 #define SEEK_END 2
28
29 /*
30  * Convert between a FILE * and a file descriptor.  We don't actually
31  * have any in-memory data, so we just abuse the pointer itself to
32  * hold the data.  Note, however, that for file descriptors, -1 is
33  * error and 0 is a valid value; for FILE *, NULL (0) is error and
34  * non-NULL are valid.
35  */
36 static __inline__ int fileno(FILE *__f)
37 {
38   /* This should really be intptr_t, but size_t should be the same size */
39   return (int)(size_t)__f - 1;
40 }
41
42 /* This is a macro so it can be used as initializer */
43 #define __create_file(__fd) ((FILE *)(size_t)((__fd) + 1))
44
45 #define stdin  __create_file(0)
46 #define stdout __create_file(1)
47 #define stderr __create_file(2)
48
49 __extern FILE *fopen(const char *, const char *);
50 struct dev_info;
51 __extern FILE *fopendev(const struct dev_info *, const char *);
52
53 static __inline__ FILE *fdopen(int __fd, const char *__m)
54 {
55   (void)__m; return __create_file(__fd);
56 }
57 static __inline__ int fclose(FILE *__f)
58 {
59   extern int close(int);
60   return close(fileno(__f));
61 }
62
63 __extern int fputs(const char *, FILE *);
64 __extern int puts(const char *);
65 __extern int fputc(int, FILE *);
66 #define putc(c,f)  fputc((c),(f))
67 #define putchar(c) fputc((c),stdout)
68
69 __extern int    fgetc(FILE *);
70 __extern char * fgets(char *, int, FILE *);
71 #define getc(f) fgetc(f)
72
73 __extern size_t _fread(void *, size_t, FILE *);
74 __extern size_t _fwrite(const void *, size_t, FILE *);
75
76 #ifndef __NO_FREAD_FWRITE_INLINES
77 extern __inline__ size_t
78 fread(void *__p, size_t __s, size_t __n, FILE *__f)
79 {
80   return _fread(__p, __s*__n, __f)/__s;
81 }
82
83 extern __inline__ size_t
84 fwrite(void *__p, size_t __s, size_t __n, FILE *__f)
85 {
86   return _fwrite(__p, __s*__n, __f)/__s;
87 }
88 #endif
89
90 /* No seek, but we can tell */
91 __extern long ftell(FILE *);
92
93 __extern int printf(const char *, ...);
94 __extern int vprintf(const char *, va_list);
95 __extern int fprintf(FILE *, const char *, ...);
96 __extern int vfprintf(FILE *, const char *, va_list);
97 __extern int sprintf(char *, const char *, ...);
98 __extern int vsprintf(char *, const char *, va_list);
99 __extern int snprintf(char *, size_t n, const char *, ...);
100 __extern int vsnprintf(char *, size_t n, const char *, va_list);
101
102 __extern int asprintf(char **, const char *, ...);
103 __extern int vasprintf(char **, const char *, va_list);
104
105 /* No buffering, so no flushing needed */
106 extern __inline__ int
107 fflush(FILE *__f)
108 {
109   (void)__f;
110   return 0;
111 }
112
113 __extern int sscanf(const char *, const char *, ...);
114 __extern int vsscanf(const char *, const char *, va_list);
115
116 __extern void perror(const char *);
117
118 __extern int rename(const char *, const char *);
119
120 #endif /* _STDIO_H */