libpsys
changeset 18:66956b1e5e3f
added missing psys_create_attr/psys_free_attr and some checking in load_attr
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Thu, 13 Sep 2012 04:10:38 +0300 |
parents | 7fbed016e739 |
children | fbccc3c0d43e |
files | src/pattr.c src/pattr.h |
diffstat | 2 files changed, 25 insertions(+), 0 deletions(-) [+] |
line diff
1.1 --- a/src/pattr.c Tue Sep 11 03:26:13 2012 +0300 1.2 +++ b/src/pattr.c Thu Sep 13 04:10:38 2012 +0300 1.3 @@ -48,6 +48,24 @@ 1.4 tex_cls = cls; 1.5 } 1.6 1.7 +struct psys_attributes *psys_create_attr(void) 1.8 +{ 1.9 + struct psys_attributes *attr = malloc(sizeof *attr); 1.10 + if(attr) { 1.11 + if(psys_init_attr(attr) == -1) { 1.12 + free(attr); 1.13 + attr = 0; 1.14 + } 1.15 + } 1.16 + return attr; 1.17 +} 1.18 + 1.19 +void psys_free_attr(struct psys_attributes *attr) 1.20 +{ 1.21 + psys_destroy_attr(attr); 1.22 + free(attr); 1.23 +} 1.24 + 1.25 int psys_init_attr(struct psys_attributes *attr) 1.26 { 1.27 memset(attr, 0, sizeof *attr); 1.28 @@ -143,6 +161,10 @@ 1.29 FILE *fp; 1.30 int res; 1.31 1.32 + if(!fname) { 1.33 + return -1; 1.34 + } 1.35 + 1.36 if(!(fp = fopen(fname, "r"))) { 1.37 fprintf(stderr, "%s: failed to read file: %s: %s\n", __func__, fname, strerror(errno)); 1.38 return -1;
2.1 --- a/src/pattr.h Tue Sep 11 03:26:13 2012 +0300 2.2 +++ b/src/pattr.h Thu Sep 13 04:10:38 2012 +0300 2.3 @@ -36,6 +36,9 @@ 2.4 2.5 void psys_texture_loader(unsigned int (*load)(const char*, void*), void (*unload)(unsigned int, void*), void *cls); 2.6 2.7 +struct psys_attributes *psys_create_attr(void); 2.8 +void psys_free_attr(struct psys_attributes *attr); 2.9 + 2.10 int psys_init_attr(struct psys_attributes *attr); 2.11 void psys_destroy_attr(struct psys_attributes *attr); 2.12