5 * Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the
11 * "Software"), to deal in the Software without restriction, including
12 * without limitation the rights to use, copy, modify, merge, publish,
13 * distribute, and/or sell copies of the Software, and to permit persons
14 * to whom the Software is furnished to do so, provided that the above
15 * copyright notice(s) and this permission notice appear in all copies of
16 * the Software and that both the above copyright notice(s) and this
17 * permission notice appear in supporting documentation.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
22 * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
24 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
25 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
26 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
27 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
29 * Except as contained in this notice, the name of a copyright holder
30 * shall not be used in advertising or otherwise to promote the sale, use
31 * or other dealings in this Software without prior written authorization
32 * of the copyright holder.
35 #pragma ident "%Z%%M% %I% %E% SMI"
38 * The following object encapsulates a buffer designed to be used to
39 * store pathnames. The pathname member of the object is initially
40 * allocated with the size that _pu_pathname_dim() returns, and then
41 * if this turns out to be pessimistic, the pathname can be reallocated
42 * via calls to pb_append_to_path() and/or pb_resize_path().
45 char *name
; /* The path buffer */
46 size_t dim
; /* The current allocated size of buffer[] */
49 PathName
*_new_PathName(void);
50 PathName
*_del_PathName(PathName
*path
);
52 char *_pn_clear_path(PathName
*path
);
53 char *_pn_append_to_path(PathName
*path
, const char *string
, int slen
,
55 char *_pn_prepend_to_path(PathName
*path
, const char *string
, int slen
,
57 char *_pn_resize_path(PathName
*path
, size_t length
);
60 * Search backwards for the potential start of a filename. This
61 * looks backwards from the specified index in a given string,
62 * stopping at the first unescaped space or the start of the line.
64 char *_pu_start_of_path(const char *string
, int back_from
);
67 * Find the end of a potential filename, starting from a given index
68 * in the string. This looks forwards from the specified index in a
69 * given string, stopping at the first unescaped space or the end
72 char *_pu_end_of_path(const char *string
, int start_from
);
76 * Return an estimate of the the length of the longest pathname
77 * on the local system.
79 size_t _pu_pathname_dim(void);
82 * Return non-zero if the specified path name refers to a directory.
84 int _pu_path_is_dir(const char *pathname
);
87 * Return non-zero if the specified path name refers to a regular file.
89 int _pu_path_is_file(const char *pathname
);
92 * Return non-zero if the specified path name refers to an executable.
94 int _pu_path_is_exe(const char *pathname
);
97 * Return non-zero if a file exists with the specified pathname.
99 int _pu_file_exists(const char *pathname
);
102 * If neither the POSIX PATH_MAX macro nor the pathconf() function
103 * can be used to find out the maximum pathlength on the target
104 * system, the following fallback maximum length is used.
106 #define MAX_PATHLEN_FALLBACK 1024
109 * If the pathname buffer turns out to be too small, it will be extended
110 * in chunks of the following amount (plus whatever is needed at the time).
112 #define PN_PATHNAME_INC 100
115 * Define the special character-sequences of the filesystem.
117 #define FS_ROOT_DIR "/" /* The root directory */
118 #define FS_ROOT_DIR_LEN (sizeof(FS_ROOT_DIR) - 1)
119 #define FS_PWD "." /* The current working directory */
120 #define FS_PWD_LEN (sizeof(FS_PWD_LEN) - 1)
121 #define FS_DIR_SEP "/" /* The directory separator string */
122 #define FS_DIR_SEP_LEN (sizeof(FS_DIR_SEP) - 1)