bspatch: apply style(9)

Make style changes (and trivial refactoring of open calls) now in order
to reduce noise in diffs for future capsicum changes.

Reviewed by:	oshogbo
No objection:	cperciva
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D7610
This commit is contained in:
Ed Maste 2016-08-23 17:42:03 +00:00
parent e0a66c6379
commit ce437beff1
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=304691

View File

@ -28,12 +28,12 @@
__FBSDID("$FreeBSD$");
#include <bzlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <err.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifndef O_BINARY
#define O_BINARY 0
@ -52,9 +52,10 @@ static off_t offtin(u_char *buf)
y = y * 256; y += buf[1];
y = y * 256; y += buf[0];
if(buf[7]&0x80) y=-y;
if (buf[7] & 0x80)
y = -y;
return y;
return (y);
}
static void
@ -70,7 +71,7 @@ int main(int argc,char * argv[])
FILE *f, *cpf, *dpf, *epf;
BZFILE *cpfbz2, *dpfbz2, *epfbz2;
int cbz2err, dbz2err, ebz2err;
int fd;
int newfd, oldfd;
ssize_t oldsize, newsize;
ssize_t bzctrllen, bzdatalen;
u_char header[32], buf[8];
@ -144,15 +145,20 @@ int main(int argc,char * argv[])
if ((epfbz2 = BZ2_bzReadOpen(&ebz2err, epf, 0, 0, NULL, 0)) == NULL)
errx(1, "BZ2_bzReadOpen, bz2err = %d", ebz2err);
if(((fd=open(argv[1],O_RDONLY|O_BINARY,0))<0) ||
((oldsize=lseek(fd,0,SEEK_END))==-1) ||
((old=malloc(oldsize+1))==NULL) ||
(lseek(fd,0,SEEK_SET)!=0) ||
(read(fd,old,oldsize)!=oldsize) ||
(close(fd)==-1)) err(1,"%s",argv[1]);
if((new=malloc(newsize+1))==NULL) err(1,NULL);
oldfd = open(argv[1], O_RDONLY | O_BINARY, 0);
if (oldfd < 0)
err(1, "%s", argv[1]);
if ((oldsize = lseek(oldfd, 0, SEEK_END)) == -1 ||
(old = malloc(oldsize+1)) == NULL ||
lseek(oldfd, 0, SEEK_SET) != 0 ||
read(oldfd, old, oldsize) != oldsize ||
close(oldfd) == -1)
err(1, "%s", argv[1]);
if ((new = malloc(newsize + 1)) == NULL)
err(1, NULL);
oldpos=0;newpos=0;
oldpos = 0;
newpos = 0;
while (newpos < newsize) {
/* Read control data */
for (i = 0; i <= 2; i++) {
@ -209,12 +215,14 @@ int main(int argc,char * argv[])
err(1, "fclose(%s)", argv[3]);
/* Write the new file */
if(((fd=open(argv[2],O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666))<0) ||
(write(fd,new,newsize)!=newsize) || (close(fd)==-1))
newfd = open(argv[2], O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0666);
if (newfd < 0)
err(1, "%s", argv[2]);
if (write(newfd, new, newsize) != newsize || close(newfd) == -1)
err(1, "%s", argv[2]);
free(new);
free(old);
return 0;
return (0);
}