Blame gnulib/lib/stripslash.c

Packit eba2e2
/* stripslash.c -- remove redundant trailing slashes from a file name
Packit eba2e2
Packit eba2e2
   Copyright (C) 1990, 2001, 2003-2006, 2009-2014 Free Software Foundation,
Packit eba2e2
   Inc.
Packit eba2e2
Packit eba2e2
   This program is free software: you can redistribute it and/or modify
Packit eba2e2
   it under the terms of the GNU General Public License as published by
Packit eba2e2
   the Free Software Foundation; either version 3 of the License, or
Packit eba2e2
   (at your option) any later version.
Packit eba2e2
Packit eba2e2
   This program is distributed in the hope that it will be useful,
Packit eba2e2
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit eba2e2
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit eba2e2
   GNU General Public License for more details.
Packit eba2e2
Packit eba2e2
   You should have received a copy of the GNU General Public License
Packit eba2e2
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit eba2e2
Packit eba2e2
#include <config.h>
Packit eba2e2
Packit eba2e2
#include "dirname.h"
Packit eba2e2
Packit eba2e2
/* Remove trailing slashes from FILE.  Return true if a trailing slash
Packit eba2e2
   was removed.  This is useful when using file name completion from a
Packit eba2e2
   shell that adds a "/" after directory names (such as tcsh and
Packit eba2e2
   bash), because on symlinks to directories, several system calls
Packit eba2e2
   have different semantics according to whether a trailing slash is
Packit eba2e2
   present.  */
Packit eba2e2
Packit eba2e2
bool
Packit eba2e2
strip_trailing_slashes (char *file)
Packit eba2e2
{
Packit eba2e2
  char *base = last_component (file);
Packit eba2e2
  char *base_lim;
Packit eba2e2
  bool had_slash;
Packit eba2e2
Packit eba2e2
  /* last_component returns "" for file system roots, but we need to turn
Packit eba2e2
     "///" into "/".  */
Packit eba2e2
  if (! *base)
Packit eba2e2
    base = file;
Packit eba2e2
  base_lim = base + base_len (base);
Packit eba2e2
  had_slash = (*base_lim != '\0');
Packit eba2e2
  *base_lim = '\0';
Packit eba2e2
  return had_slash;
Packit eba2e2
}