From owner-freebsd-hackers Sat Jan 7 12:14:45 1995 Return-Path: hackers-owner Received: (from root@localhost) by freefall.cdrom.com (8.6.9/8.6.6) id MAA25113 for hackers-outgoing; Sat, 7 Jan 1995 12:14:45 -0800 Received: from reggae.ncren.net (reggae.ncren.net [128.109.131.3]) by freefall.cdrom.com (8.6.9/8.6.6) with ESMTP id MAA25107 for ; Sat, 7 Jan 1995 12:14:44 -0800 Received: from ponds.UUCP by reggae.ncren.net (5.65/tas-reggae/may94) id AA23608; Sat, 7 Jan 95 15:14:17 -0500 Received: (rivers@localhost) by ponds.UUCP (8.6.9/8.6.5) id MAA06088; Sat, 7 Jan 1995 12:59:10 -0500 Date: Sat, 7 Jan 1995 12:59:10 -0500 From: Thomas David Rivers Message-Id: <199501071759.MAA06088@ponds.UUCP> To: freebsd-bugs@freefall.cdrom.com, freebsd-hackers@freefall.cdrom.com Subject: getwd() bug remains... Sender: hackers-owner@FreeBSD.org Precedence: bulk Several months ago I sparked a small debate about correcting getwd() when the size of the argument buffer isn't large enough to contain MAXPATHLEN characters. In this instance, the call to getwd() *always* dumps core. Although the man page does indicate that getwd of anything less than MAXPATHLEN is a no-no, in my opinion, it shouldn't automatically dump core no matter what. Certainly, that was not the behaviour getwd() had in the past, and the entire point of the compat-43 routines is to be compatible (as best as possible) with prior behaviour. Unfortunately, when rebuilding some of my (admittedly very old) programs, I ran into exactly the same problem again. I discovered that lib/libc/compat-43/getwd.c had not yet been changed. I proposed the following routine, which will only dump core when the actual directory name is larger than the argument buffer, not every time: char * getwd(buf) char *buf; { char tbuf[MAXPATHLEN]; if (getcwd(tbuf, MAXPATHLEN)) { strcpy(buf, tbuf); return buf; } (void)strcpy(buf, strerror(errno)); return((char *)NULL); } could someone _please_ commit this to 2.1 (or 2.0.5 if that ever occurs.) - Thanks - - Dave Rivers -