I had char *p = getcwd() near the bottom of the function in that patch, and
gcc complains:
main.c: In function `mainSetCwd':
main.c:434: parse error before `char'
main.c:435: `p' undeclared (first use in this function)
main.c:435: (Each undeclared identifier is reported only once
main.c:435: for each function it appears in.)
Putting it at the top means you've got to remember to free it where-ever you
return (one other place, admittedly), which means I make the best way to have
that function:
static void
mainSetCwd(void)
{
char *p;
if (Config.coredump_dir) {
if (!chdir(Config.coredump_dir)) {
debug(0, 1) ("Set Current Directory to %s\n", Config.coredump_dir);
return;
} else {
debug(50, 0) ("chdir: %s: %s\n", Config.coredump_dir, xstrerror());
}
}
/* If we don't have coredump_dir or couldn't cd there, report current dir */
p = getcwd(NULL, 0);
debug(0, 1) ("Current Directory is %s\n", p);
xfree(p);
}
(Note, definition and use seperated - my patch didn't do that). I just
checked out the main branch, and your mainSetCwd doesn't have a declaration for
p in it - it just uses, then frees it. Patch would be:
$ diff -u main.c ../../../squid/src/main.c
--- main.c Tue Jan 30 21:09:26 2001
+++ ../../../squid/src/main.c Wed Jan 31 10:20:22 2001
@@ -1,6 +1,6 @@
/*
- * $Id: main.c,v 1.18 2001/01/30 10:09:26 hno Exp $
+ * $Id: main.c,v 1.17 2001/01/12 08:20:33 hno Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
@@ -422,6 +422,7 @@
static void
mainSetCwd(void)
{
+ char *p;
if (Config.coredump_dir) {
if (!chdir(Config.coredump_dir)) {
debug(0, 1) ("Set Current Directory to %s\n", Config.coredump_dir);
@@ -430,9 +431,10 @@
debug(50, 0) ("chdir: %s: %s\n", Config.coredump_dir, xstrerror());
}
}
+ /* If we don't have coredump_dir or couldn't cd there, report current dir */
+ p = getcwd(NULL, 0);
debug(0, 1) ("Current Directory is %s\n", p);
xfree(p);
- return;
}
static void
KevinL
(Who solemnly swears to compile before submitting, no matter how trivial)
>>> Henrik Nordstrom wrote
> Kevin Littlejohn wrote:
>
> > Um - I realised afterwards that the "char *p = getcwd(NULL, 0);" line
> > needs splitting into char *p; and p = getcwd...
> >
> > Dunno whether you spotted that or not ;)
>
> Did not spot it, or realize why it should be required..
>
> --
> Henrik Nordstrom
> Squid hacker
>
Received on Tue Jan 30 2001 - 16:29:44 MST
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:13:26 MST