00001 // Copyright (C) 2006-2007 Benedikt Böhm <hollow@gentoo.org> 00002 // 00003 // This program is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU General Public License 00005 // as published by the Free Software Foundation; either version 2 00006 // of the License, or (at your option) any later version. 00007 // 00008 // This program is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00011 // GNU General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU General Public License 00014 // along with this program; if not, write to the Free Software 00015 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 00016 00017 #include "str.h" 00018 #include "strtok.h" 00019 00020 int str_path_isabs(const char *str) 00021 { 00022 int abs = 1; 00023 00024 if (str_isempty(str)) 00025 return 0; 00026 00027 if (*str != '/') 00028 return 0; 00029 00030 strtok_t _st, *st = &_st, *p; 00031 00032 if (!strtok_init_str(st, str, "/", 0)) 00033 return -1; 00034 00035 strtok_for_each(st, p) { 00036 if (str_equal(p->token, ".") || str_equal(p->token, "..") || 00037 !str_isgraph(p->token)) { 00038 abs = 0; 00039 break; 00040 } 00041 } 00042 00043 strtok_free(st); 00044 00045 return abs; 00046 }