File: file.c

package info (click to toggle)
e2undel 0.82-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 316 kB
  • ctags: 300
  • sloc: ansic: 4,112; makefile: 109
file content (58 lines) | stat: -rw-r--r-- 1,077 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "file.h"
#include "common.h"

/* (C) Oliver Diedrich */
/* this file may be redistributed under the terms of the */
/* GNU Public License (GPL), see www.gnu.org */


int main(int argc, char *argv[])
{
  char fname[PATH_MAX];
  unsigned char buf[FSIZE+1];
  int f;
  int n, i;
  
  if (argc < 2) return -1;

  if (!apprentice())
  {
    fprintf(stderr, "trouble with magic types.\n");
    return 0;
  }

  for (i=1; i<argc; i++)
  {
    strncpy(fname, argv[i], PATH_MAX);
    f = open(fname, O_RDONLY);
    if (-1 == f)
    {
      perror(fname);
      return 0;
    }
    n = read(f, buf, FSIZE);
    if (-1 == n)
    {
      perror(fname);
      close(f);
      continue;
    }

    fprintf(stderr, "%s: ", argv[i]);
    if (0 == n)
    {
      fprintf(stderr, "empty\n");
      close(f);
      continue;
    }
    if (softmagic(buf, n)) fprintf(stderr, "%s", buf);
    else
    {
      if (ascmagic(buf, n)) fprintf(stderr, "%s", buf);
      else fprintf(stderr, "data");
    }
    fprintf(stderr, "\n");
    close(f);
  }   /* for i */
  return 1;
}   /* main() */