This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] AmigaOS 4 port contribution [libiberty]
"Zack Weinberg" <zack@codesourcery.com> writes:
> pex-amigaos.c didn't get included in this diff.
Oooops. Well, that's `cvs diff' for you. Only includes files which
are in the CVS repository. :-) Sorry, new patch attached below.
> > +#ifdef __amigaos__
> > +# ifndef DIR_SEPARATOR_2
> > +# define DIR_SEPARATOR_2 ':'
> > +# endif
> > +#endif
>
> Here and elsewhere: only indent nested preprocessor directives one
> space per level. Also, I would suggest that this go into
> include/filenames.h instead of being replicated in several different
> libiberty files. (It may be possible to refactor other goo from these
> files into that header, but you don't have to do that.)
I've changed the indentation, and moved the definitions of
DIR_SEPARATOR
DIR_SEPARATOR_2
IS_DIR_SEPARATOR and
HAVE_DOS_BASED_FILE_SYSTEM
into filenames.h (some of it was already there).
// Marcus
Index: libiberty/Makefile.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/Makefile.in,v
retrieving revision 1.93
diff -u -p -r1.93 Makefile.in
--- libiberty/Makefile.in 22 Jun 2003 15:59:49 -0000 1.93
+++ libiberty/Makefile.in 7 Oct 2003 22:40:13 -0000
@@ -143,7 +143,7 @@ CFILES = alloca.c argv.c asprintf.c atex
mempcpy.c memset.c mkstemps.c \
objalloc.c obstack.c \
partition.c \
- pex-djgpp.c pex-mpw.c pex-msdos.c pex-os2.c \
+ pex-amigaos.c pex-djgpp.c pex-mpw.c pex-msdos.c pex-os2.c \
pex-unix.c pex-win32.c \
physmem.c putenv.c \
random.c regex.c rename.c rindex.c \
@@ -187,7 +187,7 @@ CONFIGURED_OFILES = asprintf.o atexit.o
getcwd.o getpagesize.o \
index.o insque.o \
memchr.o memcmp.o memcpy.o memmove.o mempcpy.o memset.o mkstemps.o \
- pex-djgpp.o pex-mpw.o pex-msdos.o pex-os2.o \
+ pex-amigaos.o pex-djgpp.o pex-mpw.o pex-msdos.o pex-os2.o \
pex-unix.o pex-win32.o \
putenv.o \
random.o rename.o rindex.o \
@@ -467,6 +467,8 @@ objalloc.o: config.h $(INCDIR)/ansidecl.
obstack.o: config.h $(INCDIR)/obstack.h
partition.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
$(INCDIR)/partition.h
+pex-amigaos.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
+ $(srcdir)/pex-common.h
pex-djgpp.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
$(srcdir)/pex-common.h
pex-mpw.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
Index: libiberty/basename.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/basename.c,v
retrieving revision 1.6
diff -u -p -r1.6 basename.c
--- libiberty/basename.c 26 Sep 2001 18:16:17 -0000 1.6
+++ libiberty/basename.c 7 Oct 2003 22:40:13 -0000
@@ -15,26 +15,7 @@ Behavior is undefined if the pathname en
#include "ansidecl.h"
#include "libiberty.h"
#include "safe-ctype.h"
-
-#ifndef DIR_SEPARATOR
-#define DIR_SEPARATOR '/'
-#endif
-
-#if defined (_WIN32) || defined (__MSDOS__) || defined (__DJGPP__) || \
- defined (__OS2__)
-#define HAVE_DOS_BASED_FILE_SYSTEM
-#ifndef DIR_SEPARATOR_2
-#define DIR_SEPARATOR_2 '\\'
-#endif
-#endif
-
-/* Define IS_DIR_SEPARATOR. */
-#ifndef DIR_SEPARATOR_2
-# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
-#else /* DIR_SEPARATOR_2 */
-# define IS_DIR_SEPARATOR(ch) \
- (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
-#endif /* DIR_SEPARATOR_2 */
+#include "filenames.h"
char *
basename (name)
Index: libiberty/configure.in
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/configure.in,v
retrieving revision 1.73
diff -u -p -r1.73 configure.in
--- libiberty/configure.in 1 Oct 2003 17:11:29 -0000 1.73
+++ libiberty/configure.in 7 Oct 2003 22:40:15 -0000
@@ -481,6 +481,7 @@ case "${host}" in
*-*-msdosdjgpp*) pexecute=pex-djgpp.o ;;
*-*-msdos*) pexecute=pex-msdos.o ;;
*-*-os2-emx*) pexecute=pex-os2.o ;;
+ *-*-amigaos*) pexecute=pex-amigaos.o;;
*) pexecute=pex-unix.o ;;
esac
AC_SUBST(pexecute)
Index: libiberty/lbasename.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/lbasename.c,v
retrieving revision 1.4
diff -u -p -r1.4 lbasename.c
--- libiberty/lbasename.c 18 Jun 2002 02:04:33 -0000 1.4
+++ libiberty/lbasename.c 7 Oct 2003 22:40:15 -0000
@@ -40,25 +40,7 @@ and a path ending in @code{/} returns th
#include "ansidecl.h"
#include "libiberty.h"
#include "safe-ctype.h"
-
-#ifndef DIR_SEPARATOR
-# define DIR_SEPARATOR '/'
-#endif
-
-#if defined (_WIN32) || defined (__MSDOS__) \
- || defined (__DJGPP__) || defined (__OS2__)
-# define HAVE_DOS_BASED_FILE_SYSTEM
-# ifndef DIR_SEPARATOR_2
-# define DIR_SEPARATOR_2 '\\'
-# endif
-#endif
-
-#ifndef DIR_SEPARATOR_2
-# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
-#else
-# define IS_DIR_SEPARATOR(ch) \
- (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
-#endif
+#include "filenames.h"
const char *
lbasename (name)
Index: libiberty/lrealpath.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/lrealpath.c,v
retrieving revision 1.1
diff -u -p -r1.1 lrealpath.c
--- libiberty/lrealpath.c 20 Feb 2003 22:11:13 -0000 1.1
+++ libiberty/lrealpath.c 7 Oct 2003 22:40:15 -0000
@@ -49,6 +49,7 @@ components will be simplified. The retu
#ifdef HAVE_STRING_H
#include <string.h>
#endif
+#include <stdio.h> /* for MAXPATHLEN */
/* On GNU libc systems the declaration is only visible with _GNU_SOURCE. */
#if defined(HAVE_CANONICALIZE_FILE_NAME) \
@@ -121,6 +122,16 @@ lrealpath (filename)
return ret;
}
}
+#endif
+
+#ifdef __amigaos__
+ /* Special case for AmigaOS 4:
+ Here readlink actually works as a realpath, so try using it. */
+ {
+ char buf[MAXPATHLEN];
+ if (readlink (filename, buf, sizeof buf) >= 0)
+ return strdup (buf);
+ }
#endif
/* This system is a lost cause, just duplicate the filename. */
Index: libiberty/make-relative-prefix.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/make-relative-prefix.c,v
retrieving revision 1.4
diff -u -p -r1.4 make-relative-prefix.c
--- libiberty/make-relative-prefix.c 20 Feb 2003 22:10:58 -0000 1.4
+++ libiberty/make-relative-prefix.c 7 Oct 2003 22:40:15 -0000
@@ -62,6 +62,7 @@ relative prefix can be found, return @co
#include "ansidecl.h"
#include "libiberty.h"
+#include "filenames.h"
#ifndef R_OK
#define R_OK 4
@@ -69,31 +70,25 @@ relative prefix can be found, return @co
#define X_OK 1
#endif
-#ifndef DIR_SEPARATOR
-# define DIR_SEPARATOR '/'
-#endif
-
#if defined (_WIN32) || defined (__MSDOS__) \
|| defined (__DJGPP__) || defined (__OS2__)
-# define HAVE_DOS_BASED_FILE_SYSTEM
-# define HAVE_HOST_EXECUTABLE_SUFFIX
-# define HOST_EXECUTABLE_SUFFIX ".exe"
-# ifndef DIR_SEPARATOR_2
-# define DIR_SEPARATOR_2 '\\'
-# endif
-# define PATH_SEPARATOR ';'
-#else
-# define PATH_SEPARATOR ':'
-#endif
-
-#ifndef DIR_SEPARATOR_2
-# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)
-#else
-# define IS_DIR_SEPARATOR(ch) \
- (((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))
+# define HAVE_HOST_EXECUTABLE_SUFFIX
+# define HOST_EXECUTABLE_SUFFIX ".exe"
+# define PATH_SEPARATOR ';'
+#endif
+
+#ifdef __amigaos__
+# define PATH_SEPARATOR ';'
+# define DIR_UP ""
#endif
-#define DIR_UP ".."
+#ifndef PATH_SEPARATOR
+# define PATH_SEPARATOR ':'
+#endif
+
+#ifndef DIR_UP
+# define DIR_UP ".."
+#endif
static char *save_string PARAMS ((const char *, int));
static char **split_directories PARAMS ((const char *, int *));
@@ -241,6 +236,7 @@ make_relative_prefix (progname, bin_pref
of the directories specified in the PATH environment variable. */
if (lbasename (progname) == progname)
{
+#ifndef __amigaos__
char *temp;
temp = getenv ("PATH");
@@ -294,6 +290,13 @@ make_relative_prefix (progname, bin_pref
endp++;
}
}
+#else /* __amigaos__ */
+ /* On AmigaOS there is PROGDIR:, so no need to look... */
+ char * nstore = (char *) alloca (strlen (progname) + 9);
+ strcpy (nstore, "PROGDIR:");
+ strcat (nstore, progname);
+ progname = nstore;
+#endif /* __amigaos__ */
}
full_progname = lrealpath (progname);
Index: libiberty/make-temp-file.c
===================================================================
RCS file: /cvsroot/gcc/gcc/libiberty/make-temp-file.c,v
retrieving revision 1.5
diff -u -p -r1.5 make-temp-file.c
--- libiberty/make-temp-file.c 17 Oct 2001 21:15:41 -0000 1.5
+++ libiberty/make-temp-file.c 7 Oct 2003 22:40:15 -0000
@@ -43,12 +43,9 @@ Boston, MA 02111-1307, USA. */
#endif
#include "libiberty.h"
-extern int mkstemps PARAMS ((char *, int));
+#include "filenames.h"
-/* '/' works just fine on MS-DOS based systems. */
-#ifndef DIR_SEPARATOR
-#define DIR_SEPARATOR '/'
-#endif
+extern int mkstemps PARAMS ((char *, int));
/* Name of temporary file.
mktemp requires 6 trailing X's. */
@@ -75,11 +72,13 @@ try (dir, base)
return 0;
}
+#ifndef __amigaos__
static const char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 };
static const char usrtmp[] =
{ DIR_SEPARATOR, 'u', 's', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
static const char vartmp[] =
{ DIR_SEPARATOR, 'v', 'a', 'r', DIR_SEPARATOR, 't', 'm', 'p', 0 };
+#endif /* __amigaos__ */
static char *memoized_tmpdir;
@@ -112,10 +111,15 @@ choose_tmpdir ()
base = try (P_tmpdir, base);
#endif
+#ifndef __amigaos__
/* Try /var/tmp, /usr/tmp, then /tmp. */
base = try (vartmp, base);
base = try (usrtmp, base);
base = try (tmp, base);
+#else /* __amigaos__ */
+ /* Try T: */
+ base = try ("T:", base);
+#endif /* __amigaos__ */
/* If all else fails, use the current directory! */
if (base == 0)
@@ -126,8 +130,16 @@ choose_tmpdir ()
len = strlen (base);
tmpdir = xmalloc (len + 2);
strcpy (tmpdir, base);
- tmpdir[len] = DIR_SEPARATOR;
- tmpdir[len+1] = '\0';
+
+ /* Don't add DIR_SEPARATOR if base already ends with a dir separator,
+ it's unneeded and can cause ill effects on e.g. AmigaOS. */
+ if (IS_DIR_SEPARATOR(base[len-1]))
+ tmpdir[len] = '\0';
+ else
+ {
+ tmpdir[len] = DIR_SEPARATOR;
+ tmpdir[len+1] = '\0';
+ }
memoized_tmpdir = tmpdir;
return tmpdir;
Index: libiberty/pex-amigaos.c
===================================================================
diff -u /dev/null libiberty/pex-amigaos.c
--- /dev/null Wed Oct 8 00:32:52 2003
+++ libiberty/pex-amigaos.c Tue Oct 7 22:37:46 2003
@@ -0,0 +1,173 @@
+/* Utilities to execute a program in a subprocess (possibly linked by pipes
+ with other subprocesses), and wait for it. Generic AmigaOS specialization.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003
+ Free Software Foundation, Inc.
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB. If not,
+write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+Boston, MA 02111-1307, USA. */
+
+#include "pex-common.h"
+
+#include <stdio.h>
+#include <errno.h>
+#ifdef NEED_DECLARATION_ERRNO
+extern int errno;
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include "safe-ctype.h"
+
+/* Note: * and " are deliberately left out from this list since they
+ are treated even more specially. */
+#define IS_METACHARACTER(ch) \
+ (ISSPACE (ch) || ch == '&' || ch == '+' || ch == ';' || \
+ ch == '<' || ch == '|' || ch == '>')
+
+
+/* For communicating information from pexecute to pwait. */
+static int last_pid = 0;
+static int last_status = 0;
+static int last_reaped = 0;
+
+int
+pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags)
+ const char *program;
+ char * const *argv;
+ const char *this_pname;
+ const char *temp_base;
+ char **errmsg_fmt, **errmsg_arg;
+ int flags;
+{
+ int rc;
+ char *scmd,*s;
+ int i,j,c,len,arglen;
+ int need_quote;
+
+ last_pid++;
+ if (last_pid < 0)
+ last_pid = 1;
+
+ if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE)
+ abort ();
+
+ len = 0;
+
+ for(i = 0 ; argv[i] != NULL ; i++)
+ {
+ arglen = strlen(argv[i]);
+
+ len += 1 + arglen;
+
+ for(j = 0, need_quote = (arglen == 0) ; j < arglen ; j++)
+ {
+ c = argv[i][j];
+
+ if (c == '*')
+ len++;
+ else if (c == '\"' || c == '\n')
+ {
+ need_quote = 1;
+ len++;
+ }
+ else if (IS_METACHARACTER (c))
+ need_quote = 1;
+ }
+
+ if(need_quote)
+ len += 2;
+ }
+
+ s = scmd = (char *) xmalloc (len+1);
+
+ for(i = 0 ; argv[i] != NULL ; i++)
+ {
+ arglen = strlen(argv[i]);
+
+ for(j = 0, need_quote = (arglen == 0) ; j < arglen ; j++)
+ {
+ c = argv[i][j];
+ if (IS_METACHARACTER (c) || c == '\"' || c == '\n')
+ need_quote = 1;
+ }
+
+ if(s != scmd)
+ *s++ = ' ';
+
+ if(need_quote)
+ *s++ = '\"';
+
+ for(j = 0 ; j < arglen ; j++)
+ {
+ c = argv[i][j];
+ if (c == '\n')
+ {
+ *s++ = '*';
+ c = 'N';
+ }
+ else if (c == '\"' || (c == '*' && need_quote))
+ *s++ = '*';
+
+ *s++ = c;
+ }
+
+ if(need_quote)
+ *s++ = '\"';
+ }
+
+ *s = '\0';
+
+ rc = system (scmd);
+
+ free (scmd);
+
+ if (rc == -1)
+ {
+ *errmsg_fmt = install_error_msg;
+ *errmsg_arg = program;
+ return -1;
+ }
+
+ /* Tuck the status away for pwait, and return a "pid". */
+ last_status = rc << 8;
+ return last_pid;
+}
+
+int
+pwait (pid, status, flags)
+ int pid;
+ int *status;
+ int flags;
+{
+ /* On AmigaOS each pexecute must be followed by it's associated pwait. */
+ if (pid != last_pid
+ /* Called twice for the same child? */
+ || pid == last_reaped)
+ {
+ /* ??? ECHILD would be a better choice. Can we use it here? */
+ errno = EINVAL;
+ return -1;
+ }
+ /* ??? Here's an opportunity to canonicalize the values in STATUS.
+ Needed? */
+ *status = last_status;
+ last_reaped = last_pid;
+ return last_pid;
+}