/*
** Copyright (C) 2002 TTTech Computertechnik AG. All rights reserved
** Schönbrunnerstraße 7, A--1040 Wien, Austria. office@tttech.com
**
**
**++
** Name
** ALF
**
** Purpose
** Abstract large file
**
** Revision Dates
** 23-Jan-2002 (CT) Creation
** 24-Jan-2002 (CT) Renamed from AFT to ALF
** 27-Feb-2002 (SM) Pretty much complete rewrite
** ««revision-date»»···
**--
**
*/
/*
ALF - abstract large files
The intent of this package is to create something that behaves like a
large file even on systems that don't support POSIX large files. To the
greatest extent possible, this just mimics the interface provided to work
with stdio's FILE object.
Author: Skip Montanaro (skip@pobox.com)
Date: 2002-01-25
*/
/* $Id: alf.h,v 1.3 2002/04/25 21:07:15 montanaro Exp $ */
/* $Source: /cvsroot/largefiles/alf/src/alf.h,v $ */
#ifndef _ALF_H_
#define _ALF_H_
#if defined(_WIN32) && !defined(MS_WIN32)
#define MS_WIN32
#endif
#ifdef MS_WIN32
#define LONG_LONG __int64
#else
#define LONG_LONG long long
#endif
#include <sys/types.h>
#ifdef MS_WIN32
#include <windows.h>
#include <direct.h>
#else
#include <dirent.h>
#endif
#include <stdio.h>
#include "common.h"
BEGIN_C_DECLS
typedef struct _ALF_chunk {
char *path;
#ifdef ALF_DEBUG
#define ALF_CHUNK_PAD_SIZE 4
LONG_LONG pad1[ALF_CHUNK_PAD_SIZE];
#endif
unsigned LONG_LONG offset;
#ifdef ALF_DEBUG
LONG_LONG pad2[ALF_CHUNK_PAD_SIZE];
#endif
} ALF_chunk;
typedef struct _ALF {
/* information provided by the user */
char *mode; /* mode the file was opened with */
char *path; /* path to the file's base dir */
/* information calculated or stored for expediency */
unsigned LONG_LONG position; /* current position in the ALF */
unsigned LONG_LONG length; /* ALF file's length */
/*@null@*/
FILE *current; /* current active file */
int _needs_flush;
#ifdef REOPEN_ON_WRITE
int _reopen_on_write; /* work around MS bug... */
#endif
/* bookkeeping stuff */
unsigned int nchunks; /* number of chunks making up ALF */
unsigned int current_chunk; /* current chunk assoc w/ current file */
/*@null@*/
ALF_chunk *chunks; /* offset info for each element file */
unsigned int eof;
unsigned int error;
} ALF;
ALF *alf_open (const char *path, const char *mode, unsigned int use_large);
/* ERRNO: fopen(3), malloc(3) */
ALF *alf_reopen (const char *path, const char *mode, unsigned int use_large,
ALF *stream);
/* ERRNO: fopen(3), malloc(3), fclose(3), fflush(3) */
int alf_close (ALF *stream);
/* ERRNO: fclose(3) */
size_t alf_read (/*@out@*/ void *ptr, size_t size, size_t nmemb, ALF *stream);
/* ERRNO: fclose(3), fflush(3) */
size_t alf_write (const void *ptr, size_t size, size_t nmemb, ALF *stream);
/* ERRNO: fclose(3), fflush(3) */
int alf_flush (ALF *stream);
/* ERRNO: fflush(3) */
int alf_seek (ALF *stream, LONG_LONG offset, int whence);
/* ERRNO: fseek(3), fclose(3), fflush(3) */
unsigned LONG_LONG alf_tell (ALF *stream);
/* ERRNO: ftell */
void alf_rewind (ALF *stream);
/* ERRNO: none */
int alf_supports_large_files (void);
int alf_putc (int c, ALF *stream);
/* ERRNO: fclose(3), fflush(3) */
int alf_puts (const char *s, ALF *stream);
/* ERRNO: fclose(3), fflush(3) */
int alf_truncate (ALF *stream, unsigned LONG_LONG length);
/* ERRNO: fclose(3), fflush(3), truncate(3) */
int alf_getc (ALF *stream);
/* ERRNO: fclose(3), fflush(3) */
char *alf_gets (char *s, int size, ALF *stream);
/* ERRNO: fclose(3), fflush(3) */
int alf_eof (ALF *stream);
int alf_error (ALF *stream);
int alf_clearerr (ALF *stream);
/* TBD */
#if 0
int alf_printf (ALF *stream, const char *format, ...);
int alf_scanf (ALF *stream, const char *format, ...);
#endif
#define LONG32_MAX 2147483647L
#define LONG32_MIN (-LONG32_MAX-1L)
#define LONG64_MAX 9223372036854775807L
#define LONG64_MIN (-LONG64_MAX-1L)
#define ULONG32_MAX 4294967295UL
#define ULONG64_MAX 18446744073709551615UL
END_C_DECLS
#endif /* _ALF_H_ */
/*
* Local Variables: ***
* c-basic-offset: 4 ***
* indent-tabs-mode: nil ***
* End: ***
*/
syntax highlighted by Code2HTML, v. 0.9.1