10-07-2011, 05:49 PM
this one should compile cleanly with gcc.
Code:
$ cat print-restore.c
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <sys/stat.h>
#include <time.h>
#include <getopt.h>
#include <unistd.h>
typedef uint32_t uint;
typedef uint64_t uint64;
typedef struct
{
uint version_bin;
char cwd[256];
uint argc;
char argv[30][256];
uint pw_min;
uint64 pw_skip;
char unused[232];
} restore_data_t;
static void read_restore (const char *eff_restore_file, restore_data_t *rd)
{
FILE *fp = fopen (eff_restore_file, "rb");
if (fp == NULL)
{
fprintf (stderr, "ERROR: restore file '%s': %s\n", eff_restore_file, strerror (errno));
exit (-1);
}
size_t nread = fread (rd, sizeof (restore_data_t), 1, fp);
if (nread != 1)
{
fprintf (stderr, "ERROR: cannot read %s\n", eff_restore_file);
exit (-1);
}
fclose (fp);
if (chdir (rd->cwd))
{
fprintf (stderr, "ERROR: cannot chdir to %s: %s\n", rd->cwd, strerror (errno));
exit (-1);
}
}
int main (int argc, char *argv[])
{
if (argc != 2)
{
fprintf (stderr, "usage: %s restore-file\n", argv[0]);
return (-1);
}
restore_data_t *rd = (restore_data_t *) malloc (sizeof (restore_data_t));
memset (rd, 0, sizeof (restore_data_t));
read_restore (argv[1], rd);
printf ("%llu\n", rd->pw_skip);
return 0;
}