108
113
fputc('\n', stderr);
116
/* Fatal error. Print message and exit. */
118
die(int err, const char *fmt, ...) {
122
vfprintf(stderr, fmt, args);
123
fprintf(stderr, "\n");
111
129
/* True if fstypes match. Null *TYPES means match anything,
112
130
except that swap types always return false. */
113
131
/* Accept nonfs,proc,devpts and nonfs,noproc,nodevpts
246
is_pseudo_fs(const char *type)
248
if (type == NULL || *type == '/')
250
if (streq(type, "none") ||
251
streq(type, "proc") ||
252
streq(type, "tmpfs") ||
253
streq(type, "sysfs") ||
254
streq(type, "devpts"))
227
259
/* Make a canonical pathname from PATH. Returns a freshly malloced string.
228
260
It is up the *caller* to ensure that the PATH is sensible. i.e.
229
261
canonicalize ("/dev/fd0/.") returns "/dev/fd0" even though ``/dev/fd0/.''
230
262
is not a legal pathname for ``/dev/fd0''. Anything we cannot parse
231
263
we return unmodified. */
233
canonicalize (const char *path) {
234
char canonical[PATH_MAX+2];
265
canonicalize_spec (const char *path)
236
269
if (path == NULL)
240
if (streq(path, "none") ||
241
streq(path, "proc") ||
242
streq(path, "devpts"))
271
if (is_pseudo_fs(path))
243
272
return xstrdup(path);
245
if (myrealpath (path, canonical, PATH_MAX+1))
246
return xstrdup(canonical);
248
return xstrdup(path);
274
res = canonicalize_path(path);
276
die(EX_SYSERR, _("not enough memory"));
253
* Parses NAME=value, returns -1 on parse error, 0 success. The success is also
254
* when the 'spec' doesn't contain name=value pair (because the spec could be
255
* a devname too). In particular case the pointer 'name' is set to NULL.
257
* The result is a new allocated string (the 'name' pointer).
260
parse_spec(const char *spec, char **name, char **value)
280
char *canonicalize (const char *path)
267
if (!(cp = strchr(spec, '=')))
268
return 0; /* no name= */
271
vl = tk + (cp - spec);
274
if (*vl == '"' || *vl == '\'') {
275
if (!(cp = strrchr(vl+1, *vl))) {
277
return -1; /* parse error */
282
char *res = canonicalize_path(path);
285
die(EX_SYSERR, _("not enough memory"));