1 /*
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * %sccs.include.redist.c%
6 */
7
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1991, 1993, 1994\n\
11 The Regents of the University of California. All rights reserved.\n";
12 #endif /* not lint */
13
14 #ifndef lint
15 static char sccsid[] = "@(#)pwd.c 8.3 (Berkeley) 04/01/94";
16 #endif /* not lint */
17
18 #include <err.h>
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22
23 void usage __P((void));
24
25 int
main(argc,argv)26 main(argc, argv)
27 int argc;
28 char *argv[];
29 {
30 int ch;
31 char *p;
32
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)
41 switch (ch) {
42 case 'P':
43 break;
44 case '?':
45 default:
46 usage();
47 }
48 argc -= optind;
49 argv += optind;
50
51 if (argc != 0)
52 usage();
53
54 if ((p = getcwd(NULL, 0)) == NULL)
55 err(1, NULL);
56 (void)printf("%s\n", p);
57 exit(0);
58 }
59
60 void
usage()61 usage()
62 {
63
64 (void)fprintf(stderr, "usage: pwd\n");
65 exit(1);
66 }
67