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