|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 1754 (0x6da) Types: TextFile Notes: UNIX file Names: »getwd.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code └─⟦f4b8d8c84⟧ UNIX Filesystem └─⟦this⟧ »libc/gen/getwd.c«
/* * Return a static string containing the current * working directory for this process. * (Warning: this call may change the current directory * of the process if for any reason it fails.) */ #include <stdio.h> #include <types.h> #include <stat.h> #include <dir.h> #include <canon.h> #define MAXNAME 400 /* Longest pathname */ extern int errno; char * getwd() { struct stat d, dd; struct direct dir; static char fnbuf[MAXNAME]; register char *cp, *dp; register int file; register dev_t rdev; register ino_t rino; errno = 0; dp = fnbuf+MAXNAME-1; *dp = '\0'; if (stat("/", &d) < 0) return (NULL); rdev = d.st_dev; rino = d.st_ino; while (stat(".", &d)>=0 && (d.st_ino!=rino || d.st_dev!=rdev)) { if ((file = open("..", 0)) < 0) return (NULL); if (fstat(file, &dd)<0 || chdir("..")<0) { close(file); return (NULL); } if (d.st_dev == dd.st_dev) { if (d.st_ino == dd.st_ino) { close(file); break; } do { if (read(file, (char *)&dir, sizeof (dir)) != sizeof (dir)) { close(file); return (NULL); } canino(dir.d_ino); } while (dir.d_ino != d.st_ino); } else do { if (read(file, (char *)&dir, sizeof (dir)) != sizeof (dir)) { close(file); return (NULL); } canino(dir.d_ino); if (dir.d_ino!=0 && stat(dir.d_name, &dd)<0) { close(file); return (NULL); } } while (dd.st_ino!=d.st_ino || dd.st_dev!=d.st_dev); close(file); if (dp-DIRSIZ <= fnbuf) return (NULL); for (cp=dir.d_name; cp!=dir.d_name+DIRSIZ && *cp!='\0'; cp++) ; while (cp > dir.d_name) *--dp = *--cp; *--dp = '/'; } if (errno) return (NULL); if (*dp != '/') *--dp = '/'; if (chdir(dp) < 0) return (NULL); return (dp); }