( psc | 2012. 12. 12., sze – 12:22 )

csak példa, hibát tartalmazhat, fejből irom, nem is ez a lényeg.


handle_t* archive_open(char* filename)
{
   handle_t* handle = NULL;
   FILE* file = NULL;
   header_t* header = NULL;
   lofasz_t* lofasz = NULL;

   handle = malloc(sizeof(handle_t));
   if (!handle) {
      global_error=E_NOMEM;
      goto error;
   }

   file = fopen(filename, ... );
   if (!file) {
      global_error=E_FILEERROR;
      goto error;
   }

   header = malloc(sizeof(header_t));
   if (!header) {
      global_error=E_NOMEM;
      goto error;
   }

   if (fread((void*)header,sizeof(header_t),1,file) < sizeof(header_t))  {
      global_error=E_FILEERROR;
      goto error;
   }

   lofasz = malloc(sizeof(lofasz_t)); 
   if (!lofasz) {
      global_error=E_NOMEM
      goto error;
   }

   blablabla
   ....
   ....

   global_error=E_OK;
   return handle;

  error:
   if (lofasz) free(lofasz);
   if (header) free(header);
   if (file) fclose(file);
   if (handle) free(handle);
   return NULL;
}