Need a getwd call. (Not getcwd).

Sean Eric Fagan sef at kithrup.COM
Tue Jun 25 12:14:53 AEST 1991


In article <1991Jun25.001136.3202 at virtech.uucp> cpcahil at virtech.uucp (Conor P. Cahill) writes:
>Here is the source code to BSDs getwd() function.  You will probably have
>to modify the directory processing portion of the code but the changes
>should be minimal.  Have fun.

And here are patches to make it work for SCO *nix.  They should be pretty
generic for SysVr3.2 for the '386, though.

*** getwd.c.orig	Mon Jun 24 19:13:28 1991
--- getwd.c	Mon Jun 24 19:03:31 1991
***************
*** 21,35 ****
--- 21,48 ----
  static char sccsid[] = "@(#)getwd.c	5.8 (Berkeley) 6/1/90";
  #endif /* LIBC_SCCS and not lint */
  
+ #include <sys/types.h>
  #include <sys/param.h>
  #include <sys/stat.h>
  #include <dirent.h>
  #include <string.h>
  
+ #ifdef	PATHSIZE
+ #	define	MAXPATHLEN	PATHSIZE
+ #endif
+ 
  #define	ISDOT(dp) \
  	(dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \
  	    dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
  
+ #if	defined(USG) && !defined(HAVE_SYMLINKS)
+ #	define	lstat	stat
+ #endif
+ 
+ #if defined(USG) && !defined(dirfd)
+ #	define	dirfd(x)	((x)->dd_fd)
+ #endif
+ 
  char *
  getwd(store)
  	char *store;
***************
*** 100,112 ****
--- 113,133 ----
  		 */
  		if (s.st_dev == dev) {
  			while (dp = readdir(dir))
+ #ifdef	USG
+ 				if (dp->d_ino == ino)
+ #else
  				if (dp->d_fileno == ino)
+ #endif
  					goto hit;
  		} else {
  			while (dp = readdir(dir)) {
  				if (ISDOT(dp))
  					continue;
+ #ifdef	USG
+ 				memcpy(pu, dp->d_name, strlen(dp->d_name) + 1);
+ #else
  				bcopy(dp->d_name, pu, dp->d_namlen + 1);
+ #endif
  				if (lstat(up, &s)) {
  					file = dp->d_name;
  					save_errno = errno;
***************
*** 116,123 ****
--- 137,149 ----
  				if (s.st_dev == dev && s.st_ino == ino) {
  hit:					if (!first)
  						*--pp = '/';
+ #ifdef	USG
+ 					pp -= strlen(dp->d_name);
+ 					memcpy(pp, dp->d_name, strlen(dp->d_name));
+ #else
  					pp -= dp->d_namlen;
  					bcopy(dp->d_name, pp, dp->d_namlen);
+ #endif
  					found = 1;
  					break;
  				}
-- 
Sean Eric Fagan  | "What *does* that 33 do?  I have no idea."
sef at kithrup.COM  |           -- Chris Torek
-----------------+              (torek at ee.lbl.gov)
Any opinions expressed are my own, and generally unpopular with others.



More information about the Comp.unix.sysv386 mailing list