Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4973 right-hear 1
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
2
#include 
3
#include 
4
#include 
5
 
6
int setvbuf(FILE *f, char *buf, int type, size_t len)
7
{
8
  int mine=0;
9
  if (!f)
10
    return -1;
11
  fflush(f);
12
  switch (type)
13
  {
14
  case _IOFBF:
15
  case _IOLBF:
16
    if (len <= 0)
17
      return -1;
18
    if (buf == 0)
19
    {
20
      buf = (char *)malloc(len);
21
      if (buf == 0)
22
	return -1;
23
      mine = 1;
24
    }
25
  case _IONBF:
26
    if (f->_base != NULL && f->_flag & _IOMYBUF)
27
      free(f->_base);
28
    f->_cnt = 0;
29
 
30
    f->_flag &= ~(_IONBF|_IOFBF|_IOLBF);
31
    f->_flag |= type;
32
    if (type != _IONBF)
33
    {
34
      if (mine)
35
	f->_flag |= _IOMYBUF;
36
      f->_ptr = f->_base = buf;
37
      f->_bufsiz = len;
38
    }
39
    else
40
    {
41
      f->_base = 0;
42
      f->_bufsiz = 0;
43
    }
44
    return 0;
45
  default:
46
    return -1;
47
  }
48
}