Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / pcc / dist / pcc-libs / libI77 / pwd.c
blob0856dff74872c34cdcb81950c43fe21e79dd8e8b
1 /* $Id: pwd.c,v 1.1.1.1 2008/08/24 05:34:47 gmcgarry Exp $ */
2 /*
3 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
9 * Redistributions of source code and documentation must retain the above
10 * copyright notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditionsand the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed or owned by Caldera
17 * International, Inc.
18 * Neither the name of Caldera International, Inc. nor the names of other
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
22 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27 * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
36 * Print working (current) directory
38 #include <sys/types.h>
39 #include <sys/stat.h>
40 #include <sys/dir.h>
42 char dot[] ".";
43 char dotdot[] "..";
44 char root[] "/";
45 char name[512];
46 int file;
47 int off -1;
48 struct stat x;
49 struct direct y;
51 main()
53 for (;;) {
54 stat(dot, &x);
55 if ((file = open(dotdot,0)) < 0) prname();
56 do {
57 if (read(file, &y, sizeof(y)) < sizeof(y))
58 prname();
59 } while (y.d_ino != x.st_ino);
60 close(file);
61 if (y.d_ino == 2)
62 ckroot();
63 cat();
64 chdir(dotdot);
68 ckroot()
70 register i;
72 if (stat(y.d_name,&x)<0 || chdir(root)<0 || (file=open(root,0))<0)
73 prname();
74 i = x.st_dev;
75 do {
76 if (read(file,&y,sizeof(y)) < sizeof(y))
77 prname();
78 if (y.d_ino == 0)
79 continue;
80 if (stat(y.d_name,&x) < 0)
81 prname();
82 } while (x.st_dev!=i || (x.st_mode&S_IFMT)!=S_IFDIR);
83 if (strcmp(dot, y.d_name) || strcmp(dotdot, y.d_name))
84 cat();
85 write(1, root, 1);
86 prname();
89 prname()
91 if (off<0)
92 off = 0;
93 name[off] = '\n';
94 write(1, name, off+1);
95 exit(0);
98 cat()
100 register i, j;
102 i = -1;
103 while (y.d_name[++i] != 0);
104 if ((off+i+2) > 511)
105 prname();
106 for(j=off+1; j>=0; --j)
107 name[j+i+1] = name[j];
108 off=i+off+1;
109 name[i] = root[0];
110 for(--i; i>=0; --i)
111 name[i] = y.d_name[i];