File: res_vald.c

package info (click to toggle)
dosemu-freedos 1%3A0.0.b9r5a%2Betch.1-0etch1
  • links: PTS
  • area: contrib
  • in suites: etch
  • size: 19,744 kB
  • ctags: 23,279
  • sloc: ansic: 143,864; asm: 20,397; makefile: 3,868; perl: 1,106; yacc: 690; sh: 553; pascal: 297; xml: 150; cpp: 67
file content (57 lines) | stat: -rw-r--r-- 1,099 bytes parent folder | download | duplicates (2)
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
/* $Id: res_vald.c,v 1.1 2003/12/09 20:25:34 skaus Exp $

	Returns whether the passed-in file is a probably
	valid resource file.

	0 -> is valid
	1 -> no such file
	2 -> is a device
	3 -> not valid

*/

#include "../config.h"

#include <assert.h>
#include <fcntl.h>
#include <io.h>

#include "../include/command.h"
#include "../include/misc.h"
#include "../include/openf.h"
#include "../include/resource.h"
#include "../include/strings.typ"

/* Is called only, if the Strings resource had been found,
	hence, returning TRUE alsways. */
#pragma argsused
static int test_fct(res_majorid_t major
	, res_minorid_t minor
	, long length
	, FILE* f
	, void * const arg)
{	
	assert(major == RES_ID_STRINGS);
	return minor == STRING_RESOURCE_MINOR_ID? 1 : 2;
}

int validResFile(const char * const fnam)
{	int fd;

	assert(fnam);

	if((fd = open(fnam, O_RDONLY | O_BINARY)) < 0)
		return 1;

	if(isadev(fd)) {
		close(fd);
		return 2;
	}

	close(fd);
	if(enumFileResources(fnam
	 , RES_ID_STRINGS, test_fct, (void*)0) != 1)
		return 3;

	return 0;
}