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.5 (Berkeley) 12/15/91"; 16 #endif /* not lint */ 17 18 #include <sys/types.h> 19 #include <unistd.h> 20 #include <stdlib.h> 21 #include <errno.h> 22 #include <stdio.h> 23 #include <string.h> 24 25 void usage __P((void)); 26 27 int 28 main(argc, argv) 29 int argc; 30 char *argv[]; 31 { 32 int ch; 33 char *p; 34 35 while ((ch = getopt(argc, argv, "")) != EOF) 36 switch(ch) { 37 case '?': 38 default: 39 usage(); 40 } 41 argc -= optind; 42 argv += optind; 43 44 if (argc != 0) 45 usage(); 46 47 p = getcwd(NULL, 0); 48 if (p) { 49 (void)printf("%s\n", p); 50 exit(0); 51 } 52 (void)fprintf(stderr, "pwd: %s\n", strerror(errno)); 53 exit(1); 54 } 55 56 void 57 usage() 58 { 59 (void)fprintf(stderr, "usage: pwd\n"); 60 exit(1); 61 } 62