Blame example/isolsn.c

Packit dd8086
/*
Packit dd8086
  Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011, 2014
Packit dd8086
   Rocky Bernstein <rocky@gnu.org>
Packit dd8086
  
Packit dd8086
  This program is free software: you can redistribute it and/or modify
Packit dd8086
  it under the terms of the GNU General Public License as published by
Packit dd8086
  the Free Software Foundation, either version 3 of the License, or
Packit dd8086
  (at your option) any later version.
Packit dd8086
Packit dd8086
  This program is distributed in the hope that it will be useful,
Packit dd8086
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit dd8086
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit dd8086
  GNU General Public License for more details.
Packit dd8086
Packit dd8086
  You should have received a copy of the GNU General Public License
Packit dd8086
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
Packit dd8086
*/
Packit dd8086
Packit dd8086
/* Simple program to show using libiso9660 to get a file path
Packit dd8086
   for a given LSN of an ISO-9660 image.
Packit dd8086
Packit dd8086
   If a single argument is given, it is used as the LSN to search for.
Packit dd8086
   Otherwise we use a built-in default value.
Packit dd8086
Packit dd8086
   If a second argument is given, it is ISO 9660 image to use in the
Packit dd8086
   listing. Otherwise a compiled-in default ISO 9660 image name (that
Packit dd8086
   comes with the libcdio distribution) will be used.
Packit dd8086
 */
Packit dd8086
Packit dd8086
/* Set up a CD-DA image to test on which is in the libcdio distribution. */
Packit dd8086
#define ISO9660_IMAGE_PATH "../test/"
Packit dd8086
#define ISO9660_IMAGE ISO9660_IMAGE_PATH "copying.iso"
Packit dd8086
Packit dd8086
#ifdef HAVE_CONFIG_H
Packit dd8086
#include "config.h"
Packit dd8086
#define __CDIO_CONFIG_H__ 1
Packit dd8086
#endif
Packit dd8086
Packit dd8086
#ifdef HAVE_STDIO_H
Packit dd8086
#include <stdio.h>
Packit dd8086
#endif
Packit dd8086
#ifdef HAVE_STDLIB_H
Packit dd8086
#include <stdlib.h>
Packit dd8086
#endif
Packit dd8086
#ifdef HAVE_STRING_H
Packit dd8086
#include <string.h>
Packit dd8086
#endif
Packit dd8086
#ifdef HAVE_UNISTD_H
Packit dd8086
#include <unistd.h>
Packit dd8086
#endif
Packit dd8086
#ifdef HAVE_SYS_TYPES_H
Packit dd8086
#include <sys/types.h>
Packit dd8086
#endif
Packit dd8086
Packit dd8086
#include <cdio/cdio.h>
Packit dd8086
#include <cdio/iso9660.h>
Packit dd8086
Packit dd8086
#define print_vd_info(title, fn)	  \
Packit dd8086
  if (fn(p_iso, &psz_str)) {		  \
Packit dd8086
    printf(title ": %s\n", psz_str);	  \
Packit dd8086
  }					  \
Packit dd8086
  free(psz_str);			  \
Packit dd8086
  psz_str = NULL;			  
Packit dd8086
Packit dd8086
Packit dd8086
int
Packit dd8086
main(int argc, const char *argv[])
Packit dd8086
{
Packit dd8086
  char const *psz_fname;
Packit dd8086
  iso9660_t *p_iso;
Packit dd8086
  iso9660_stat_t *p_stat;
Packit dd8086
  lsn_t lsn = 24;
Packit dd8086
  char *psz_path = NULL;
Packit dd8086
  
Packit dd8086
  if (argc > 1) 
Packit dd8086
    lsn = strtol(argv[1], (char **)NULL, 10);
Packit dd8086
Packit dd8086
  if (argc > 2) 
Packit dd8086
    psz_fname = argv[2];
Packit dd8086
  else 
Packit dd8086
    psz_fname = ISO9660_IMAGE;
Packit dd8086
Packit dd8086
  p_iso = iso9660_open (psz_fname);
Packit dd8086
  
Packit dd8086
  if (NULL == p_iso) {
Packit dd8086
    fprintf(stderr, "Sorry, couldn't open %s as an ISO-9660 image\n", 
Packit dd8086
	    psz_fname);
Packit dd8086
    return 1;
Packit dd8086
  }
Packit dd8086
Packit dd8086
  p_stat = iso9660_ifs_find_lsn_with_path (p_iso, lsn, &psz_path);
Packit dd8086
  if (psz_path != NULL) {
Packit dd8086
    printf("File at LSN %u is %s\n", lsn, psz_path);
Packit dd8086
    free(psz_path);
Packit dd8086
  }
Packit dd8086
  iso9660_stat_free(p_stat);
Packit dd8086
Packit dd8086
  iso9660_close(p_iso);
Packit dd8086
  return 0;
Packit dd8086
}
Packit dd8086