@@ -110,12 +110,10 @@ archive_dict(struct archive *ar, const char *filename, xbps_dictionary_t dict)
110110 errno = 0 ;
111111 buf = xbps_dictionary_externalize (dict );
112112 if (!buf ) {
113- r = - errno ;
114- xbps_error_printf ("failed to externalize dictionary for: %s\n" ,
115- filename );
116- if (r == 0 )
117- return - EINVAL ;
118- return 0 ;
113+ if (errno == 0 )
114+ errno = EINVAL ;
115+ return xbps_error_errno (errno ,
116+ "failed to externalize dictionary for: %s\n" , filename );
119117 }
120118
121119 r = xbps_archive_append_buf (ar , buf , strlen (buf ), filename , 0644 ,
@@ -147,23 +145,23 @@ repodata_flush(const char *repodir,
147145
148146 r = snprintf (path , sizeof (path ), "%s/%s-repodata" , repodir , arch );
149147 if (r < 0 || (size_t )r >= sizeof (tmp )) {
150- xbps_error_printf ("repodata path too long: %s: %s\n" , path ,
148+ return xbps_error_errno (ENAMETOOLONG ,
149+ "repodata path too long: %s: %s\n" , path ,
151150 strerror (ENAMETOOLONG ));
152- return - ENAMETOOLONG ;
153151 }
154152
155153 r = snprintf (tmp , sizeof (tmp ), "%s.XXXXXXX" , path );
156154 if (r < 0 || (size_t )r >= sizeof (tmp )) {
157- xbps_error_printf ("repodata tmp path too long: %s: %s\n" , path ,
155+ return xbps_error_errno (ENAMETOOLONG ,
156+ "repodata tmp path too long: %s: %s\n" , path ,
158157 strerror (ENAMETOOLONG ));
159- return - ENAMETOOLONG ;
160158 }
161159
162160 prevumask = umask (S_IXUSR |S_IRWXG |S_IRWXO );
163161 fd = mkstemp (tmp );
164162 if (fd == -1 ) {
165- r = - errno ;
166- xbps_error_printf ( "failed to open temp file: %s: %s" , tmp , strerror (- r ));
163+ r = xbps_error_errno ( errno , "failed to open temp file: %s: %s" ,
164+ tmp , strerror (- r ));
167165 umask (prevumask );
168166 goto err ;
169167 }
@@ -194,8 +192,7 @@ repodata_flush(const char *repodir,
194192 goto err ;
195193 }
196194 if (archive_write_free (ar ) == ARCHIVE_FATAL ) {
197- r = - errno ;
198- xbps_error_printf ("failed to free archive: %s\n" , strerror (- r ));
195+ r = xbps_error_errno (errno , "failed to free archive: %s\n" , strerror (errno ));
199196 goto err ;
200197 }
201198
@@ -206,19 +203,18 @@ repodata_flush(const char *repodir,
206203#endif
207204
208205 if (fchmod (fd , 0664 ) == -1 ) {
209- errno = - r ;
210- xbps_error_printf ("failed to set mode: %s: %s\n" ,
211- tmp , strerror (- r ));
206+ r = xbps_error_errno (errno , "failed to set mode: %s: %s\n" , tmp ,
207+ strerror (errno ));
212208 close (fd );
213209 unlink (tmp );
214210 return r ;
215211 }
216212 close (fd );
217213
218214 if (rename (tmp , path ) == -1 ) {
219- r = - errno ;
220- xbps_error_printf ( "failed to rename repodata: %s: %s: %s\n" ,
221- tmp , path , strerror (- r ));
215+ r = xbps_error_errno ( errno ,
216+ "failed to rename repodata: %s: %s: %s\n" , tmp , path ,
217+ strerror (errno ));
222218 unlink (tmp );
223219 return r ;
224220 }
0 commit comments