File: librsrc.h

package info (click to toggle)
hfsutils 3.2.6-15
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,672 kB
  • sloc: ansic: 12,857; tcl: 1,937; makefile: 566; sh: 156; perl: 29
file content (101 lines) | stat: -rw-r--r-- 3,095 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
 * librsrc - library for reading and writing Macintosh resources
 * Copyright (C) 1996-1998 Robert Leslie
 *
 * 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
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: librsrc.h,v 1.5 1998/04/11 08:27:19 rob Exp $
 */

# include "rsrc.h"

#include <errno.h>

# define ERROR(code, str)  \
    do { rsrc_error = (str), errno = (code); goto fail; } while (0)

# ifdef DEBUG
#  define ASSERT(cond)	do { if (! (cond)) abort(); } while (0)
# else
#  define ASSERT(cond)	/* nothing */
# endif

# define SIZE(type, n)		((size_t) (sizeof(type) * (n)))
# define ALLOC(type, n)		((type *) malloc(SIZE(type, n)))
# define ALLOCX(type, n)	((n) ? ALLOC(type, n) : (type *) 0)
# define FREE(ptr)		((ptr) ? (void) free((void *) ptr) : (void) 0)

# define REALLOC(ptr, type, n)  \
    ((type *) ((ptr) ? realloc(ptr, SIZE(type, n)) : malloc(SIZE(type, n))))
# define REALLOCX(ptr, type, n)  \
    ((n) ? REALLOC(ptr, type, n) : (FREE(ptr), (type *) 0))

# define BMTST(bm, num)  \
    (((byte *) (bm))[(num) >> 3]  &  (0x80 >> ((num) & 0x07)))
# define BMSET(bm, num)  \
    (((byte *) (bm))[(num) >> 3] |=  (0x80 >> ((num) & 0x07)))
# define BMCLR(bm, num)  \
    (((byte *) (bm))[(num) >> 3] &= ~(0x80 >> ((num) & 0x07)))

# define STRINGIZE(x)		#x
# define STR(x)			STRINGIZE(x)

typedef unsigned char byte;

typedef struct {
  unsigned long dstart;
  unsigned long mstart;

  unsigned long dlen;
  unsigned long mlen;
} rsrchdr;

typedef struct {
  byte *data;

  unsigned short attrs;

  byte *tlist;
  byte *nlist;
} rsrcmap;

# define RSRC_MAP_READONLY	0x0080	/* set to make file read-only */
# define RSRC_MAP_COMPACT	0x0040	/* set to compact file on update */
# define RSRC_MAP_CHANGED	0x0020	/* set to write map on update */

# define RSRC_RES_SYSHEAP	0x40	/* set if read into system heap */
# define RSRC_RES_PURGEABLE	0x20	/* set if purgeable */
# define RSRC_RES_LOCKED	0x10	/* set if locked */
# define RSRC_RES_PROTECTED	0x08	/* set if protected */
# define RSRC_RES_PRELOAD	0x04	/* set if to be preloaded */
# define RSRC_RES_CHANGED	0x02	/* set if to be written to rsrc fork */

struct _rsrcfile_ {
  void *priv;			/* file-dependent private data */
  struct rsrcprocs procs;	/* procedures for accessing the file path */

  rsrchdr hdr;			/* resource header */
  rsrcmap map;			/* resource map */
};

typedef struct {
  struct _rsrcfile_ *rfile;
  const byte *ritem;

  unsigned short attrs;

  unsigned long len;
  byte data[1];
} rsrchandle;