1 /* Copyright (C) 2001-2012 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., 7 Mt. Lassen Drive - Suite A-134, San Rafael,
13 CA 94903, U.S.A., +1(415)492-9861, 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 const char gp_fmode_binary_suffix[] = "";
29
30 /* Define the file modes for binary reading or writing. */
31 #if (defined(__MINGW32__) && __MINGW32__ == 1) || (defined(__CYGWIN__) && __CYGWIN__ == 1)
32 const char gp_fmode_rb[] = "rb";
33 const char gp_fmode_wb[] = "wb";
34 #else
35 const char gp_fmode_rb[] = "r";
36 const char gp_fmode_wb[] = "w";
37 #endif
38
39 /* -------------- Helpers for gp_file_name_combine_generic ------------- */
40
gp_file_name_root(const char * fname,uint len)41 uint gp_file_name_root(const char *fname, uint len)
42 { if (len > 0 && fname[0] == '/')
43 return 1;
44 return 0;
45 }
46
gs_file_name_check_separator(const char * fname,int len,const char * item)47 uint gs_file_name_check_separator(const char *fname, int len, const char *item)
48 { if (len > 0) {
49 if (fname[0] == '/')
50 return 1;
51 } else if (len < 0) {
52 if (fname[-1] == '/')
53 return 1;
54 }
55 return 0;
56 }
57
gp_file_name_is_parent(const char * fname,uint len)58 bool gp_file_name_is_parent(const char *fname, uint len)
59 { return len == 2 && fname[0] == '.' && fname[1] == '.';
60 }
61
gp_file_name_is_current(const char * fname,uint len)62 bool gp_file_name_is_current(const char *fname, uint len)
63 { return len == 1 && fname[0] == '.';
64 }
65
gp_file_name_separator(void)66 const char *gp_file_name_separator(void)
67 { return "/";
68 }
69
gp_file_name_directory_separator(void)70 const char *gp_file_name_directory_separator(void)
71 { return "/";
72 }
73
gp_file_name_parent(void)74 const char *gp_file_name_parent(void)
75 { return "..";
76 }
77
gp_file_name_current(void)78 const char *gp_file_name_current(void)
79 { return ".";
80 }
81
gp_file_name_is_partent_allowed(void)82 bool gp_file_name_is_partent_allowed(void)
83 { return true;
84 }
85
gp_file_name_is_empty_item_meanful(void)86 bool gp_file_name_is_empty_item_meanful(void)
87 { return false;
88 }
89
90 gp_file_name_combine_result
gp_file_name_combine(const char * prefix,uint plen,const char * fname,uint flen,bool no_sibling,char * buffer,uint * blen)91 gp_file_name_combine(const char *prefix, uint plen, const char *fname, uint flen,
92 bool no_sibling, char *buffer, uint *blen)
93 {
94 return gp_file_name_combine_generic(prefix, plen,
95 fname, flen, no_sibling, buffer, blen);
96 }
97