/* truncate.c: truncate too-long components in a filename. Copyright 1993, 95 Karl Berry. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include /* Truncate any too-long components in NAME, returning the result. It's too bad this is necessary. See comments in readable.c for why. */ string kpse_truncate_filename P1C(const_string, name) { unsigned c_len = 0; /* Length of current component. */ unsigned ret_len = 0; /* Length of constructed result. */ /* Allocate enough space. */ string ret = (string) xmalloc (strlen (name) + 1); for (; *name; name++) { if (IS_DIR_SEP (*name) || IS_DEVICE_SEP (*name)) { /* At a directory delimiter, reset component length. */ c_len = 0; } else if (c_len > NAME_MAX) { /* If past the max for a component, ignore this character. */ continue; } /* Copy this character. */ ret[ret_len++] = *name; c_len++; } ret[ret_len] = 0; return ret; }