projects
/
my-code
/
api.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f838286
)
some improvements to bmp_write_file function (still untested!)
author
hackbard
<hackbard>
Wed, 6 Oct 2004 18:40:57 +0000
(18:40 +0000)
committer
hackbard
<hackbard>
Wed, 6 Oct 2004 18:40:57 +0000
(18:40 +0000)
bmp/bmp.c
patch
|
blob
|
history
bmp/bmp.h
patch
|
blob
|
history
diff --git
a/bmp/bmp.c
b/bmp/bmp.c
index
2476140
..
4d8c7ac
100644
(file)
--- a/
bmp/bmp.c
+++ b/
bmp/bmp.c
@@
-59,6
+59,11
@@
int bmp_write_file(t_bmp *bmp) {
int fill,xsize,size;
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;
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 */
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)<BMP_H_SIZE) {
+ dprintf(bmp->outfd,"[bmp] unable to write bmp header\n");
+ return B_E_WRITE_DATA;
+ }
+
+ if(write(bmp->fd,&(bmp->info),BMP_I_SIZE)<BMP_I_SIZE) {
+ dprintf(bmp->outfd,"[bmp] unable to write bmp info\n");
+ return B_E_WRITE_DATA;
+ }
return B_SUCCESS;
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");
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) {
}
if((bmp->fd=open(bmp->file,O_RDONLY))<0) {
diff --git
a/bmp/bmp.h
b/bmp/bmp.h
index
58bee0a
..
f25007d
100644
(file)
--- a/
bmp/bmp.h
+++ b/
bmp/bmp.h
@@
-12,13
+12,14
@@
/* defines */
#define B_SUCCESS 1
#define B_ERROR -1
/* defines */
#define B_SUCCESS 1
#define B_ERROR -1
-#define B_
NO_READ
_MODE -2
+#define B_
WRONG
_MODE -2
#define B_NO_FILE -3
#define B_NO_HI -4
#define B_NO_SUPPORT -5
#define B_HI_FAIL -6
#define B_E_MEM -7
#define B_NO_FILE -3
#define B_NO_HI -4
#define B_NO_SUPPORT -5
#define B_HI_FAIL -6
#define B_E_MEM -7
-#define B_E_READ_DATA -8;
+#define B_E_READ_DATA -8
+#define B_E_WRITE_DATA -9
#define MAX_CHARS_FILE 32
#define BMP_H_SIZE 14
#define BMP_I_SIZE 40
#define MAX_CHARS_FILE 32
#define BMP_H_SIZE 14
#define BMP_I_SIZE 40