Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(440)

Side by Side Diff: libiberty/make-relative-prefix.c

Issue 11969036: Merge GDB 7.5.1 (Closed) Base URL: http://git.chromium.org/native_client/nacl-gdb.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « libiberty/filename_cmp.c ('k') | libiberty/md5.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Relative (relocatable) prefix support. 1 /* Relative (relocatable) prefix support.
2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2 Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2006 Free Software Foundation, Inc. 3 1999, 2000, 2001, 2002, 2006, 2012 Free Software Foundation, Inc.
4 4
5 This file is part of libiberty. 5 This file is part of libiberty.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free 8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later 9 Software Foundation; either version 2, or (at your option) any later
10 version. 10 version.
11 11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #ifdef HAVE_CONFIG_H 51 #ifdef HAVE_CONFIG_H
52 #include "config.h" 52 #include "config.h"
53 #endif 53 #endif
54 54
55 #ifdef HAVE_STDLIB_H 55 #ifdef HAVE_STDLIB_H
56 #include <stdlib.h> 56 #include <stdlib.h>
57 #endif 57 #endif
58 #ifdef HAVE_UNISTD_H 58 #ifdef HAVE_UNISTD_H
59 #include <unistd.h> 59 #include <unistd.h>
60 #endif 60 #endif
61 #ifdef HAVE_SYS_STAT_H
62 #include <sys/stat.h>
63 #endif
61 64
62 #include <string.h> 65 #include <string.h>
63 66
64 #include "ansidecl.h" 67 #include "ansidecl.h"
65 #include "libiberty.h" 68 #include "libiberty.h"
66 69
67 #ifndef R_OK 70 #ifndef R_OK
68 #define R_OK 4 71 #define R_OK 4
69 #define W_OK 2 72 #define W_OK 2
70 #define X_OK 1 73 #define X_OK 1
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 of the directories specified in the PATH environment variable. */ 241 of the directories specified in the PATH environment variable. */
239 if (lbasename (progname) == progname) 242 if (lbasename (progname) == progname)
240 { 243 {
241 char *temp; 244 char *temp;
242 245
243 temp = getenv ("PATH"); 246 temp = getenv ("PATH");
244 if (temp) 247 if (temp)
245 { 248 {
246 char *startp, *endp, *nstore; 249 char *startp, *endp, *nstore;
247 size_t prefixlen = strlen (temp) + 1; 250 size_t prefixlen = strlen (temp) + 1;
251 size_t len;
248 if (prefixlen < 2) 252 if (prefixlen < 2)
249 prefixlen = 2; 253 prefixlen = 2;
250 254
251 » nstore = (char *) alloca (prefixlen + strlen (progname) + 1); 255 » len = prefixlen + strlen (progname) + 1;
256 #ifdef HAVE_HOST_EXECUTABLE_SUFFIX
257 » len += strlen (HOST_EXECUTABLE_SUFFIX);
258 #endif
259 » nstore = (char *) alloca (len);
252 260
253 startp = endp = temp; 261 startp = endp = temp;
254 while (1) 262 while (1)
255 { 263 {
256 if (*endp == PATH_SEPARATOR || *endp == 0) 264 if (*endp == PATH_SEPARATOR || *endp == 0)
257 { 265 {
258 if (endp == startp) 266 if (endp == startp)
259 { 267 {
260 nstore[0] = '.'; 268 nstore[0] = '.';
261 nstore[1] = DIR_SEPARATOR; 269 nstore[1] = DIR_SEPARATOR;
262 nstore[2] = '\0'; 270 nstore[2] = '\0';
263 } 271 }
264 else 272 else
265 { 273 {
266 » » strncpy (nstore, startp, endp - startp); 274 » » memcpy (nstore, startp, endp - startp);
267 if (! IS_DIR_SEPARATOR (endp[-1])) 275 if (! IS_DIR_SEPARATOR (endp[-1]))
268 { 276 {
269 nstore[endp - startp] = DIR_SEPARATOR; 277 nstore[endp - startp] = DIR_SEPARATOR;
270 nstore[endp - startp + 1] = 0; 278 nstore[endp - startp + 1] = 0;
271 } 279 }
272 else 280 else
273 nstore[endp - startp] = 0; 281 nstore[endp - startp] = 0;
274 } 282 }
275 strcat (nstore, progname); 283 strcat (nstore, progname);
276 if (! access (nstore, X_OK) 284 if (! access (nstore, X_OK)
277 #ifdef HAVE_HOST_EXECUTABLE_SUFFIX 285 #ifdef HAVE_HOST_EXECUTABLE_SUFFIX
278 || ! access (strcat (nstore, HOST_EXECUTABLE_SUFFIX), X_OK ) 286 || ! access (strcat (nstore, HOST_EXECUTABLE_SUFFIX), X_OK )
279 #endif 287 #endif
280 ) 288 )
281 { 289 {
282 » » progname = nstore; 290 #if defined (HAVE_SYS_STAT_H) && defined (S_ISREG)
283 » » break; 291 » » struct stat st;
292 » » if (stat (nstore, &st) >= 0 && S_ISREG (st.st_mode))
293 #endif
294 » » » {
295 » » » progname = nstore;
296 » » » break;
297 » » » }
284 } 298 }
285 299
286 if (*endp == 0) 300 if (*endp == 0)
287 break; 301 break;
288 endp = startp = endp + 1; 302 endp = startp = endp + 1;
289 } 303 }
290 else 304 else
291 endp++; 305 endp++;
292 } 306 }
293 } 307 }
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 installation is patched together with soft links. */ 418 installation is patched together with soft links. */
405 419
406 char * 420 char *
407 make_relative_prefix_ignore_links (const char *progname, 421 make_relative_prefix_ignore_links (const char *progname,
408 const char *bin_prefix, 422 const char *bin_prefix,
409 const char *prefix) 423 const char *prefix)
410 { 424 {
411 return make_relative_prefix_1 (progname, bin_prefix, prefix, 0); 425 return make_relative_prefix_1 (progname, bin_prefix, prefix, 0);
412 } 426 }
413 427
OLDNEW
« no previous file with comments | « libiberty/filename_cmp.c ('k') | libiberty/md5.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698