Annotation of researchv10no/cmd/odist/opkg/pwd.c, revision 1.1.1.1

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: #include <libv.h>
                      8: #include <stdio.h>
                      9: 
                     10: #define CHUNK 64
                     11: 
                     12: char *
                     13: pwd(void)
                     14: {
                     15:        register FILE *f;
                     16:        static char *r;
                     17:        static unsigned size;
                     18:        register int n, c;
                     19: 
                     20:        if (r == NULL) {
                     21:                f = popen ("pwd", "r");
                     22:                schk ((char *) f);
                     23:                
                     24:                n = 0;
                     25:                while ((c = getc (f)) != EOF) {
                     26:                        if (n >= size) {
                     27:                                size += CHUNK;
                     28:                                r = ralloc (r, size);
                     29:                        }
                     30:                        r[n++] = c;
                     31:                }
                     32: 
                     33:                /* replace the trailing newline by a null */
                     34:                r[n - 1] = '\0';
                     35: 
                     36:                pclose (f);
                     37:        }
                     38: 
                     39:        return r;
                     40: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.