1 /* Copyright (C) 2001-2019 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., 1305 Grant Avenue - Suite 200, Novato, 13 CA 94945, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* Miscellaneous support for platform facilities */ 18 19 #ifndef gpmisc_INCLUDED 20 # define gpmisc_INCLUDED 21 22 #include "gp.h" 23 24 /* 25 * The facilities defined in this file and implemented in gpmisc.c are 26 * generic utilities shared among multiple gp_ platform files. 27 */ 28 29 /* 30 * Get the name of the directory for temporary files, if any. Currently 31 * this checks the TMPDIR and TEMP environment variables, in that order. 32 * The return value and the setting of *ptr and *plen are as for gp_getenv. 33 */ 34 int gp_gettmpdir(char *ptr, int *plen); 35 36 /* 37 * Open a temporary file, using O_EXCL and S_IRWXU to prevent race 38 * conditions and symlink attacks. 39 */ 40 FILE *gp_fopentemp(const char *fname, const char *mode); 41 42 /* 43 * Combine a file name with a prefix. 44 * Concatenates two paths and reduce parent references and current 45 * directory references from the concatenation when possible. 46 * The trailing zero byte is being added. 47 */ 48 gp_file_name_combine_result gp_file_name_combine_generic(const char *prefix, uint plen, 49 const char *fname, uint flen, bool no_sibling, char *buffer, uint *blen); 50 51 /* 52 * Reduces parent references and current directory references when possible. 53 * The trailing zero byte is being added. 54 */ 55 gp_file_name_combine_result gp_file_name_reduce(const char *fname, uint flen, 56 char *buffer, uint *blen); 57 58 /* 59 * Answers whether a file name is absolute (starts from a root). 60 */ 61 bool gp_file_name_is_absolute(const char *fname, uint flen); 62 63 /* 64 * Returns length of all starting parent references. 65 */ 66 uint gp_file_name_parents(const char *fname, uint flen); 67 68 /* 69 * Returns length of all starting cwd references. 70 */ 71 uint gp_file_name_cwds(const char *fname, uint flen); 72 73 #endif /* gpmisc_INCLUDED */ 74