Back to index

glibc  2.9
Defines | Functions
open.c File Reference
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
#include <bits/stdio_lim.h>
#include <unistd.h>
#include "filedesc.h"

Go to the source code of this file.

Defines

#define __DECLARE_FILE_DESCRIPTORS__

Functions

int __open (char *file, int oflag) const
 libc_hidden_def (__open)

Define Documentation

Definition at line 30 of file open.c.


Function Documentation

int __open ( char *  file,
int  oflag 
) const

Definition at line 37 of file open.c.

{
  int mode;
  int newfd;
  int index;

  if (file == NULL)
    {
      __set_errno (EINVAL);
      return -1;
    }

  if (oflag & O_CREAT)
    {
      va_list arg;
      va_start(arg, oflag);
      mode = va_arg(arg, int);
      va_end(arg);
    }

  /*
   *  Find an open slot.
   */

  newfd = -1;

  for ( index=0 ; index< FOPEN_MAX ; index++ )
    if ( !__FD_Table[ index ].in_use ) {
      newfd = index;
      break;
    }

  if ( newfd == -1 ) {
    __set_errno (ENFILE);
    return -1;
  }

  /*
   *  Initialize the open slot
   */

  __FD_Table[ newfd ].in_use = 1;
  __FD_Table[ newfd ].flags = oflag;

  return newfd;
}

Here is the call graph for this function:

Definition at line 85 of file open.c.

{
  int index;

  for ( index=0 ; index< FOPEN_MAX ; index++ )
    __FD_Table[ index ].in_use = 0;

  stdin = fopen( "", "r" );

  stdout = fopen( "", "w" );

  stderr = fopen( "", "w" );

  /*
   *  Line buffer the standard input and output and use no buffering for
   *  standard error.
   */

  setvbuf( stdin,  NULL, _IOLBF, BUFSIZ );
  setvbuf( stdout, NULL, _IOLBF, BUFSIZ );
  setvbuf( stderr, NULL, _IONBF, BUFSIZ );

  (void) &__NONE_init_console_io;  /* Avoid "defined but not used" warning. */
}

Here is the call graph for this function: