Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
stream.c File Reference
#include "unarr-imp.h"
+ Include dependency graph for stream.c:

Go to the source code of this file.

Data Structures

struct  MemoryStream
 

Functions

ar_streamar_open_stream (void *data, ar_stream_close_fn close, ar_stream_read_fn read, ar_stream_seek_fn seek, ar_stream_tell_fn tell)
 
void ar_close (ar_stream *stream)
 
size_t ar_read (ar_stream *stream, void *buffer, size_t count)
 
bool ar_seek (ar_stream *stream, off64_t offset, int origin)
 
bool ar_skip (ar_stream *stream, off64_t count)
 
off64_t ar_tell (ar_stream *stream)
 
static void file_close (void *data)
 
static size_t file_read (void *data, void *buffer, size_t count)
 
static bool file_seek (void *data, off64_t offset, int origin)
 
static off64_t file_tell (void *data)
 
ar_streamar_open_file (const char *path)
 
static void memory_close (void *data)
 
static size_t memory_read (void *data, void *buffer, size_t count)
 
static bool memory_seek (void *data, off64_t offset, int origin)
 
static off64_t memory_tell (void *data)
 
ar_streamar_open_memory (const void *data, size_t datalen)
 

Function Documentation

void ar_close ( ar_stream stream)

Definition at line 21 of file stream.c.

22 {
23  if (stream)
24  stream->close(stream->data);
25  free(stream);
26 }

+ Here is the caller graph for this function:

ar_stream* ar_open_file ( const char *  path)

Definition at line 86 of file stream.c.

87 {
88  FILE *f = path ? fopen(path, "rb") : NULL;
89  if (!f)
90  return NULL;
92 }

+ Here is the caller graph for this function:

ar_stream* ar_open_memory ( const void *  data,
size_t  datalen 
)

Definition at line 147 of file stream.c.

148 {
149  struct MemoryStream *stm = malloc(sizeof(struct MemoryStream));
150  if (!stm)
151  return NULL;
152  stm->data = data;
153  stm->length = datalen;
154  stm->offset = 0;
156 }
ar_stream* ar_open_stream ( void *  data,
ar_stream_close_fn  close,
ar_stream_read_fn  read,
ar_stream_seek_fn  seek,
ar_stream_tell_fn  tell 
)

Definition at line 6 of file stream.c.

7 {
8  ar_stream *stream = malloc(sizeof(ar_stream));
9  if (!stream) {
10  close(data);
11  return NULL;
12  }
13  stream->data = data;
14  stream->close = close;
15  stream->read = read;
16  stream->seek = seek;
17  stream->tell = tell;
18  return stream;
19 }

+ Here is the caller graph for this function:

size_t ar_read ( ar_stream stream,
void *  buffer,
size_t  count 
)

Definition at line 28 of file stream.c.

29 {
30  return stream->read(stream->data, buffer, count);
31 }

+ Here is the caller graph for this function:

bool ar_seek ( ar_stream stream,
off64_t  offset,
int  origin 
)

Definition at line 33 of file stream.c.

34 {
35  return stream->seek(stream->data, offset, origin);
36 }

+ Here is the caller graph for this function:

bool ar_skip ( ar_stream stream,
off64_t  count 
)

Definition at line 38 of file stream.c.

39 {
40  return stream->seek(stream->data, count, SEEK_CUR);
41 }

+ Here is the caller graph for this function:

off64_t ar_tell ( ar_stream stream)

Definition at line 43 of file stream.c.

44 {
45  return stream->tell(stream->data);
46 }

+ Here is the caller graph for this function:

static void file_close ( void *  data)
static

Definition at line 50 of file stream.c.

51 {
52  fclose(data);
53 }

+ Here is the caller graph for this function:

static size_t file_read ( void *  data,
void *  buffer,
size_t  count 
)
static

Definition at line 55 of file stream.c.

56 {
57  return fread(buffer, 1, count, data);
58 }

+ Here is the caller graph for this function:

static bool file_seek ( void *  data,
off64_t  offset,
int  origin 
)
static

Definition at line 60 of file stream.c.

61 {
62 #ifdef _MSC_VER
63  return _fseeki64(data, offset, origin) == 0;
64 #else
65 #if _POSIX_C_SOURCE >= 200112L
66  if (sizeof(off_t) == 8)
67  return fseeko(data, offset, origin) == 0;
68 #endif
69  if (offset > INT32_MAX || offset < INT32_MIN)
70  return false;
71  return fseek(data, (long)offset, origin) == 0;
72 #endif
73 }

+ Here is the caller graph for this function:

static off64_t file_tell ( void *  data)
static

Definition at line 75 of file stream.c.

76 {
77 #ifdef _MSC_VER
78  return _ftelli64(data);
79 #elif _POSIX_C_SOURCE >= 200112L
80  return ftello(data);
81 #else
82  return ftell(data);
83 #endif
84 }

+ Here is the caller graph for this function:

static void memory_close ( void *  data)
static

Definition at line 112 of file stream.c.

113 {
114  struct MemoryStream *stm = data;
115  free(stm);
116 }

+ Here is the caller graph for this function:

static size_t memory_read ( void *  data,
void *  buffer,
size_t  count 
)
static

Definition at line 118 of file stream.c.

119 {
120  struct MemoryStream *stm = data;
121  if (count > stm->length - stm->offset)
122  count = stm->length - stm->offset;
123  memcpy(buffer, stm->data + stm->offset, count);
124  stm->offset += count;
125  return count;
126 }

+ Here is the caller graph for this function:

static bool memory_seek ( void *  data,
off64_t  offset,
int  origin 
)
static

Definition at line 128 of file stream.c.

129 {
130  struct MemoryStream *stm = data;
131  if (origin == SEEK_CUR)
132  offset += stm->offset;
133  else if (origin == SEEK_END)
134  offset += stm->length;
135  if (offset < 0 || offset > (off64_t)stm->length || (size_t)offset > stm->length)
136  return false;
137  stm->offset = (size_t)offset;
138  return true;
139 }

+ Here is the caller graph for this function:

static off64_t memory_tell ( void *  data)
static

Definition at line 141 of file stream.c.

142 {
143  struct MemoryStream *stm = data;
144  return stm->offset;
145 }

+ Here is the caller graph for this function: