2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 #include "got_path_priv.h"
26 got_path_is_absolute(const char *path)
28 return path[0] == '/';
32 got_path_get_absolute(const char *relpath)
37 if (getcwd(cwd, sizeof(cwd)) == NULL)
40 if (asprintf(&abspath, "%s/%s/", cwd, relpath) == -1)
47 got_path_normalize(const char *path)
51 resolved = realpath(path, NULL);
55 if (!got_path_is_absolute(resolved)) {
56 char *abspath = got_path_get_absolute(resolved);
71 if (strlcpy(name, "/tmp/got.XXXXXXXX", sizeof(name)) >= sizeof(name))