Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/base/gp_upapr.c
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (C) 2001-2023 Artifex Software, Inc.
2
   All Rights Reserved.
3
4
   This software is provided AS-IS with no warranty, either express or
5
   implied.
6
7
   This software is distributed under license and may not be copied,
8
   modified or distributed except as expressly authorized under the terms
9
   of the license contained in the file LICENSE in this distribution.
10
11
   Refer to licensing information at http://www.artifex.com or contact
12
   Artifex Software, Inc.,  39 Mesa Street, Suite 108A, San Francisco,
13
   CA 94129, USA, for further information.
14
*/
15
16
17
/* $Id:$ */
18
/* Unix implementation of gp_defaultpapersize */
19
20
#ifdef USE_LIBPAPER
21
#include <paper.h>
22
#include <stdlib.h>
23
24
/* libpaper uses the std library's malloc() to allocate
25
   the string, but a normal "free" call below will
26
   get "hooked" if memento is in use (via malloc_.h).
27
   So workaround that...
28
*/
29
#ifdef MEMENTO
30
/* This definition *must* come before memento.h gets included
31
   (in this case, via malloc_.h) so that the free() call
32
   inside std_free() avoids the pre-processor (re)definition
33
   to Memento_free()
34
*/
35
static void std_free(void *ptr)
36
{
37
   free(ptr);
38
}
39
#else
40
#define std_free free
41
#endif
42
43
#endif
44
45
#include "string_.h"
46
#include "malloc_.h"
47
#include "gx.h"
48
#include "gp.h"
49
50
/* ------ Default paper size ------ */
51
52
/* Get the default paper size.  See gp_paper.h for details. */
53
int
54
gp_defaultpapersize(char *ptr, int *plen)
55
162k
{
56
#ifdef USE_LIBPAPER
57
    const char *paper;
58
    bool is_systempaper;
59
60
    paperinit();
61
62
    paper = systempapername();
63
    if (paper)
64
        is_systempaper =  true;
65
    else {
66
        paper = defaultpapername();
67
        is_systempaper =  false;
68
    }
69
70
    if (paper) {
71
        int rc, len = strlen(paper);
72
73
        if (len < *plen) {
74
            /* string fits */
75
            strcpy(ptr, paper);
76
            rc = 0;
77
        } else {
78
            /* string doesn't fit */
79
            rc = -1;
80
        }
81
        *plen = len + 1;
82
        paperdone();
83
        if (is_systempaper)
84
            std_free((void *)paper);
85
        return rc;
86
    }
87
#endif
88
89
    /* No default paper size */
90
91
162k
    if (*plen > 0)
92
0
        *ptr = 0;
93
162k
    *plen = 1;
94
162k
    return 1;
95
162k
}