~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to base/gsdsrc.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: gsdsrc.c 8250 2007-09-25 13:31:24Z giles $ */
 
14
/* $Id$ */
15
15
/* DataSource procedures */
16
16
 
17
17
#include "memory_.h"
22
22
 
23
23
/* GC descriptor */
24
24
public_st_data_source();
25
 
static 
 
25
static
26
26
ENUM_PTRS_WITH(data_source_enum_ptrs, gs_data_source_t *psrc)
27
27
{
28
28
    if (psrc->type == data_source_type_string)
29
 
        ENUM_RETURN_CONST_STRING_PTR(gs_data_source_t, data.str);
 
29
        ENUM_RETURN_CONST_STRING_PTR(gs_data_source_t, data.str);
30
30
    else if (psrc->type == data_source_type_stream)
31
 
        ENUM_RETURN_PTR(gs_data_source_t, data.strm);
 
31
        ENUM_RETURN_PTR(gs_data_source_t, data.strm);
32
32
    else                        /* bytes or floats */
33
 
        ENUM_RETURN_PTR(gs_data_source_t, data.str.data);
 
33
        ENUM_RETURN_PTR(gs_data_source_t, data.str.data);
34
34
}
35
35
ENUM_PTRS_END
36
36
static RELOC_PTRS_WITH(data_source_reloc_ptrs, gs_data_source_t *psrc)
37
37
{
38
38
    if (psrc->type == data_source_type_string)
39
 
        RELOC_CONST_STRING_PTR(gs_data_source_t, data.str);
 
39
        RELOC_CONST_STRING_PTR(gs_data_source_t, data.str);
40
40
    else if (psrc->type == data_source_type_stream)
41
 
        RELOC_PTR(gs_data_source_t, data.strm);
 
41
        RELOC_PTR(gs_data_source_t, data.strm);
42
42
    else                        /* bytes or floats */
43
 
        RELOC_PTR(gs_data_source_t, data.str.data);
 
43
        RELOC_PTR(gs_data_source_t, data.str.data);
44
44
}
45
45
RELOC_PTRS_END
46
46
 
49
49
   but CPSI implementation silently gives (bogus) data. */
50
50
int
51
51
data_source_access_string(const gs_data_source_t * psrc, ulong start,
52
 
                          uint length, byte * buf, const byte ** ptr)
 
52
                          uint length, byte * buf, const byte ** ptr)
53
53
{
54
54
    const byte *p = psrc->data.str.data + start;
55
55
 
56
56
    if (start + length <= psrc->data.str.size) {
57
 
        if (ptr)
58
 
            *ptr = p;
59
 
        else
60
 
            memcpy(buf, p, length);
 
57
        if (ptr)
 
58
            *ptr = p;
 
59
        else
 
60
            memcpy(buf, p, length);
61
61
    } else {
62
 
        if (start < psrc->data.str.size) {
63
 
            uint oklen = psrc->data.str.size - start;
64
 
            memcpy(buf, p, oklen);
65
 
            memset(buf + oklen, 0, length - oklen);
66
 
        } else {
67
 
            memset(buf, 0, length);
68
 
        }
69
 
        *ptr = buf;
 
62
        if (start < psrc->data.str.size) {
 
63
            uint oklen = psrc->data.str.size - start;
 
64
            memcpy(buf, p, oklen);
 
65
            memset(buf + oklen, 0, length - oklen);
 
66
        } else {
 
67
            memset(buf, 0, length);
 
68
        }
 
69
        *ptr = buf;
70
70
    }
71
71
    return 0;
72
72
}
74
74
/* GC procedure. */
75
75
int
76
76
data_source_access_bytes(const gs_data_source_t * psrc, ulong start,
77
 
                         uint length, byte * buf, const byte ** ptr)
 
77
                         uint length, byte * buf, const byte ** ptr)
78
78
{
79
79
    const byte *p = psrc->data.str.data + start;
80
80
 
81
81
    if (ptr)
82
 
        *ptr = p;
 
82
        *ptr = p;
83
83
    else
84
 
        memcpy(buf, p, length);
 
84
        memcpy(buf, p, length);
85
85
    return 0;
86
86
}
87
87
 
89
89
/* Returns gs_error_rangecheck if out of bounds. */
90
90
int
91
91
data_source_access_stream(const gs_data_source_t * psrc, ulong start,
92
 
                          uint length, byte * buf, const byte ** ptr)
 
92
                          uint length, byte * buf, const byte ** ptr)
93
93
{
94
94
    stream *s = psrc->data.strm;
95
95
    const byte *p;
96
96
 
97
97
    if (start >= s->position &&
98
 
        (p = start - s->position + s->cbuf) + length <=
99
 
        s->cursor.r.limit + 1
100
 
        ) {
101
 
        if (ptr)
102
 
            *ptr = p;
103
 
        else
104
 
            memcpy(buf, p, length);
 
98
        (p = start - s->position + s->cbuf) + length <=
 
99
        s->cursor.r.limit + 1
 
100
        ) {
 
101
        if (ptr)
 
102
            *ptr = p;
 
103
        else
 
104
            memcpy(buf, p, length);
105
105
    } else {
106
 
        uint nread;
107
 
        int code = sseek(s, start);
 
106
        uint nread;
 
107
        int code = sseek(s, start);
108
108
 
109
 
        if (code < 0)
110
 
            return_error(gs_error_rangecheck);
111
 
        code = sgets(s, buf, length, &nread);
112
 
        if (code < 0)
113
 
            return_error(gs_error_rangecheck);
114
 
        if (nread != length)
115
 
            return_error(gs_error_rangecheck);
116
 
        if (ptr)
117
 
            *ptr = buf;
 
109
        if (code < 0)
 
110
            return_error(gs_error_rangecheck);
 
111
        code = sgets(s, buf, length, &nread);
 
112
        if (code < 0)
 
113
            return_error(gs_error_rangecheck);
 
114
        if (nread != length)
 
115
            return_error(gs_error_rangecheck);
 
116
        if (ptr)
 
117
            *ptr = buf;
118
118
    }
119
119
    return 0;
120
120
}