Salut à tous,

Voilà j'ai un exercice a faire et j'ai vraiment du mal a comprendre par ou commencer mais surtout comment tester mon travail.
On m'a passé un stdio.h qui date de l'époque de SUN MicroSystem :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# ifndef FILE
#define	BUFSIZ	1024
 
#define _SBFSIZ	8
extern	struct	_iobuf {
	int		_cnt; 
	unsigned char*  _ptr; 
	unsigned char*  _base; 
	int		_bufsiz; 
	short		_flag; 
	char		_file; 
} _IOB[];
 
#define _IOFBF	 0 
#define	_IOREAD	 01
#define	_IOWRT	 02
#define	_IONBF	 04 
#define	_IOMYBUF 010
#define	_IOEOF	 020
#define	_IOERR	 040
#define	_IOSTRG	 0100
#define	_IOLBF	 0200 
#define	_IORW	 0400
#define	NULL	 ((void*) 0)
#define	FILE	 struct _iobuf
#define	EOF	 (-1)
 
#define	stdin	 (&_IOB[0])
#define	stdout	 (&_IOB[1])
#define	stderr	 (&_IOB[2])
 
 
extern int _flsbuf(unsigned char c, FILE *f);
extern int _filbuf(FILE * f);
 
#ifdef lint	/* so that lint likes (void)putc(a,b) */
extern int putc();
extern int getc();
 
#else
#define	getc(p)		(--(p)->_cnt>=0? ((int)*(p)->_ptr++):_filbuf(p))
#define putc(x, p)	(--(p)->_cnt >= 0 ?\
	(int)(*(p)->_ptr++ = (unsigned char)(x)) :\
	(((p)->_flag & _IOLBF) && -(p)->_cnt < (p)->_bufsiz ?\
		((*(p)->_ptr = (unsigned char)(x)) != '\n' ?\
			(int)(*(p)->_ptr++) :\
			_flsbuf(*(unsigned char *)(p)->_ptr, p)) :\
		_flsbuf((unsigned char)(x), p)))
#endif
#define	getchar()	getc(stdin)
#define	putchar(x)	putc((x),stdout)
#define	feof(p)		(((p)->_flag&_IOEOF)!=0)
#define	ferror(p)	(((p)->_flag&_IOERR)!=0)
#define	fileno(p)	((p)->_file)
#define	clearerr(p)	(void) ((p)->_flag &= ~(_IOERR|_IOEOF))
 
 
FILE *fopen(const char *path, const char *mode);
FILE *fdopen(int fd, const char *mode);
FILE *freopen(const char *path, const char *mode, FILE *stream);
int fclose(FILE *fp);
 
FILE *popen(const char *command, const char *type);
int pclose(FILE *stream);
 
FILE *tmpfile(void);
 
int fgetc(FILE *stream);
char *fgets(char *s, int size, FILE *stream);
char *gets(char *s);
 
int fputc(int c, FILE *stream);
int fputs(const char *s, FILE *stream);
int puts(const char *s);
 
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
int sprintf(char *str, const char *format, ...);
 
void setbuf(FILE *stream, char *buf);
int setvbuf(FILE *stream, char *buf, int mode, int size);
# endif
A partir de là je doit commencer par les fonctions : _filbuf et fopen à l'heure le problème c'est que je ne sait pas comment vérifier mon travail....

Voilà mon travail pour filbuf :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
extern int _filbuf(FILE * f) {
 
	int bufsize;
 
	bufsize = (f->_flag & _IONBF) ? 1 : BUFSIZ;
	if (f->_base == NULL)     // no buffer yet
	   if ((f->_base = (char *) malloc(bufsize)) == NULL)
		   return EOF;       // can't get buffer
	f->_ptr = f->_base;
 
	f->_cnt = read(f->_file, f->_ptr, bufsize);
	if (--f->_cnt < 0) {
	   if (f->_cnt == -1)
		   f->_flag |= _IOEOF;
	   else
		   f->_flag |= _IOERR;
	   f->_cnt = 0;
	   return EOF;
	}
	return (unsigned char) *f->_ptr++;
} //_filbuf()