12 stralloc target = {0};
15 #define FATAL "install: fatal: "
16 void nomem() { strerr_die2x(111,FATAL,"out of memory"); }
18 char inbuf[SUBSTDIO_INSIZE];
19 char outbuf[SUBSTDIO_OUTSIZE];
42 x = line->s; xlen = line->len;
45 i = byte_chr(x,xlen,':'); if (i == xlen) return;
46 x[i++] = 0; x += i; xlen -= i;
49 i = byte_chr(x,xlen,':'); if (i == xlen) return;
50 x[i++] = 0; x += i; xlen -= i;
53 i = byte_chr(x,xlen,':'); if (i == xlen) return;
54 x[i++] = 0; x += i; xlen -= i;
57 i = byte_chr(x,xlen,':'); if (i == xlen) return;
58 x[i++] = 0; x += i; xlen -= i;
61 i = byte_chr(x,xlen,':'); if (i == xlen) return;
62 x[i++] = 0; x += i; xlen -= i;
65 i = byte_chr(x,xlen,':'); if (i == xlen) return;
66 x[i++] = 0; x += i; xlen -= i;
68 if (!stralloc_copys(&target,to)) nomem();
69 if (!stralloc_cats(&target,mid)) nomem();
70 if (!stralloc_cats(&target,name)) nomem();
71 if (!stralloc_0(&target)) nomem();
73 uid = -1; if (*uidstr) scan_ulong(uidstr,&uid);
74 gid = -1; if (*gidstr) scan_ulong(gidstr,&gid);
75 scan_8long(modestr,&mode);
79 scan_ulong(type + 1,&zlen);
81 fdout = open_trunc(target.s);
83 strerr_die4sys(111,FATAL,"unable to write ",target.s,": ");
84 substdio_fdbuf(&ssout,write,fdout,outbuf,sizeof(outbuf));
87 if (substdio_put(&ssout,"",1) == -1)
88 strerr_die4sys(111,FATAL,"unable to write ",target.s,": ");
90 if (substdio_flush(&ssout) == -1)
91 strerr_die4sys(111,FATAL,"unable to write ",target.s,": ");
92 if (fsync(fdout) == -1)
93 strerr_die4sys(111,FATAL,"unable to write ",target.s,": ");
98 if (fifo_make(target.s,0700) == -1)
99 if (errno != error_exist)
100 strerr_die4sys(111,FATAL,"unable to mkfifo ",target.s,": ");
104 if (mkdir(target.s,0700) == -1)
105 if (errno != error_exist)
106 strerr_die4sys(111,FATAL,"unable to mkdir ",target.s,": ");
110 fdin = open_read(name);
112 strerr_die4sys(111,FATAL,"unable to read ",name,": ");
113 substdio_fdbuf(&ssin,read,fdin,inbuf,sizeof(inbuf));
115 fdout = open_trunc(target.s);
117 strerr_die4sys(111,FATAL,"unable to write ",target.s,": ");
118 substdio_fdbuf(&ssout,write,fdout,outbuf,sizeof(outbuf));
120 switch(substdio_copy(&ssout,&ssin)) {
122 strerr_die4sys(111,FATAL,"unable to read ",name,": ");
124 strerr_die4sys(111,FATAL,"unable to write ",target.s,": ");
128 if (substdio_flush(&ssout) == -1)
129 strerr_die4sys(111,FATAL,"unable to write ",target.s,": ");
130 if (fsync(fdout) == -1)
131 strerr_die4sys(111,FATAL,"unable to write ",target.s,": ");
139 if (chown(target.s,uid,gid) == -1)
140 strerr_die4sys(111,FATAL,"unable to chown ",target.s,": ");
141 if (chmod(target.s,mode) == -1)
142 strerr_die4sys(111,FATAL,"unable to chmod ",target.s,": ");
146 substdio in = SUBSTDIO_FDBUF(read,0,buf,sizeof(buf));
158 if (!to) strerr_die2x(100,FATAL,"install: usage: install dir");
161 if (getln(&in,&line,&match,'\n') == -1)
162 strerr_die2sys(111,FATAL,"unable to read input: ");