From: Khoo Yit Phang <khooyp@cs.umd.edu>
To: Andreas Schwab <schwab@linux-m68k.org>
Cc: Khoo Yit Phang <khooyp@cs.umd.edu>,
Jan Kratochvil <jan.kratochvil@redhat.com>,
Eli Zaretskii <eliz@gnu.org>,
gdb-patches@sourceware.org
Subject: Re: [PATCH 1/2]: Refactor relocate_path to also check if the relocated file/directory exists
Date: Sat, 22 Sep 2012 16:07:00 -0000 [thread overview]
Message-ID: <FE1014DE-0D92-4BC9-9B01-05919B9100C9@cs.umd.edu> (raw)
In-Reply-To: <m2sjab9os3.fsf@igel.home>
[-- Attachment #1: Type: text/plain, Size: 443 bytes --]
Hi,
On Sep 21, 2012, at 3:09 PM, Andreas Schwab wrote:
> Jan Kratochvil <jan.kratochvil@redhat.com> writes:
>
>> It would have to be written as:
>> if (stat (path, &s) != 0 || !isdir != !S_ISDIR (s.st_mode))
>
> A common idiom is to use !! when the other side is already boolean.
I like this idiom, it does seem to be used in GDB, and isdir should be a boolean. Here's a patch that uses it.
Yit
September 22, 2012
[-- Attachment #2: refactor-relocate-path.txt --]
[-- Type: text/plain, Size: 2819 bytes --]
gdb/ChangeLog
2012-09-21 Khoo Yit Phang <khooyp@cs.umd.edu>
Refactor relocate_path to also check if the relocated
file/directory exists.
* main.c (relocate_path): Add an isdir argument, and check that
the relocated file/directory exists.
(relocate_gdb_directory): Remove the directory check that is
subsumed by relocate_path.
(get_init_files): Remove the file check that is subsumed by
relocate_path.
diff --git a/gdb/main.c b/gdb/main.c
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -91,17 +91,34 @@
static void print_gdb_help (struct ui_file *);
-/* Relocate a file or directory. PROGNAME is the name by which gdb
- was invoked (i.e., argv[0]). INITIAL is the default value for the
- file or directory. FLAG is true if the value is relocatable, false
- otherwise. Returns a newly allocated string; this may return NULL
- under the same conditions as make_relative_prefix. */
+/* Relocate a file or directory, checking if it exists. PROGNAME is the
+ name by which gdb was invoked (i.e., argv[0]). INITIAL is the default
+ value for the file or directory. ISDIR is true if INITIAL is a
+ directory. FLAG is true if the value is relocatable, false otherwise.
+ Returns a newly allocated string; this may return NULL under the same
+ conditions as make_relative_prefix, or if the relocated path does not
+ exist. */
static char *
-relocate_path (const char *progname, const char *initial, int flag)
+relocate_path (const char *progname, const char *initial, int isdir,
+ int flag)
{
if (flag)
- return make_relative_prefix (progname, BINDIR, initial);
+ {
+ char *path;
+ path = make_relative_prefix (progname, BINDIR, initial);
+ if (path)
+ {
+ struct stat s;
+
+ if (stat (path, &s) != 0 || (isdir != !!S_ISDIR (s.st_mode)))
+ {
+ xfree (path);
+ path = NULL;
+ }
+ }
+ return path;
+ }
return xstrdup (initial);
}
@@ -116,17 +133,7 @@
{
char *dir;
- dir = relocate_path (gdb_program_name, initial, flag);
- if (dir)
- {
- struct stat s;
-
- if (stat (dir, &s) != 0 || !S_ISDIR (s.st_mode))
- {
- xfree (dir);
- dir = NULL;
- }
- }
+ dir = relocate_path (gdb_program_name, initial, 1, flag);
if (!dir)
dir = xstrdup (initial);
@@ -162,15 +169,15 @@
if (!initialized)
{
- struct stat homebuf, cwdbuf, s;
+ struct stat homebuf, cwdbuf;
char *homedir, *relocated_sysgdbinit;
if (SYSTEM_GDBINIT[0])
{
relocated_sysgdbinit = relocate_path (gdb_program_name,
- SYSTEM_GDBINIT,
+ SYSTEM_GDBINIT, 0,
SYSTEM_GDBINIT_RELOCATABLE);
- if (relocated_sysgdbinit && stat (relocated_sysgdbinit, &s) == 0)
+ if (relocated_sysgdbinit)
sysgdbinit = relocated_sysgdbinit;
else
xfree (relocated_sysgdbinit);
next prev parent reply other threads:[~2012-09-22 16:07 UTC|newest]
Thread overview: 72+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-18 20:33 [PATCH] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary Khoo Yit Phang
2012-09-19 13:01 ` Jan Kratochvil
2012-09-19 19:53 ` [PATCH 1/2]: Refactor relocate_path to also check if the relocated file/directory exists Khoo Yit Phang
2012-09-21 18:27 ` Jan Kratochvil
2012-09-21 18:36 ` Eli Zaretskii
2012-09-21 18:46 ` Jan Kratochvil
2012-09-21 18:59 ` Eli Zaretskii
2012-09-21 19:09 ` Andreas Schwab
2012-09-22 16:07 ` Khoo Yit Phang [this message]
2012-09-25 6:59 ` Jan Kratochvil
2012-09-19 19:56 ` [PATCH 2/2] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary Khoo Yit Phang
2012-09-21 18:31 ` Jan Kratochvil
2012-09-21 19:05 ` Khoo Yit Phang
2012-09-22 11:08 ` Jan Kratochvil
2012-09-22 15:50 ` Khoo Yit Phang
2012-09-24 7:30 ` Joel Brobecker
2012-09-24 13:14 ` Khoo Yit Phang
2012-09-24 14:24 ` Eli Zaretskii
2012-09-24 14:37 ` Khoo Yit Phang
2012-09-24 14:51 ` Eli Zaretskii
2012-09-24 15:00 ` Khoo Yit Phang
2012-09-24 15:27 ` Khoo Yit Phang
2012-09-24 15:49 ` Eli Zaretskii
2012-09-24 14:59 ` Joel Brobecker
2012-09-24 15:08 ` Khoo Yit Phang
2012-09-24 15:09 ` Eli Zaretskii
2012-09-24 15:12 ` Khoo Yit Phang
2012-09-24 15:27 ` Joel Brobecker
2012-09-24 16:10 ` Khoo Yit Phang
2012-09-24 16:45 ` Khoo Yit Phang
2012-09-24 17:04 ` Joel Brobecker
2012-09-24 19:19 ` [PATCH] Also install data-directory into the build directory as computed by relocate_gdb_directory Khoo Yit Phang
2012-09-27 9:17 ` Joel Brobecker
2012-09-27 14:57 ` Khoo Yit Phang
2012-10-03 21:31 ` Doug Evans
2012-10-04 0:09 ` Joel Brobecker
2012-10-04 0:50 ` Doug Evans
2012-10-04 1:34 ` Joel Brobecker
2012-10-04 3:41 ` Khoo Yit Phang
2012-10-04 13:39 ` Joel Brobecker
2012-10-04 14:26 ` Doug Evans
2012-10-04 14:25 ` Doug Evans
2012-10-04 14:51 ` Joel Brobecker
2012-10-04 15:07 ` Doug Evans
2012-10-04 15:28 ` Joel Brobecker
2012-10-06 19:02 ` Khoo Yit Phang
2012-10-06 19:25 ` Eli Zaretskii
2012-10-06 19:36 ` Khoo Yit Phang
2012-10-06 20:07 ` Eli Zaretskii
2012-10-06 20:12 ` Khoo Yit Phang
2012-10-06 20:29 ` Eli Zaretskii
2012-10-06 20:32 ` Khoo Yit Phang
2012-10-06 21:00 ` Eli Zaretskii
2012-10-08 16:33 ` Doug Evans
2012-10-08 20:13 ` Khoo Yit Phang
2012-10-08 20:24 ` Doug Evans
2012-10-09 5:48 ` Joel Brobecker
2012-10-09 16:49 ` Eli Zaretskii
2012-10-04 3:43 ` Eli Zaretskii
2012-10-04 13:49 ` Joel Brobecker
2012-10-04 14:48 ` Doug Evans
2012-10-04 15:23 ` Doug Evans
2012-10-04 17:07 ` Eli Zaretskii
2012-09-24 18:12 ` [PATCH 2/2] Try to initialize data-directory by first searching for "data-directory" in the same directory as the gdb binary Eli Zaretskii
2012-09-24 20:49 ` Joel Brobecker
2012-09-24 21:08 ` Eli Zaretskii
2012-09-24 21:37 ` Joel Brobecker
2012-09-25 6:29 ` Eli Zaretskii
2012-09-25 6:35 ` Joel Brobecker
2012-09-25 6:50 ` Eli Zaretskii
2012-09-25 7:02 ` Joel Brobecker
2012-09-24 18:11 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=FE1014DE-0D92-4BC9-9B01-05919B9100C9@cs.umd.edu \
--to=khooyp@cs.umd.edu \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=jan.kratochvil@redhat.com \
--cc=schwab@linux-m68k.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox