1N/A/* dirname.c -- return all but the last element in a file name 1N/A Copyright (C) 1990, 1998, 2000-2001, 2003-2006, 2009-2010 Free Software 1N/A This program is free software: you can redistribute it and/or modify 1N/A it under the terms of the GNU General Public License as published by 1N/A the Free Software Foundation; either version 3 of the License, or 1N/A (at your option) any later version. 1N/A This program is distributed in the hope that it will be useful, 1N/A but WITHOUT ANY WARRANTY; without even the implied warranty of 1N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1N/A GNU General Public License for more details. 1N/A You should have received a copy of the GNU General Public License 1N/A/* Return the length of the prefix of FILE that will be used by 1N/A dir_name. If FILE is in the working directory, this returns zero 1N/A even though `dir_name (FILE)' will return ".". Works properly even 1N/A if there are trailing slashes (by effectively ignoring them). */ 1N/A /* Advance prefix_length beyond important leading slashes. */ 1N/A /* Strip the basename and any redundant slashes before it. */ 1N/A/* In general, we can't use the builtin `dirname' function if available, 1N/A since it has different meanings in different environments. 1N/A In some environments the builtin `dirname' modifies its argument. 1N/A Return the leading directories part of FILE, allocated with malloc. 1N/A Works properly even if there are trailing slashes (by effectively 1N/A ignoring them). Return NULL on failure. 1N/A If lstat (FILE) would succeed, then { chdir (dir_name (FILE)); 1N/A lstat (base_name (FILE)); } will access the same file. Likewise, 1N/A if the sequence { chdir (dir_name (FILE)); 1N/A rename (base_name (FILE), "foo"); } succeeds, you have renamed FILE 1N/A to "foo" in the same directory FILE was in. */