X-Git-Url: https://hackdaworld.org/gitweb/?p=my-code%2Fapi.git;a=blobdiff_plain;f=bmp%2Fbmp.c;h=4d8c7acbc3a93c9cca03c3ab92cfd072669ca816;hp=2476140c61db6d033b521002ab682fbf5e38efe8;hb=a54cc5ef402ca4ba6202f13ee65e5f2fdcfd10c1;hpb=f8382861ee7bff6d129bd149579d26bf9b81ada0 diff --git a/bmp/bmp.c b/bmp/bmp.c index 2476140..4d8c7ac 100644 --- a/bmp/bmp.c +++ b/bmp/bmp.c @@ -59,6 +59,11 @@ int bmp_write_file(t_bmp *bmp) { int fill,xsize,size; + if(!(bmp->mode&WRITE)) { + dprintf(bmp->outfd,"[bmp] write mode not specified\n"); + return B_WRONG_MODE; + } + xsize=bmp->width*3; fill=(4-(xsize%4))%4; size=(xsize+fill)*bmp->height; @@ -79,7 +84,20 @@ int bmp_write_file(t_bmp *bmp) { bmp->info.ic=0; /* write it */ - ... + if((bmp->fd=open(bmp->file,O_WRONLY)<0) { + dprintf(bmp->outfd,"[bmp] unable to open file %s\n",bmp->file); + return B_NO_FILE; + } + + if(write(bmp->fd,&(bmp->hdr),BMP_H_SIZE)outfd,"[bmp] unable to write bmp header\n"); + return B_E_WRITE_DATA; + } + + if(write(bmp->fd,&(bmp->info),BMP_I_SIZE)outfd,"[bmp] unable to write bmp info\n"); + return B_E_WRITE_DATA; + } return B_SUCCESS; @@ -94,7 +112,7 @@ int bmp_read_file(t_bmp *bmp) { if(!(bmp->mode&READ)) { dprintf(bmp->outfd,"[bmp] read mode not specified"); - return B_NO_READ_MODE; + return B_WRONG_MODE; } if((bmp->fd=open(bmp->file,O_RDONLY))<0) {