From patchwork Mon Mar 14 17:13:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kai Tietz X-Patchwork-Id: 86778 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 2805FB6F12 for ; Tue, 15 Mar 2011 04:13:53 +1100 (EST) Received: (qmail 5066 invoked by alias); 14 Mar 2011 17:13:51 -0000 Received: (qmail 5056 invoked by uid 22791); 14 Mar 2011 17:13:49 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, RFC_ABUSE_POST, TW_CP X-Spam-Check-By: sourceware.org Received: from mail-qw0-f47.google.com (HELO mail-qw0-f47.google.com) (209.85.216.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 14 Mar 2011 17:13:44 +0000 Received: by qwh5 with SMTP id 5so1505004qwh.20 for ; Mon, 14 Mar 2011 10:13:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.136.9 with SMTP id p9mr11302878qat.187.1300122822412; Mon, 14 Mar 2011 10:13:42 -0700 (PDT) Received: by 10.229.89.197 with HTTP; Mon, 14 Mar 2011 10:13:42 -0700 (PDT) Date: Mon, 14 Mar 2011 18:13:42 +0100 Message-ID: Subject: [patch libcpp]: Improve handling of DOS-filenames and -paths From: Kai Tietz To: GCC Patches X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Hello, this patch fixes some DOS-filename comparision and directory-separator checks. Changelog libcpp 2011-03-14 Kai Tietz * files.c (file_hash_eq): Use filename_cmp instead of strcmp. (nonexistent_file_hash_eq): Likewise. (remap_filename): Likewise. Handle absolute DOS-path, (append_file_to_dir): Check for IS_DIR_SEPARATOR instead of slash. (read_name_map): Likewise. * linemap.c (linemap_add): Use filename_cmp instead of strcmp. * mkdeps.c (apply_vpath): Use filename_ncmp instead of strncmp. (deps_restore): Use filename_cmp instead of strcmp. * init.c (read_original_directory): Use IS_DIR_SEPARATOR instead of checking for slash. Tested for x86_64-pc-linux-gnu and x86_64-w64-mingw32. Ok for apply? Regards, Kai Index: gcc/libcpp/files.c =================================================================== --- gcc.orig/libcpp/files.c 2011-03-14 17:28:34.106392100 +0100 +++ gcc/libcpp/files.c 2011-03-14 18:03:04.260379100 +0100 @@ -1155,7 +1155,7 @@ file_hash_eq (const void *p, const void else hname = entry->u.dir->name; - return strcmp (hname, fname) == 0; + return filename_cmp (hname, fname) == 0; } /* Compare entries in the nonexistent file hash table. These are just @@ -1163,7 +1163,7 @@ file_hash_eq (const void *p, const void static int nonexistent_file_hash_eq (const void *p, const void *q) { - return strcmp ((const char *) p, (const char *) q) == 0; + return filename_cmp ((const char *) p, (const char *) q) == 0; } /* Initialize everything in this source file. */ @@ -1413,7 +1413,7 @@ append_file_to_dir (const char *fname, c flen = strlen (fname); path = XNEWVEC (char, dlen + 1 + flen + 1); memcpy (path, dir->name, dlen); - if (dlen && path[dlen - 1] != '/') + if (dlen && !IS_DIR_SEPARATOR (path[dlen - 1])) path[dlen++] = '/'; memcpy (&path[dlen], fname, flen + 1); @@ -1461,7 +1461,7 @@ read_name_map (cpp_dir *dir) len = dir->len; name = (char *) alloca (len + sizeof (FILE_NAME_MAP_FILE) + 1); memcpy (name, dir->name, len); - if (len && name[len - 1] != '/') + if (len && !IS_DIR_SEPARATOR (name[len - 1])) name[len++] = '/'; strcpy (name + len, FILE_NAME_MAP_FILE); f = fopen (name, "r"); @@ -1532,10 +1532,18 @@ remap_filename (cpp_reader *pfile, _cpp_ read_name_map (dir); for (index = 0; dir->name_map[index]; index += 2) - if (!strcmp (dir->name_map[index], fname)) + if (!filename_cmp (dir->name_map[index], fname)) return xstrdup (dir->name_map[index + 1]); - + if (IS_ABSOLUTE_PATH (fname)) + return NULL; p = strchr (fname, '/'); +#ifdef HAVE_DOS_BASED_FILE_SYSTEM + { + char *p2 = strchr (fname, '\\'); + if (!p || (p > p2)) + p = p2; + } +#endif if (!p || p == fname) return NULL; Index: gcc/libcpp/line-map.c =================================================================== --- gcc.orig/libcpp/line-map.c 2011-03-14 17:28:34.108392100 +0100 +++ gcc/libcpp/line-map.c 2011-03-14 18:03:04.274380900 +0100 @@ -138,7 +138,7 @@ linemap_add (struct line_maps *set, enum else { from = INCLUDED_FROM (set, map - 1); - error = to_file && strcmp (from->to_file, to_file); + error = to_file && filename_cmp (from->to_file, to_file); } /* Depending upon whether we are handling preprocessed input or Index: gcc/libcpp/mkdeps.c =================================================================== --- gcc.orig/libcpp/mkdeps.c 2011-03-14 17:28:34.114392100 +0100 +++ gcc/libcpp/mkdeps.c 2011-03-14 18:03:04.278881500 +0100 @@ -130,7 +130,7 @@ apply_vpath (struct deps *d, const char unsigned int i; for (i = 0; i < d->nvpaths; i++) { - if (!strncmp (d->vpathv[i], t, d->vpathlv[i])) + if (!filename_ncmp (d->vpathv[i], t, d->vpathlv[i])) { const char *p = t + d->vpathlv[i]; if (!IS_DIR_SEPARATOR (*p)) @@ -421,7 +421,7 @@ deps_restore (struct deps *deps, FILE *f buf[num_to_read] = '\0'; /* Generate makefile dependencies from .pch if -nopch-deps. */ - if (self != NULL && strcmp (buf, self) != 0) + if (self != NULL && filename_cmp (buf, self) != 0) deps_add_dep (deps, buf); } Index: gcc/libcpp/init.c =================================================================== --- gcc.orig/libcpp/init.c 2011-03-14 17:28:34.107392100 +0100 +++ gcc/libcpp/init.c 2011-03-14 18:03:04.283882100 +0100 @@ -26,6 +26,7 @@ along with this program; see the file CO #include "internal.h" #include "mkdeps.h" #include "localedir.h" +#include "filenames.h" static void init_library (void); static void mark_named_operators (cpp_reader *, int); @@ -640,8 +641,8 @@ read_original_directory (cpp_reader *pfi if (token->type != CPP_STRING || ! (token->val.str.len >= 5 - && token->val.str.text[token->val.str.len-2] == '/' - && token->val.str.text[token->val.str.len-3] == '/')) + && IS_DIR_SEPARATOR (token->val.str.text[token->val.str.len-2]) + && IS_DIR_SEPARATOR (token->val.str.text[token->val.str.len-3]))) { _cpp_backup_tokens (pfile, 3); return;