1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
29
30
31
32 #include <stdio.h>
33 #include <string.h>
34 #include <limits.h>
35 #include <stdlib.h>
36 #include <unistd.h>
37 #include <sys/types.h>
38 #include "pkgstrct.h"
39
40 int holdcinfo = 0;
41
42 int
ppkgmap(struct cfent * ept,FILE * fp)43 ppkgmap(struct cfent *ept, FILE *fp)
44 {
45 if (ept->path == NULL)
46 return (-1);
47
48 if (ept->volno) {
49 if (fprintf(fp, "%d ", ept->volno) < 0)
50 return (-1);
51 }
52
53 if (ept->ftype == 'i') {
54 if (fprintf(fp, "%c %s", ept->ftype, ept->path) < 0)
55 return (-1);
56 } else {
57 if (fprintf(fp, "%c %s %s", ept->ftype, ept->pkg_class,
58 ept->path) < 0)
59 return (-1);
60 }
61
62 if (ept->ainfo.local) {
63 if (fprintf(fp, "=%s", ept->ainfo.local) < 0)
64 return (-1);
65 }
66
67 if (strchr("cb", ept->ftype)) {
68 if (ept->ainfo.major == BADMAJOR) {
69 if (fprintf(fp, " ?") < 0)
70 return (-1);
71 } else {
72 if (fprintf(fp, " %ld", ept->ainfo.major) < 0)
73 return (-1);
74 }
75 if (ept->ainfo.minor == BADMINOR) {
76 if (fprintf(fp, " ?") < 0)
77 return (-1);
78 } else {
79 if (fprintf(fp, " %ld", ept->ainfo.minor) < 0)
80 return (-1);
81 }
82 }
83
84 if (strchr("dxcbpfve", ept->ftype)) {
85 if (fprintf(fp, ((ept->ainfo.mode == BADMODE) ? " ?" : " %04o"),
86 ept->ainfo.mode) < 0)
87 return (-1);
88 if (fprintf(fp, " %s %s", ept->ainfo.owner, ept->ainfo.group) <
89 0)
90 return (-1);
91 }
92 if (holdcinfo) {
93 if (fputc('\n', fp) == EOF)
94 return (-1);
95 return (0);
96 }
97
98 if (strchr("ifve", ept->ftype)) {
99 if (fprintf(fp, ((ept->cinfo.size == BADCONT) ? " ?" : " %llu"),
100 ept->cinfo.size) < 0)
101 return (-1);
102 if (fprintf(fp, ((ept->cinfo.cksum == BADCONT) ? " ?" : " %ld"),
103 ept->cinfo.cksum) < 0)
104 return (-1);
105 if (fprintf(fp,
106 ((ept->cinfo.modtime == BADCONT) ? " ?" : " %ld"),
107 ept->cinfo.modtime) < 0)
108 return (-1);
109 }
110
111 if (ept->ftype == 'i') {
112 if (fputc('\n', fp) == EOF)
113 return (-1);
114 return (0);
115 }
116 if (fprintf(fp, "\n") < 0)
117 return (-1);
118 return (0);
119 }
120