Back to index

glibc  2.9
Functions | Variables
iofopncook.c File Reference
#include <libioP.h>
#include <stdio.h>
#include <stdlib.h>
#include <shlib-compat.h>

Go to the source code of this file.

Functions

static _IO_ssize_t _IO_cookie_read (register _IO_FILE *fp, void *buf, _IO_ssize_t size)
static _IO_ssize_t _IO_cookie_write (register _IO_FILE *fp, const void *buf, _IO_ssize_t size)
static _IO_off64_t _IO_cookie_seek (_IO_FILE *fp, _IO_off64_t offset, int dir)
static _IO_off64_t _IO_cookie_seekoff (_IO_FILE *fp, _IO_off64_t offset, int dir, int mode)
static int _IO_cookie_close (_IO_FILE *fp)
static _IO_ssize_t _IO_cookie_read (_IO_FILE *fp, void *buf, _IO_ssize_t size)
static _IO_ssize_t _IO_cookie_write (_IO_FILE *fp, const void *buf, _IO_ssize_t size)
void _IO_cookie_init (struct _IO_cookie_file *cfile, int read_write, void *cookie, _IO_cookie_io_functions_t io_functions)
_IO_FILE_IO_fopencookie (void *cookie, const char *mode, _IO_cookie_io_functions_t io_functions)
 versioned_symbol (libc, _IO_fopencookie, fopencookie, GLIBC_2_2)

Variables

static struct _IO_jump_t

Function Documentation

static int _IO_cookie_close ( _IO_FILE fp) [static]

Definition at line 95 of file iofopncook.c.

{
  struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;

  if (cfile->__io_functions.close == NULL)
    return 0;

  return cfile->__io_functions.close (cfile->__cookie);
}
void _IO_cookie_init ( struct _IO_cookie_file cfile,
int  read_write,
void *  cookie,
_IO_cookie_io_functions_t  io_functions 
)

Definition at line 146 of file iofopncook.c.

{
  INTUSE(_IO_init) (&cfile->__fp.file, 0);
  _IO_JUMPS (&cfile->__fp) = &_IO_cookie_jumps;

  cfile->__cookie = cookie;
  cfile->__io_functions = io_functions;

  INTUSE(_IO_file_init) (&cfile->__fp);

  cfile->__fp.file._IO_file_flags =
    _IO_mask_flags (&cfile->__fp.file, read_write,
                  _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);

  /* We use a negative number different from -1 for _fileno to mark that
     this special stream is not associated with a real file, but still has
     to be treated as such.  */
  cfile->__fp.file._fileno = -2;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static _IO_ssize_t _IO_cookie_read ( register _IO_FILE fp,
void *  buf,
_IO_ssize_t  size 
) [static]
static _IO_ssize_t _IO_cookie_read ( _IO_FILE fp,
void *  buf,
_IO_ssize_t  size 
) [static]

Definition at line 45 of file iofopncook.c.

{
  struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;

  if (cfile->__io_functions.read == NULL)
    return -1;

  return cfile->__io_functions.read (cfile->__cookie, buf, size);
}
static _IO_off64_t _IO_cookie_seek ( _IO_FILE fp,
_IO_off64_t  offset,
int  dir 
) [static]

Definition at line 80 of file iofopncook.c.

{
  struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;

  return ((cfile->__io_functions.seek == NULL
          || (cfile->__io_functions.seek (cfile->__cookie, &offset, dir)
              == -1)
          || offset == (_IO_off64_t) -1)
         ? _IO_pos_BAD : offset);
}
static _IO_off64_t _IO_cookie_seekoff ( _IO_FILE fp,
_IO_off64_t  offset,
int  dir,
int  mode 
) [static]

Definition at line 108 of file iofopncook.c.

{
  /* We must force the fileops code to always use seek to determine
     the position.  */
  fp->_offset = _IO_pos_BAD;
  return INTUSE(_IO_file_seekoff) (fp, offset, dir, mode);
}

Here is the call graph for this function:

static _IO_ssize_t _IO_cookie_write ( register _IO_FILE fp,
const void *  buf,
_IO_ssize_t  size 
) [static]
static _IO_ssize_t _IO_cookie_write ( _IO_FILE fp,
const void *  buf,
_IO_ssize_t  size 
) [static]

Definition at line 59 of file iofopncook.c.

{
  struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp;

  if (cfile->__io_functions.write == NULL)
    {
      fp->_flags |= _IO_ERR_SEEN;
      return 0;
    }

  _IO_ssize_t n = cfile->__io_functions.write (cfile->__cookie, buf, size);
  if (n < size)
    fp->_flags |= _IO_ERR_SEEN;

  return n;
}
_IO_FILE* _IO_fopencookie ( void *  cookie,
const char *  mode,
_IO_cookie_io_functions_t  io_functions 
)

Definition at line 169 of file iofopncook.c.

{
  int read_write;
  struct locked_FILE
  {
    struct _IO_cookie_file cfile;
#ifdef _IO_MTSAFE_IO
    _IO_lock_t lock;
#endif
  } *new_f;

  switch (*mode++)
    {
    case 'r':
      read_write = _IO_NO_WRITES;
      break;
    case 'w':
      read_write = _IO_NO_READS;
      break;
    case 'a':
      read_write = _IO_NO_READS|_IO_IS_APPENDING;
      break;
    default:
      return NULL;
  }
  if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
    read_write &= _IO_IS_APPENDING;

  new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
  if (new_f == NULL)
    return NULL;
#ifdef _IO_MTSAFE_IO
  new_f->cfile.__fp.file._lock = &new_f->lock;
#endif

  _IO_cookie_init (&new_f->cfile, read_write, cookie, io_functions);

  return (_IO_FILE *) &new_f->cfile.__fp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

versioned_symbol ( libc  ,
_IO_fopencookie  ,
fopencookie  ,
GLIBC_2_2   
)

Variable Documentation

struct _IO_jump_t [static]