Print out entire file. (File must fit in memory though.)

This commit is contained in:
rocky
2006-04-11 01:02:18 +00:00
parent 6eeb46aea7
commit e11190d0b2

View File

@@ -1,7 +1,7 @@
/* /*
$Id: udf2.c,v 1.3 2006/02/02 04:37:29 rocky Exp $ $Id: udf2.c,v 1.4 2006/04/11 01:02:18 rocky Exp $
Copyright (C) 2005 Rocky Bernstein <rocky@panix.com> Copyright (C) 2005, 2006 Rocky Bernstein <rockyb@users.sourceforge.net>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -52,6 +52,8 @@
#include <sys/types.h> #include <sys/types.h>
#endif #endif
#define CEILING(x, y) ((x+(y-1))/y)
#define udf_PATH_DELIMITERS "/\\" #define udf_PATH_DELIMITERS "/\\"
static void static void
@@ -67,7 +69,7 @@ print_file_info(const udf_dirent_t *p_udf_dirent, const char* psz_dirname)
psz_mode)); psz_mode));
printf("%4d ", udf_get_link_count(p_udf_dirent)); printf("%4d ", udf_get_link_count(p_udf_dirent));
printf("%ld ", (long unsigned int) udf_get_file_length(p_udf_dirent)); printf("%ld ", (long unsigned int) udf_get_file_length(p_udf_dirent));
printf("%s %s", *psz_fname ? psz_fname : "/", ctime(&mod_time)); printf("%s %s\n", *psz_fname ? psz_fname : "/", ctime(&mod_time));
} }
int int
@@ -106,9 +108,16 @@ main(int argc, const char *argv[])
p_udf_file = udf_fopen(p_udf_root, psz_udf_fname); p_udf_file = udf_fopen(p_udf_root, psz_udf_fname);
print_file_info(p_udf_file, udf_get_filename(p_udf_file)); print_file_info(p_udf_file, udf_get_filename(p_udf_file));
{ {
char buf[2048]; long unsigned int i_file_length = udf_get_file_length(p_udf_file);
udf_read_block(p_udf_file, buf, 1); char *p_buf;
printf("%s", buf); unsigned int i_blocks = CEILING(i_file_length, UDF_BLOCKSIZE);
char fmt_string[100] = {'\0'};
snprintf(fmt_string, sizeof(fmt_string), "%%%lus", i_file_length);
p_buf = (char *) calloc(sizeof(char), UDF_BLOCKSIZE*i_blocks);
udf_read_block(p_udf_file, p_buf, i_blocks);
printf(fmt_string, p_buf);
free(p_buf);
} }
udf_dirent_free(p_udf_file); udf_dirent_free(p_udf_file);
udf_dirent_free(p_udf_root); udf_dirent_free(p_udf_root);