Implement is_absolute_path() helper function

This commit is contained in:
Ramiro Polla 2010-07-15 15:05:22 -03:00 committed by Joel Rosdahl
parent d325739040
commit 82b7876473
3 changed files with 11 additions and 1 deletions

View File

@ -107,6 +107,7 @@ const char *get_home_directory(void);
char *get_cwd();
size_t common_dir_prefix_length(const char *s1, const char *s2);
char *get_relative_path(const char *from, const char *to);
int is_absolute_path(const char *path);
void update_mtime(const char *path);
void *x_fmmap(const char *fname, off_t *size, const char *errstr);
int x_munmap(void *addr, size_t length);

View File

@ -90,7 +90,7 @@ char *find_executable(const char *name, const char *exclude_name)
{
char *path;
if (*name == '/') {
if (is_absolute_path(name)) {
return x_strdup(name);
}

9
util.c
View File

@ -938,6 +938,15 @@ char *get_relative_path(const char *from, const char *to)
return result;
}
/*
* Return whether path is absolute.
*/
int
is_absolute_path(const char *path)
{
return path[0] == '/';
}
/*
* Update the modification time of a file in the cache to save it from LRU
* cleanup.