Coverage Report

Created: 2025-06-24 07:01

/src/ghostpdl/base/gp_unifn.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
/* Unix-like file name syntax platform routines for Ghostscript */
18
#include "gx.h"
19
#include "gp.h"
20
#include "gpmisc.h"
21
#include "gsutil.h"
22
23
/* Define the character used for separating file names in a list. */
24
const char gp_file_name_list_separator = ':';
25
26
/* Define the string to be concatenated with the file mode */
27
/* for opening files without end-of-line conversion. */
28
#if (defined(__MINGW32__) && __MINGW32__ == 1) || (defined(__CYGWIN__) && __CYGWIN__ == 1)
29
const char* gp_fmode_binary_suffix = "b";
30
#else
31
const char* gp_fmode_binary_suffix = "";
32
#endif
33
34
35
/* Define the file modes for binary reading or writing. */
36
#if (defined(__MINGW32__) && __MINGW32__ == 1) || (defined(__CYGWIN__) && __CYGWIN__ == 1)
37
const char gp_fmode_rb[] = "rb";
38
const char gp_fmode_wb[] = "wb";
39
#else
40
const char gp_fmode_rb[] = "r";
41
const char gp_fmode_wb[] = "w";
42
#endif
43
44
/* -------------- Helpers for gp_file_name_combine_generic ------------- */
45
46
uint gp_file_name_root(const char *fname, uint len)
47
581M
{   if (len > 0 && fname[0] == '/')
48
297M
        return 1;
49
283M
    return 0;
50
581M
}
51
52
uint gs_file_name_check_separator(const char *fname, int len, const char *item)
53
43.5G
{   if (len > 0) {
54
43.5G
        if (fname[0] == '/')
55
9.38G
            return 1;
56
43.5G
    } else if (len < 0) {
57
61.8M
        if (fname[-1] == '/')
58
23.1k
            return 1;
59
61.8M
    }
60
34.2G
    return 0;
61
43.5G
}
62
63
bool gp_file_name_is_parent(const char *fname, uint len)
64
1.48G
{   return len == 2 && fname[0] == '.' && fname[1] == '.';
65
1.48G
}
66
67
bool gp_file_name_is_current(const char *fname, uint len)
68
1.46G
{   return len == 1 && fname[0] == '.';
69
1.46G
}
70
71
const char *gp_file_name_separator(void)
72
116M
{   return "/";
73
116M
}
74
75
const char *gp_file_name_directory_separator(void)
76
39.7M
{   return "/";
77
39.7M
}
78
79
const char *gp_file_name_parent(void)
80
0
{   return "..";
81
0
}
82
83
const char *gp_file_name_current(void)
84
75.0M
{   return ".";
85
75.0M
}
86
87
bool gp_file_name_is_parent_allowed(void)
88
15
{   return true;
89
15
}
90
91
bool gp_file_name_is_empty_item_meanful(void)
92
198k
{   return false;
93
198k
}
94
95
gp_file_name_combine_result
96
gp_file_name_combine(const char *prefix, uint plen, const char *fname, uint flen,
97
                    bool no_sibling, char *buffer, uint *blen)
98
226M
{
99
226M
    return gp_file_name_combine_generic(prefix, plen,
100
226M
            fname, flen, no_sibling, buffer, blen);
101
226M
}
102
103
bool
104
gp_file_name_good_char(unsigned char c)
105
270
{
106
270
  return c != 0 && c != '/' && c != '\\' && c != ':';
107
270
}