xref: /original-bsd/bin/pwd/pwd.c (revision 9e86b9c3)
1 /*
2  * Copyright (c) 1991 Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 char copyright[] =
10 "@(#) Copyright (c) 1991 Regents of the University of California.\n\
11  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)pwd.c	5.6 (Berkeley) 04/29/93";
16 #endif /* not lint */
17 
18 #include <sys/types.h>
19 
20 #include <err.h>
21 #include <errno.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 
27 void usage __P((void));
28 
29 int
30 main(argc, argv)
31 	int argc;
32 	char *argv[];
33 {
34 	int ch;
35 	char *p;
36 
37 	while ((ch = getopt(argc, argv, "")) != EOF)
38 		switch (ch) {
39 		case '?':
40 		default:
41 			usage();
42 		}
43 	argc -= optind;
44 	argv += optind;
45 
46 	if (argc != 0)
47 		usage();
48 
49 	if ((p = getcwd(NULL, 0)) == NULL) {
50 		err(1, NULL);
51 		exit(1);
52 	}
53 	(void)printf("%s\n", p);
54 	exit(0);
55 }
56 
57 void
58 usage()
59 {
60 	(void)fprintf(stderr, "usage: pwd\n");
61 	exit(1);
62 }
63