File: pathutil.h

package info (click to toggle)
yuma123 2.11-1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 20,900 kB
  • sloc: ansic: 179,975; cpp: 10,968; python: 5,839; sh: 2,287; makefile: 1,021; xml: 621; exp: 592; perl: 70
file content (122 lines) | stat: -rw-r--r-- 4,467 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#ifndef pathutil_h
#define pathutil_h

/*
 * Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd.
 * 
 * All rights reserved.
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, and/or sell copies of the Software, and to permit persons
 * to whom the Software is furnished to do so, provided that the above
 * copyright notice(s) and this permission notice appear in all copies of
 * the Software and that both the above copyright notice(s) and this
 * permission notice appear in supporting documentation.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
 * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 * 
 * Except as contained in this notice, the name of a copyright holder
 * shall not be used in advertising or otherwise to promote the sale, use
 * or other dealings in this Software without prior written authorization
 * of the copyright holder.
 */

/*
 * The following object encapsulates a buffer designed to be used to
 * store pathnames. The pathname member of the object is initially
 * allocated with the size that _pu_pathname_dim() returns, and then
 * if this turns out to be pessimistic, the pathname can be reallocated
 * via calls to pb_append_to_path() and/or pb_resize_path().
 */
typedef struct {
  char *name;         /* The path buffer */
  size_t dim;         /* The current allocated size of buffer[] */
} PathName;

PathName *_new_PathName(void);
PathName *_del_PathName(PathName *path);

char *_pn_clear_path(PathName *path);
char *_pn_append_to_path(PathName *path, const char *string, int slen,
			int remove_escapes);
char *_pn_prepend_to_path(PathName *path, const char *string, int slen,
			  int remove_escapes);
char *_pn_resize_path(PathName *path, size_t length);

/*
 * Search backwards for the potential start of a filename. This
 * looks backwards from the specified index in a given string,
 * stopping at the first unescaped space or the start of the line.
 */
char *_pu_start_of_path(const char *string, int back_from);

/*
 * Find the end of a potential filename, starting from a given index
 * in the string. This looks forwards from the specified index in a
 * given string, stopping at the first unescaped space or the end
 * of the line.
 */
char *_pu_end_of_path(const char *string, int start_from);


/*
 * Return an estimate of the the length of the longest pathname
 * on the local system.
 */
size_t _pu_pathname_dim(void);

/*
 * Return non-zero if the specified path name refers to a directory.
 */
int _pu_path_is_dir(const char *pathname);

/*
 * Return non-zero if the specified path name refers to a regular file.
 */
int _pu_path_is_file(const char *pathname);

/*
 * Return non-zero if the specified path name refers to an executable.
 */
int _pu_path_is_exe(const char *pathname);

/*
 * Return non-zero if a file exists with the specified pathname.
 */
int _pu_file_exists(const char *pathname);

/*
 * If neither the POSIX PATH_MAX macro nor the pathconf() function
 * can be used to find out the maximum pathlength on the target
 * system, the following fallback maximum length is used.
 */
#define MAX_PATHLEN_FALLBACK 1024

/*
 * If the pathname buffer turns out to be too small, it will be extended
 * in chunks of the following amount (plus whatever is needed at the time).
 */
#define PN_PATHNAME_INC 100

/*
 * Define the special character-sequences of the filesystem.
 */
#define FS_ROOT_DIR "/"     /* The root directory */
#define FS_ROOT_DIR_LEN (sizeof(FS_ROOT_DIR) - 1)
#define FS_PWD "."          /* The current working directory */
#define FS_PWD_LEN (sizeof(FS_PWD_LEN) - 1)
#define FS_DIR_SEP "/"      /* The directory separator string */
#define FS_DIR_SEP_LEN (sizeof(FS_DIR_SEP) - 1)

#endif