Back to index

tetex-bin  3.0
Functions | Variables
mfileio.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "system.h"
#include "mfileio.h"
#include "error.h"

Go to the source code of this file.

Functions

static long=0 static void io_debug_init (void)
FILEmfopen (const char *name, const char *mode, const char *function, int line)
int mfclose (FILE *file, const char *function, int line)
static void os_error ()
void seek_absolute (FILE *file, long pos)
void seek_relative (FILE *file, long pos)
void seek_end (FILE *file)
long tell_position (FILE *file)
long file_size (FILE *file)
char * mfgets (char *buffer, unsigned long length, FILE *file)

Variables

static FILEiodebug_file = NULL

Function Documentation

long file_size ( FILE file)

Definition at line 103 of file mfileio.c.

{
  long size;
  /* Seek to end */
  seek_end (file);
  size = tell_position (file);
  rewind (file);
  return (size);
}

Here is the call graph for this function:

static long=0 static void io_debug_init ( void  ) [static]

Definition at line 34 of file mfileio.c.

{
  if (!iodebug_file) {
    iodebug_file = fopen ("fopen.log", "wb");
    fprintf (stderr, "\n*** File IO debugging started ***\n");
  }
  if (!iodebug_file) {
    fprintf (stderr, "\nError opening io log\n");
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mfclose ( FILE file,
const char *  function,
int  line 
)

Definition at line 57 of file mfileio.c.

{
  io_debug_init();
  event += 1;
  fprintf(iodebug_file, "%p %07ld [fclose] %s:%d\n", file, event,
         function, line);
  return fclose(file);
}

Here is the call graph for this function:

char* mfgets ( char *  buffer,
unsigned long  length,
FILE file 
)

Definition at line 114 of file mfileio.c.

{
  int ch = 0, i = 0;
  while (i < length-1 && (ch = fgetc (file)) >= 0 && ch != '\n' && ch != '\r')
    buffer[i++] = ch;
  buffer[i] = 0;
  if (ch < 0 && i == 0)
    return NULL;
  if (ch == '\r' && (ch = fgetc (file)) >= 0 && (ch != '\n'))
    ungetc (ch, file);
  return buffer;
}

Here is the caller graph for this function:

FILE* mfopen ( const char *  name,
const char *  mode,
const char *  function,
int  line 
)

Definition at line 47 of file mfileio.c.

{
  FILE *tmp;
  io_debug_init();
  tmp = fopen (name, mode);
  event += 1;
  fprintf(iodebug_file, "%p %07ld [fopen] %s:%d\n", tmp, event,
         function, line);
  return tmp;
}

Here is the call graph for this function:

static void os_error ( ) [static]

Definition at line 67 of file mfileio.c.

{
  ERROR ("io:  An OS command failed that should not have.\n");
}

Here is the caller graph for this function:

void seek_absolute ( FILE file,
long  pos 
)

Definition at line 72 of file mfileio.c.

{
  if (fseek(file, pos, SEEK_SET)) {
    os_error();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void seek_end ( FILE file)

Definition at line 87 of file mfileio.c.

{
  if (fseek(file, 0L, SEEK_END)) {
    os_error();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void seek_relative ( FILE file,
long  pos 
)

Definition at line 79 of file mfileio.c.

{
  if (fseek(file, pos, SEEK_CUR)) {
    os_error();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

long tell_position ( FILE file)

Definition at line 94 of file mfileio.c.

{
  long size;
  if ((size = ftell (file)) < 0) {
    os_error();
  }
  return size;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

FILE* iodebug_file = NULL [static]

Definition at line 32 of file mfileio.c.