Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct {
- FILE *handle;
- const char *fname;
- } mystruct;
- mystruct *open_file(const char *file)
- {
- mystruct *r = NULL;
- const char *fname = NULL;
- FILE *handle = NULL;
- r = malloc(sizeof(r));
- if (r == NULL) goto life_sucks;
- handle = fopen(file, "r");
- if (handle == NULL) goto life_sucks;
- fname = strdup(file);
- if (fname == NULL) goto life_sucks;
- r.handle = handle;
- r.fname = fname;
- return r;
- life_sucks:
- free(fname);
- if (handle != NULL) fclose(handle);
- free(r);
- return NULL
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement