Revision 323
more stuff
xpm_utils.c | ||
---|---|---|
8 | 8 |
#include <stdlib.h> |
9 | 9 |
#include <string.h> |
10 | 10 |
|
11 |
void xpm_save_as_xpm2(const char **p, const char *s){
|
|
11 |
void xpm_save_as_xpm2(const char* const* p, const char *s){
|
|
12 | 12 |
FILE *f = fopen(s, "w"); |
13 | 13 |
int w, h, num_colors, chars_per_pixel; |
14 | 14 |
sscanf(p[0], "%d %d %d %d", &w, &h, &num_colors, &chars_per_pixel); |
... | ... | |
22 | 22 |
FILE *f = fopen(fpath, "r"); |
23 | 23 |
if(f == NULL) return NULL; |
24 | 24 |
size_t len = 1024; char *line_buf = malloc(len*sizeof(char)); |
25 |
int sz;
|
|
25 |
ssize_t sz;
|
|
26 | 26 |
|
27 | 27 |
char **ret = NULL; |
28 | 28 |
|
29 |
int w, h, num_colors, chars_per_pixel;
|
|
29 |
unsigned w, h, num_colors, chars_per_pixel;
|
|
30 | 30 |
|
31 | 31 |
sz = getline(&line_buf, &len, f);{ |
32 | 32 |
sscanf(line_buf, "%d %d %d %d", &w, &h, &num_colors, &chars_per_pixel); |
33 | 33 |
ret = malloc((1+num_colors+h)*sizeof(char*)); |
34 | 34 |
} |
35 |
ret[0] = malloc((sz+1)*sizeof(char)); if(ret[0] == NULL){ free(ret); return NULL; } |
|
35 |
ret[0] = malloc(((unsigned)sz+1)*sizeof(char)); if(ret[0] == NULL){ free(ret); return NULL; }
|
|
36 | 36 |
strcpy(ret[0], line_buf); |
37 | 37 |
|
38 |
for(int i = 1; i < 1+num_colors+h; ++i){
|
|
38 |
for(size_t i = 1; i < 1+num_colors+h; ++i){
|
|
39 | 39 |
sz = getline(&line_buf, &len, f); |
40 |
ret[i] = malloc((sz+1)*sizeof(char)); |
|
40 |
ret[i] = malloc(((unsigned)sz+1)*sizeof(char));
|
|
41 | 41 |
if(ret[i] == NULL){ |
42 |
for(int j = 0; j < i; ++j)
|
|
42 |
for(size_t j = 0; j < i; ++j)
|
|
43 | 43 |
free(ret[i]); |
44 | 44 |
free(ret); |
45 | 45 |
return NULL; |
... | ... | |
48 | 48 |
ret[i][sz-1] = '\0'; |
49 | 49 |
} |
50 | 50 |
fclose(f); f = NULL; |
51 |
free(line_buf); line_buf = NULL; |
|
51 | 52 |
return ret; |
52 | 53 |
} |
Also available in: Unified diff