prettyness police
[unix-history] / usr / src / bin / pwd / pwd.c
CommitLineData
bcf1365c 1/*
84dded44 2 * Copyright (c) 1991, 1993, 1994
cd5a06d8 3 * The Regents of the University of California. All rights reserved.
32c6fcda 4 *
27c71911 5 * %sccs.include.redist.c%
bcf1365c
DF
6 */
7
8#ifndef lint
cd5a06d8 9static char copyright[] =
84dded44 10"@(#) Copyright (c) 1991, 1993, 1994\n\
cd5a06d8 11 The Regents of the University of California. All rights reserved.\n";
32c6fcda 12#endif /* not lint */
bcf1365c
DF
13
14#ifndef lint
706c0358 15static char sccsid[] = "@(#)pwd.c 8.3 (Berkeley) %G%";
32c6fcda 16#endif /* not lint */
bcf1365c 17
1ade9c9b 18#include <err.h>
7a02fcc7 19#include <stdio.h>
1ade9c9b 20#include <stdlib.h>
1ade9c9b 21#include <unistd.h>
1b66014a 22
2a017f09
KB
23void usage __P((void));
24
25int
26main(argc, argv)
27 int argc;
28 char *argv[];
1b66014a 29{
2a017f09 30 int ch;
5b7f648b 31 char *p;
1b66014a 32
84dded44
KB
33 /*
34 * Flags for pwd are a bit strange. The POSIX 1003.2B/D9 document
35 * has an optional -P flag for physical, which is what this program
36 * will produce by default. The logical flag, -L, should fail, as
37 * there's no way to display a logical path after forking. We don't
38 * document either flag, only adding -P for future portability.
39 */
40 while ((ch = getopt(argc, argv, "P")) != EOF)
1ade9c9b 41 switch (ch) {
84dded44
KB
42 case 'P':
43 break;
2a017f09
KB
44 case '?':
45 default:
46 usage();
47 }
48 argc -= optind;
49 argv += optind;
50
51 if (argc != 0)
52 usage();
53
84dded44 54 if ((p = getcwd(NULL, 0)) == NULL)
1ade9c9b 55 err(1, NULL);
1ade9c9b
KB
56 (void)printf("%s\n", p);
57 exit(0);
1b66014a 58}
2a017f09
KB
59
60void
61usage()
62{
706c0358 63
2a017f09
KB
64 (void)fprintf(stderr, "usage: pwd\n");
65 exit(1);
66}