xref: /illumos-gate/usr/src/lib/libpkg/common/ppkgmap.c (revision e71ca95ca6de23d33b54cb55cefdef30bc7c969b)
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
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 #ifdef SUNOS41
69 		if (ept->ainfo.xmajor == BADMAJOR) {
70 			if (fprintf(fp, " ?") < 0)
71 				return (-1);
72 		} else {
73 			if (fprintf(fp, " %d", ept->ainfo.xmajor) < 0)
74 				return (-1);
75 		}
76 #else
77 		if (ept->ainfo.major == BADMAJOR) {
78 			if (fprintf(fp, " ?") < 0)
79 				return (-1);
80 		} else {
81 			if (fprintf(fp, " %d", ept->ainfo.major) < 0)
82 				return (-1);
83 		}
84 #endif
85 #ifdef SUNOS41
86 		if (ept->ainfo.xminor == BADMINOR) {
87 			if (fprintf(fp, " ?") < 0)
88 				return (-1);
89 		} else {
90 			if (fprintf(fp, " %d", ept->ainfo.xminor) < 0)
91 				return (-1);
92 		}
93 #else
94 		if (ept->ainfo.minor == BADMINOR) {
95 			if (fprintf(fp, " ?") < 0)
96 				return (-1);
97 		} else {
98 			if (fprintf(fp, " %d", ept->ainfo.minor) < 0)
99 				return (-1);
100 		}
101 #endif
102 	}
103 
104 	if (strchr("dxcbpfve", ept->ftype)) {
105 		if (fprintf(fp, ((ept->ainfo.mode == BADMODE) ? " ?" : " %04o"),
106 		    ept->ainfo.mode) < 0)
107 			return (-1);
108 		if (fprintf(fp, " %s %s", ept->ainfo.owner, ept->ainfo.group) <
109 		    0)
110 			return (-1);
111 	}
112 	if (holdcinfo) {
113 		if (fputc('\n', fp) == EOF)
114 			return (-1);
115 		return (0);
116 	}
117 
118 	if (strchr("ifve", ept->ftype)) {
119 		if (fprintf(fp, ((ept->cinfo.size == BADCONT) ? " ?" : " %llu"),
120 		    ept->cinfo.size) < 0)
121 			return (-1);
122 		if (fprintf(fp, ((ept->cinfo.cksum == BADCONT) ? " ?" : " %ld"),
123 		    ept->cinfo.cksum) < 0)
124 			return (-1);
125 		if (fprintf(fp,
126 		    ((ept->cinfo.modtime == BADCONT) ? " ?" : " %ld"),
127 		    ept->cinfo.modtime) < 0)
128 			return (-1);
129 	}
130 
131 	if (ept->ftype == 'i') {
132 		if (fputc('\n', fp) == EOF)
133 			return (-1);
134 		return (0);
135 	}
136 	if (fprintf(fp, "\n") < 0)
137 		return (-1);
138 	return (0);
139 }
140