Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!kithrup!sef From: sef@kithrup.COM (Sean Eric Fagan) Newsgroups: comp.unix.sysv386 Subject: Re: Need a getwd call. (Not getcwd). Message-ID: <1991Jun25.021453.26997@kithrup.COM> Date: 25 Jun 91 02:14:53 GMT References: <1991Jun24.204808.22333@world.std.com> <1991Jun25.001136.3202@virtech.uucp> Organization: Kithrup Enterprises, Ltd. Lines: 86 In article <1991Jun25.001136.3202@virtech.uucp> cpcahil@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 #include #include #include #include + #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@kithrup.COM | -- Chris Torek -----------------+ (torek@ee.lbl.gov) Any opinions expressed are my own, and generally unpopular with others.