Back to index

glibc  2.9
Defines | Functions | Variables
fopenport.c File Reference
#include <hurd.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>

Go to the source code of this file.

Defines

#define cookie_io_functions_t   __io_functions

Functions

static ssize_t readio (void *cookie, char *buf, size_t n)
static ssize_t writeio (void *cookie, const char *buf, size_t n)
static int seekio (void *cookie, fpos_t *pos, int whence)
static int closeio (void *cookie)
FILE__fopenport (mach_port_t port, const char *mode)

Variables

static const cookie_io_functions_t funcsio

Define Documentation

#define cookie_io_functions_t   __io_functions

Definition at line 93 of file fopenport.c.


Function Documentation

FILE* __fopenport ( mach_port_t  port,
const char *  mode 
)

Definition at line 102 of file fopenport.c.

{
  int pflags;
  int needflags;
  error_t err;

  const char *m = mode;

  switch (*m++)
    {
    case 'r':
      needflags = O_READ;
      break;
    case 'w':
      needflags = O_WRITE;
      break;
    case 'a':
      needflags = O_WRITE|O_APPEND;
      break;
    default:
      return NULL;
  }
  if (m[0] == '+' || (m[0] == 'b' && m[1] == '+'))
    needflags |= O_RDWR;

  /* Verify the PORT is valid allows the access MODE specifies.  */

  if (err = __io_get_openmodes (port, &pflags))
    return __hurd_fail (err), NULL;

  /* Check the access mode.  */
  if ((pflags & needflags) != needflags)
    {
      errno = EBADF;
      return NULL;
    }

  return fopencookie ((void *) port, mode, funcsio);
}

Here is the call graph for this function:

static int closeio ( void *  cookie) [static]

Definition at line 80 of file fopenport.c.

{
  error_t error = __mach_port_deallocate (__mach_task_self (),
                                     (mach_port_t) cookie);
  if (error)
    return __hurd_fail (error);
  return 0;
}

Here is the call graph for this function:

static ssize_t readio ( void *  cookie,
char *  buf,
size_t  n 
) [static]

Definition at line 27 of file fopenport.c.

{
  mach_msg_type_number_t nread;
  error_t err;
  char *bufp = buf;

  nread = n;
  if (err = __io_read ((io_t) cookie, &bufp, &nread, -1, n))
    return __hurd_fail (err);

  if (bufp != buf)
    {
      memcpy (buf, bufp, nread);
      __vm_deallocate (__mach_task_self (),
                     (vm_address_t) bufp, (vm_size_t) nread);
    }

  return nread;
}

Here is the call graph for this function:

static int seekio ( void *  cookie,
fpos_t pos,
int  whence 
) [static]

Definition at line 65 of file fopenport.c.

{
  error_t err = __io_seek ((file_t) cookie, *pos, whence, pos);
  return err ? __hurd_fail (err) : 0;
}

Here is the call graph for this function:

static ssize_t writeio ( void *  cookie,
const char *  buf,
size_t  n 
) [static]

Definition at line 50 of file fopenport.c.

{
  mach_msg_type_number_t wrote;
  error_t err;

  if (err = __io_write ((io_t) cookie, buf, n, -1, &wrote))
    return __hurd_fail (err);

  return wrote;
}

Here is the call graph for this function:


Variable Documentation

Initial value:

Definition at line 95 of file fopenport.c.