8 extern void hier(char *);
10 #define FATAL "install: fatal: "
14 void h(home
,uid
,gid
,mode
)
20 if (mkdir(home
,0700) == -1)
21 if (errno
!= error_exist
)
22 strerr_die4sys(111,FATAL
,"unable to mkdir ",home
,": ");
23 if (chown(home
,uid
,gid
) == -1)
24 strerr_die4sys(111,FATAL
,"unable to chown ",home
,": ");
25 if (chmod(home
,mode
) == -1)
26 strerr_die4sys(111,FATAL
,"unable to chmod ",home
,": ");
29 void d(home
,subdir
,uid
,gid
,mode
)
36 if (chdir(home
) == -1)
37 strerr_die4sys(111,FATAL
,"unable to switch to ",home
,": ");
38 if (mkdir(subdir
,0700) == -1)
39 if (errno
!= error_exist
)
40 strerr_die6sys(111,FATAL
,"unable to mkdir ",home
,"/",subdir
,": ");
41 if (chown(subdir
,uid
,gid
) == -1)
42 strerr_die6sys(111,FATAL
,"unable to chown ",home
,"/",subdir
,": ");
43 if (chmod(subdir
,mode
) == -1)
44 strerr_die6sys(111,FATAL
,"unable to chmod ",home
,"/",subdir
,": ");
47 char inbuf
[SUBSTDIO_INSIZE
];
48 char outbuf
[SUBSTDIO_OUTSIZE
];
52 void c(home
,subdir
,file
,uid
,gid
,mode
)
63 if (fchdir(fdsourcedir
) == -1)
64 strerr_die2sys(111,FATAL
,"unable to switch back to source directory: ");
66 fdin
= open_read(file
);
68 strerr_die4sys(111,FATAL
,"unable to read ",file
,": ");
69 substdio_fdbuf(&ssin
,read
,fdin
,inbuf
,sizeof inbuf
);
71 if (chdir(home
) == -1)
72 strerr_die4sys(111,FATAL
,"unable to switch to ",home
,": ");
73 if (chdir(subdir
) == -1)
74 strerr_die6sys(111,FATAL
,"unable to switch to ",home
,"/",subdir
,": ");
76 fdout
= open_trunc(file
);
78 strerr_die6sys(111,FATAL
,"unable to write .../",subdir
,"/",file
,": ");
79 substdio_fdbuf(&ssout
,write
,fdout
,outbuf
,sizeof outbuf
);
81 switch(substdio_copy(&ssout
,&ssin
)) {
83 strerr_die4sys(111,FATAL
,"unable to read ",file
,": ");
85 strerr_die6sys(111,FATAL
,"unable to write .../",subdir
,"/",file
,": ");
89 if (substdio_flush(&ssout
) == -1)
90 strerr_die6sys(111,FATAL
,"unable to write .../",subdir
,"/",file
,": ");
91 if (fsync(fdout
) == -1)
92 strerr_die6sys(111,FATAL
,"unable to write .../",subdir
,"/",file
,": ");
93 if (close(fdout
) == -1) /* NFS silliness */
94 strerr_die6sys(111,FATAL
,"unable to write .../",subdir
,"/",file
,": ");
96 if (chown(file
,uid
,gid
) == -1)
97 strerr_die6sys(111,FATAL
,"unable to chown .../",subdir
,"/",file
,": ");
98 if (chmod(file
,mode
) == -1)
99 strerr_die6sys(111,FATAL
,"unable to chmod .../",subdir
,"/",file
,": ");
102 void main(int argc
, char *argv
[])
105 fdsourcedir
= open_read(".");
108 if (fdsourcedir
== -1)
109 strerr_die2sys(111,FATAL
,"unable to open current directory: ");