Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/base/gp_getnv.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
/* Standard implementation of gp_getenv */
18
#include "stdio_.h"
19
#include "string_.h"
20
#include "gsmemory.h"
21
#include "gstypes.h"
22
#include "gp.h"
23
24
/* Import the C getenv function. */
25
extern char *getenv(const char *);
26
27
/* Get the value of an environment variable.  See gp.h for details. */
28
int
29
gp_getenv(const char *key, char *ptr, int *plen)
30
2.05M
{
31
2.05M
    const char *str = getenv(key);
32
33
2.05M
    if (str) {
34
0
        int len = strlen(str);
35
36
0
        if (len < *plen) {
37
            /* string fits */
38
0
            strcpy(ptr, str);
39
0
            *plen = len + 1;
40
0
            return 0;
41
0
        }
42
        /* string doesn't fit */
43
0
        *plen = len + 1;
44
0
        return -1;
45
0
    }
46
    /* missing key */
47
2.05M
    if (*plen > 0)
48
575k
        *ptr = 0;
49
2.05M
    *plen = 1;
50
2.05M
    return 1;
51
2.05M
}