|
|
1.1 root 1: /*
2: * pwd() - return the name of the current directory.
3: * We assume that the current directory never changes.
4: */
5:
6: #include "asd.h"
7:
8: #define CHUNK 64
9:
10: char *
11: pwd()
12: {
13: register FILE *f;
14: static char *r;
15: static unsigned size;
16: register int n, c;
17:
18: if (r == NULL) {
19: f = popen ("pwd", "r");
20: schk ((char *) f);
21:
22: n = 0;
23: while ((c = getc (f)) != EOF) {
24: if (n >= size) {
25: size += CHUNK;
26: r = ralloc (r, size);
27: }
28: r[n++] = c;
29: }
30:
31: /* replace the trailing newline by a null */
32: r[n - 1] = '\0';
33:
34: pclose (f);
35: }
36:
37: return r;
38: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.