annotate lib/stripslash.c @ 276:23034db7dd8a 2.5

fixed expression 'slots' to not store null on a pass 1 store
author lost
date Mon, 31 Aug 2009 08:39:36 +0000
parents d5392bb5da3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
272
d5392bb5da3c Added generated files
lost
parents:
diff changeset
1 /* stripslash.c -- remove redundant trailing slashes from a file name
d5392bb5da3c Added generated files
lost
parents:
diff changeset
2
d5392bb5da3c Added generated files
lost
parents:
diff changeset
3 Copyright (C) 1990, 2001, 2003-2006 Free Software Foundation, Inc.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
4
d5392bb5da3c Added generated files
lost
parents:
diff changeset
5 This program is free software: you can redistribute it and/or modify
d5392bb5da3c Added generated files
lost
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
d5392bb5da3c Added generated files
lost
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
d5392bb5da3c Added generated files
lost
parents:
diff changeset
8 (at your option) any later version.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
9
d5392bb5da3c Added generated files
lost
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
d5392bb5da3c Added generated files
lost
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
d5392bb5da3c Added generated files
lost
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d5392bb5da3c Added generated files
lost
parents:
diff changeset
13 GNU General Public License for more details.
d5392bb5da3c Added generated files
lost
parents:
diff changeset
14
d5392bb5da3c Added generated files
lost
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
d5392bb5da3c Added generated files
lost
parents:
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
17
d5392bb5da3c Added generated files
lost
parents:
diff changeset
18 #include <config.h>
d5392bb5da3c Added generated files
lost
parents:
diff changeset
19
d5392bb5da3c Added generated files
lost
parents:
diff changeset
20 #include "dirname.h"
d5392bb5da3c Added generated files
lost
parents:
diff changeset
21
d5392bb5da3c Added generated files
lost
parents:
diff changeset
22 /* Remove trailing slashes from FILE. Return true if a trailing slash
d5392bb5da3c Added generated files
lost
parents:
diff changeset
23 was removed. This is useful when using file name completion from a
d5392bb5da3c Added generated files
lost
parents:
diff changeset
24 shell that adds a "/" after directory names (such as tcsh and
d5392bb5da3c Added generated files
lost
parents:
diff changeset
25 bash), because on symlinks to directories, several system calls
d5392bb5da3c Added generated files
lost
parents:
diff changeset
26 have different semantics according to whether a trailing slash is
d5392bb5da3c Added generated files
lost
parents:
diff changeset
27 present. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
28
d5392bb5da3c Added generated files
lost
parents:
diff changeset
29 bool
d5392bb5da3c Added generated files
lost
parents:
diff changeset
30 strip_trailing_slashes (char *file)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
31 {
d5392bb5da3c Added generated files
lost
parents:
diff changeset
32 char *base = last_component (file);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
33 char *base_lim;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
34 bool had_slash;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
35
d5392bb5da3c Added generated files
lost
parents:
diff changeset
36 /* last_component returns "" for file system roots, but we need to turn
d5392bb5da3c Added generated files
lost
parents:
diff changeset
37 `///' into `/'. */
d5392bb5da3c Added generated files
lost
parents:
diff changeset
38 if (! *base)
d5392bb5da3c Added generated files
lost
parents:
diff changeset
39 base = file;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
40 base_lim = base + base_len (base);
d5392bb5da3c Added generated files
lost
parents:
diff changeset
41 had_slash = (*base_lim != '\0');
d5392bb5da3c Added generated files
lost
parents:
diff changeset
42 *base_lim = '\0';
d5392bb5da3c Added generated files
lost
parents:
diff changeset
43 return had_slash;
d5392bb5da3c Added generated files
lost
parents:
diff changeset
44 }