Date: Thu, 13 Nov 1997 12:34:35 +0200 (IST) From: Eli Zaretskii To: sl cc: DJGPP mailing list Subject: Re: getcwd() In-Reply-To: <199711122340.SAA13067@delorie.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Wed, 12 Nov 1997, sl wrote: > (...) > char result[MAX_PATH]; > strcmp(result, getcwd(NULL, 0)); > (...) > > Does this cause a pointer to be lost forever? Is a "free()" missing > here on the result of getcwd()? Yes and yes. You should use either this: char result[MAX_PATH]; char try[MAX_PATH]; if (strcmp (result, getcwd (try, MAX_PATH)) == 0) do_something (); or this: char result[MAX_PATH]; char *p; if (strcmp (result, (p = getcwd ((char *)0, MAX_PATH))) == 0) { do_something (); free (p); } And, btw, the call "getcwd(NULL, 0)" will ALWAYS fail because the second argument says what's the max number of bytes `getcwd' is allowed to return, even if the first argument is a null pointer. (This is explicitly explained in the library reference).