From: Eli Zaretskii <eliz@is.elta.co.il>
To: Andrew Cagney <ac131313@cygnus.com>
Cc: kevinb@cygnus.com, gdb-patches@sources.redhat.com
Subject: Re: [RFA] Remove OS-specific defines (was: _WIN32?)
Date: Thu, 10 May 2001 03:31:00 -0000 [thread overview]
Message-ID: <Pine.SUN.3.91.1010510133136.4393C-100000@is> (raw)
In-Reply-To: <3AF6EB58.1020904@cygnus.com>
On Mon, 7 May 2001, Andrew Cagney wrote:
> > Btw, is it perhaps a good idea to add to gdbint.texinfo some
> > guidelines about writing portable code which handles file names,
> > including the list of these macros? Andrew?
>
> Yes, and yes.
I committed the following patch:
--- gdb/doc/gdbint.t~0 Sun Apr 1 11:27:48 2001
+++ gdb/doc/gdbint.texinfo Tue May 8 16:24:42 2001
@@ -4133,7 +4133,7 @@
All static functions must be declared in a block near the top of the
source file.
-@subsection Clean Design
+@subsection Clean Design and Portable Implementation
@cindex design
In addition to getting the syntax right, there's the little question of
@@ -4219,6 +4219,67 @@
duplicated code. Other times, duplicating a few lines of code here or
there is much cleaner than introducing a large number of small hooks.
+@cindex portable file name handling
+@cindex file names, portability
+One particularly notorious area where system dependencies tend to
+creep in is handling of file names. The mainline @value{GDBN} code
+assumes Posix semantics of file names: absolute file names begin with
+a forward slash @file{/}, slashes are used to separate leading
+directories, case-sensitive file names. These assumptions are not
+necessarily true on non-Posix systems such as MS-Windows. To avoid
+system-dependent code where you need to take apart or construct a file
+name, use the following portable macros:
+
+@table @code
+@findex HAVE_DOS_BASED_FILE_SYSTEM
+@item HAVE_DOS_BASED_FILE_SYSTEM
+This preprocessing symbol is defined to a non-zero value on hosts
+whose filesystems belong to the MS-DOS/MS-Windows family. Use this
+symbol to write conditional code which should only be compiled for
+such hosts.
+
+@findex IS_DIR_SEPARATOR
+@item IS_DIR_SEPARATOR (@var{c}
+Evaluates to a non-zero value if @var{c} is a directory separator
+character. On Unix and GNU/Linux systems, only a slash @file{/} is
+such a character, but on Windows, both @file{/} and @file{\} will
+pass.
+
+@findex IS_ABSOLUTE_PATH
+@item IS_ABSOLUTE_PATH (@var{file})
+Evaluates to a non-zero value if @var{file} is an absolute file name.
+For Unix and GNU/Linux hosts, a name which begins with a slash
+@file{/} is absolute. On DOS and Windows, @file{d:/foo} and
+@file{x:\bar} are also absolute file names.
+
+@findex FILENAME_CMP
+@item FILENAME_CMP (@var{f1}, @var{f2})
+Calls a function which compares file names @var{f1} and @var{f2} as
+appropriate for the underlying host filesystem. For Posix systems,
+this simply calls @code{strcmp}; on case-insensitive filesystems it
+will call @code{strcasecmp} instead.
+
+@findex DIRNAME_SEPARATOR
+@item DIRNAME_SEPARATOR
+Evaluates to a character which separates directories in
+@code{PATH}-style lists, typically held in environment variables.
+This character is @samp{:} on Unix, @samp{;} on DOS and Windows.
+
+@findex SLASH_STRING
+@item SLASH_STRING
+This evaluates to a constant string you should use to produce an
+absolute filename from leading directories and the file's basename.
+@code{SLASH_STRING} is @code{"/"} on most systems, but might be
+@code{"\\"} for some Windows-based ports.
+@end table
+
+In addition to using these macros, be sure to use portable library
+functions whenever possible. For example, to extract a directory or a
+basename part from a file name, use the @code{dirname} and
+@code{basename} library functions (available in @code{libiberty} for
+platforms which don't provide them), instead of searching for a slash
+with @code{strrchr}.
+
Another way to generalize @value{GDBN} along a particular interface is with an
attribute struct. For example, @value{GDBN} has been generalized to handle
multiple kinds of remote interfaces---not by @code{#ifdef}s everywhere, but
next parent reply other threads:[~2001-05-10 3:31 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <3AF6EB58.1020904@cygnus.com>
2001-05-10 3:31 ` Eli Zaretskii [this message]
[not found] <20010503211502.21716.qmail@web6401.mail.yahoo.com>
[not found] ` <3AF1DAA0.3060702@cygnus.com>
[not found] ` <200105071610.TAA24144@is.elta.co.il>
[not found] ` <1010507173855.ZM18890@ocotillo.lan>
2001-05-07 11:24 ` Eli Zaretskii
2001-06-10 6:28 ` Eli Zaretskii
2001-06-12 17:14 ` Christopher Faylor
2001-06-13 2:08 ` Eli Zaretskii
2001-05-13 1:29 ` Eli Zaretskii
2001-05-13 7:09 ` Fernando Nasser
2001-05-13 23:34 ` Eli Zaretskii
2001-05-14 13:18 ` Andrew Cagney
2001-06-04 0:46 ` Eli Zaretskii
2001-05-07 11:36 David Taylor
2001-05-08 0:12 ` 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=Pine.SUN.3.91.1010510133136.4393C-100000@is \
--to=eliz@is.elta.co.il \
--cc=ac131313@cygnus.com \
--cc=gdb-patches@sources.redhat.com \
--cc=kevinb@cygnus.com \
/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