summaryrefslogtreecommitdiff
path: root/gcc/prefix.c
diff options
context:
space:
mode:
authorghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>1999-01-05 19:11:22 +0000
committerghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4>1999-01-05 19:11:22 +0000
commit7bcdc3c72acd322469e7e757bd44f03072a93459 (patch)
treef98dde49db8ef6f1d425e196eb7db84dab10c8b4 /gcc/prefix.c
parent34f474122add99e4b033b875f2a2574dbd11e884 (diff)
downloadgcc-7bcdc3c72acd322469e7e757bd44f03072a93459.tar.gz
* 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@24498 138bc75d-0d04-0410-961f-82ee72b054a4
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 3e98ded4d73..5e4fdb1505e 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);
}