xref: /plan9/sys/src/cmd/gs/src/gpmisc.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 2000 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: gpmisc.h,v 1.12 2003/08/16 07:53:27 raph Exp $ */
18 /* Miscellaneous support for platform facilities */
19 
20 #ifndef gpmisc_INCLUDED
21 #  define gpmisc_INCLUDED
22 
23 /*
24  * The facilities defined in this file and implemented in gpmisc.c are
25  * generic utilities shared among multiple gp_ platform files.
26  */
27 
28 /*
29  * Get the name of the directory for temporary files, if any.  Currently
30  * this checks the TMPDIR and TEMP environment variables, in that order.
31  * The return value and the setting of *ptr and *plen are as for gp_getenv.
32  */
33 int gp_gettmpdir(char *ptr, int *plen);
34 
35 /*
36  * Open a temporary file, using O_EXCL and S_IRWXU to prevent race
37  * conditions and symlink attacks.
38  */
39 FILE *gp_fopentemp(const char *fname, const char *mode);
40 
41 /*
42  * Combine a file name with a prefix.
43  * Concatenates two paths and reduce parent references and current
44  * directory references from the concatenation when possible.
45  * The trailing zero byte is being added.
46  */
47 gp_file_name_combine_result gp_file_name_combine_generic(const char *prefix, uint plen,
48 	    const char *fname, uint flen, bool no_sibling, char *buffer, uint *blen);
49 
50 /*
51  * Reduces parent references and current directory references when possible.
52  * The trailing zero byte is being added.
53  */
54 gp_file_name_combine_result gp_file_name_reduce(const char *fname, uint flen,
55 		char *buffer, uint *blen);
56 
57 /*
58  * Answers whether a file name is absolute (starts from a root).
59  */
60 bool gp_file_name_is_absolute(const char *fname, uint flen);
61 
62 /*
63  * Returns length of all starting parent references.
64  */
65 uint gp_file_name_parents(const char *fname, uint flen);
66 
67 /*
68  * Returns length of all starting cwd references.
69  */
70 uint gp_file_name_cwds(const char *fname, uint flen);
71 
72 #endif /* gpmisc_INCLUDED */
73