24f091624808faece1c9d9697ec7391ac4f5a68d
11 stralloc target
= {0};
14 #define FATAL "install: fatal: "
15 void nomem() { strerr_die2x(111,FATAL
,"out of memory"); }
17 char inbuf
[SUBSTDIO_INSIZE
];
18 char outbuf
[SUBSTDIO_OUTSIZE
];
40 x
= line
->s
; xlen
= line
->len
;
43 i
= byte_chr(x
,xlen
,':'); if (i
== xlen
) return;
44 x
[i
++] = 0; x
+= i
; xlen
-= i
;
47 i
= byte_chr(x
,xlen
,':'); if (i
== xlen
) return;
48 x
[i
++] = 0; x
+= i
; xlen
-= i
;
51 i
= byte_chr(x
,xlen
,':'); if (i
== xlen
) return;
52 x
[i
++] = 0; x
+= i
; xlen
-= i
;
55 i
= byte_chr(x
,xlen
,':'); if (i
== xlen
) return;
56 x
[i
++] = 0; x
+= i
; xlen
-= i
;
59 i
= byte_chr(x
,xlen
,':'); if (i
== xlen
) return;
60 x
[i
++] = 0; x
+= i
; xlen
-= i
;
63 i
= byte_chr(x
,xlen
,':'); if (i
== xlen
) return;
64 x
[i
++] = 0; x
+= i
; xlen
-= i
;
66 if (!stralloc_copys(&target
,to
)) nomem();
67 if (!stralloc_cats(&target
,mid
)) nomem();
68 if (!stralloc_cats(&target
,name
)) nomem();
69 if (!stralloc_0(&target
)) nomem();
71 uid
= -1; if (*uidstr
) scan_ulong(uidstr
,&uid
);
72 gid
= -1; if (*gidstr
) scan_ulong(gidstr
,&gid
);
73 scan_8long(modestr
,&mode
);
77 if (mkdir(target
.s
,0700) == -1)
78 if (errno
!= error_exist
)
79 strerr_die4sys(111,FATAL
,"unable to mkdir ",target
.s
,": ");
83 fdin
= open_read(name
);
85 strerr_die4sys(111,FATAL
,"unable to read ",name
,": ");
86 substdio_fdbuf(&ssin
,read
,fdin
,inbuf
,sizeof(inbuf
));
88 fdout
= open_trunc(target
.s
);
90 strerr_die4sys(111,FATAL
,"unable to write ",target
.s
,": ");
91 substdio_fdbuf(&ssout
,write
,fdout
,outbuf
,sizeof(outbuf
));
93 switch(substdio_copy(&ssout
,&ssin
)) {
95 strerr_die4sys(111,FATAL
,"unable to read ",name
,": ");
97 strerr_die4sys(111,FATAL
,"unable to write ",target
.s
,": ");
101 if (substdio_flush(&ssout
) == -1)
102 strerr_die4sys(111,FATAL
,"unable to write ",target
.s
,": ");
103 if (fsync(fdout
) == -1)
104 strerr_die4sys(111,FATAL
,"unable to write ",target
.s
,": ");
112 if (chown(target
.s
,uid
,gid
) == -1)
113 strerr_die4sys(111,FATAL
,"unable to chown ",target
.s
,": ");
114 if (chmod(target
.s
,mode
) == -1)
115 strerr_die4sys(111,FATAL
,"unable to chmod ",target
.s
,": ");
119 substdio in
= SUBSTDIO_FDBUF(read
,0,buf
,sizeof(buf
));
131 if (!to
) strerr_die2x(100,FATAL
,"install: usage: install dir");
134 if (getln(&in
,&line
,&match
,'\n') == -1)
135 strerr_die2sys(111,FATAL
,"unable to read input: ");