aboutsummaryrefslogtreecommitdiff
path: root/gcc/prefix.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>1999-01-05 19:11:22 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>1999-01-05 19:11:22 +0000
commit460ee1120c62c6c543e8bdfac4ee287e754e3a61 (patch)
treef98dde49db8ef6f1d425e196eb7db84dab10c8b4 /gcc/prefix.c
parent258ce95eb63d074fc9d39d7e1f82316a4fb7874d (diff)
downloadgcc-460ee1120c62c6c543e8bdfac4ee287e754e3a61.zip
gcc-460ee1120c62c6c543e8bdfac4ee287e754e3a61.tar.gz
gcc-460ee1120c62c6c543e8bdfac4ee287e754e3a61.tar.bz2
Makefile.in (gcc.o, [...]): Depend on prefix.h.
* Makefile.in (gcc.o, prefix.o, cccp.o, cpplib.o): Depend on prefix.h. * cccp.c: Include prefix.h, don't prototype prefix.c functions. (new_include_prefix): Constify char* parameters. * cppfiles.c (read_name_map): Likewise. (append_include_chain): Likewise. Also, use a writable char* copy of parameter `dir' which we then modify, rather than using the parameter itself to store the new writable string. (remap_filename): Constify some variables. Also, use a writable char* to store an allocated string which we will be modifying. * cpplib.c: Include prefix.h, don't prototype prefix.c functions. (cpp_start_read): Constify variable `str'. * cpplib.h (append_include_chain): Constify a char* parameter. * gcc.c Include prefix.h, don't prototype prefix.c functions. (add_prefix, save_string): Constify char* parameters. (fatal, error): Add ATTRIBUTE_PRINTF_1 to prototypes. * prefix.c: Include prefix.h. (get_key_value, translate_name, save_string, update_path, set_std_prefix): Constify various char* parameters and variables. (save_string): Use xmalloc, not malloc. (translate_name): Use a writable temporary variable to create and modify a string before setting it to a const char*. * prefix.h: New file to prototype functions exported from prefix.c. From-SVN: r24498
Diffstat (limited to 'gcc/prefix.c')
-rw-r--r--gcc/prefix.c41
1 files changed, 22 insertions, 19 deletions
diff --git a/gcc/prefix.c b/gcc/prefix.c
index 3e98ded..5e4fdb1 100644
--- a/gcc/prefix.c
+++ b/gcc/prefix.c
@@ -68,12 +68,13 @@ Boston, MA 02111-1307, USA. */
#ifdef _WIN32
#include <windows.h>
#endif
+#include "prefix.h"
-static char *std_prefix = PREFIX;
+static const char *std_prefix = PREFIX;
-static char *get_key_value PROTO((char *));
-static char *translate_name PROTO((char *));
-static char *save_string PROTO((char *, int));
+static const char *get_key_value PROTO((char *));
+static const char *translate_name PROTO((const char *));
+static char *save_string PROTO((const char *, int));
#ifdef _WIN32
static char *lookup_key PROTO((char *));
@@ -82,11 +83,11 @@ static HKEY reg_key = (HKEY) INVALID_HANDLE_VALUE;
/* Given KEY, as above, return its value. */
-static char *
+static const char *
get_key_value (key)
char *key;
{
- char *prefix = 0;
+ const char *prefix = 0;
char *temp = 0;
#ifdef _WIN32
@@ -165,10 +166,10 @@ concat VPROTO((const char *first, ...))
static char *
save_string (s, len)
- char *s;
- int len;
+ const char *s;
+ int len;
{
- register char *result = (char *) malloc (len + 1);
+ register char *result = xmalloc (len + 1);
bcopy (s, result, len);
result[len] = 0;
@@ -227,12 +228,13 @@ lookup_key (key)
/* If NAME starts with a '@' or '$', apply the translation rules above
and return a new name. Otherwise, return the given name. */
-static char *
+static const char *
translate_name (name)
- char *name;
+ const char *name;
{
char code = name[0];
- char *key, *prefix = 0;
+ char *key;
+ const char *prefix = 0;
int keylen;
if (code != '@' && code != '$')
@@ -272,8 +274,9 @@ translate_name (name)
#endif
)
{
- prefix = save_string (prefix, strlen (prefix));
- prefix[strlen (prefix) - 1] = 0;
+ char * temp = save_string (prefix, strlen (prefix));
+ temp[strlen (temp) - 1] = 0;
+ prefix = temp;
}
return concat (prefix, name, NULL_PTR);
@@ -281,10 +284,10 @@ translate_name (name)
/* Update PATH using KEY if PATH starts with PREFIX. */
-char *
+const char *
update_path (path, key)
- char *path;
- char *key;
+ const char *path;
+ const char *key;
{
if (! strncmp (path, std_prefix, strlen (std_prefix)) && key != 0)
{
@@ -316,8 +319,8 @@ update_path (path, key)
/* Reset the standard prefix */
void
set_std_prefix (prefix, len)
- char *prefix;
- int len;
+ const char *prefix;
+ int len;
{
std_prefix = save_string (prefix, len);
}