Logo Search packages:      
Sourcecode: cbmconvert version File versions  Download package

static int init_files ( const char *  filename  )  [static]

Initialize the files

Parameters:
filename the base file name
Returns:
0 on success;
1 on out of memory;
2 if not all input files could be opened;
3 if no output could be created

Definition at line 71 of file zip2disk.c.

References fname, infile, inname, out_suffix, outfile, outname, and PATH_SEPARATOR.

{
  /* flag: was an output file name already specified? */
  int outflag = !!outname;
  int i = strlen (filename);

  if (!(inname = malloc (i + 3)) ||
      (!outname && !(outname = malloc (i + sizeof out_suffix))))
    return 1;

  /* copy the base filename */
  memcpy (inname, filename, i);

  if (!outflag) {
    memcpy (outname, filename, i);
    memcpy (outname + i, out_suffix, sizeof out_suffix);
  }

  /* modify input filename */

  for (fname = inname + i;
       fname > inname && *fname != PATH_SEPARATOR; fname--);
  if (fname > inname)
    fname++;
  fname[1] = '!';
  memcpy (fname + 2, filename + (fname - inname), i);

  /* try to find the input files */

  for (*fname = '1'; *fname < '5'; (*fname)++) {
    infile = fopen (inname, "rb");

    if (infile)
      fclose (infile);
    else
      return 2;
  }

  infile = 0;

  /* try to create output file */

  if (!(outfile = fopen (outname, "wb"))) {
    return 3;
  }

  return 0;
}


Generated by  Doxygen 1.6.0   Back to index