File: hook_mem.c

package info (click to toggle)
unar 1.1-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,664 kB
  • sloc: ansic: 52,939; objc: 39,563; cpp: 4,074; makefile: 99; perl: 10
file content (107 lines) | stat: -rw-r--r-- 3,133 bytes parent folder | download | duplicates (6)
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
102
103
104
105
106
107
#ifndef XADMASTER_HOOK_MEM_C
#define XADMASTER_HOOK_MEM_C

/*  $Id: hook_mem.c,v 1.5 2005/06/23 14:54:37 stoecker Exp $
    Memory IO hooks

    XAD library system for archive handling
    Copyright (C) 1998 and later by Dirk Stcker <soft@dstoecker.de>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifdef AMIGA
#include <proto/xadmaster.h>
#endif
#include "include/functions.h"
#include "include/SDI_compiler.h"

/*************************** read-from-mem hook **************************/

FUNCHOOK(InHookMem)
{
  struct xadMasterBaseP *xadMasterBase;

  xadMasterBase = ai->xaip_MasterBase;
  switch(param->xhp_Command)
  {
  case XADHC_READ:
    if(param->xhp_DataPos + param->xhp_BufferSize > ai->xaip_InSize)
      return XADERR_INPUT;
    if(param->xhp_BufferPtr)
      xadCopyMem(XADM ai->xaip_InMemory + param->xhp_DataPos, param->xhp_BufferPtr,
      param->xhp_BufferSize);
    param->xhp_DataPos += param->xhp_BufferSize;
    break;
  case XADHC_SEEK:
    if(((xadSignSize)param->xhp_DataPos + param->xhp_CommandData < 0) ||
    (param->xhp_DataPos + param->xhp_CommandData > ai->xaip_InSize))
      return XADERR_INPUT;
    param->xhp_DataPos += param->xhp_CommandData;
    break;
  case XADHC_INIT:
#ifdef DEBUG
  DebugHook("InHookMem: XADHC_INIT");
#endif
    param->xhp_DataPos = 0;
  case XADHC_FREE:
  case XADHC_ABORT:
    break;
  default: return XADERR_NOTSUPPORTED;
  }

  return 0;
}
ENDFUNC

/*************************** write-to-mem hook **************************/

FUNCHOOK(OutHookMem)
{
  struct xadMasterBaseP *xadMasterBase;

  xadMasterBase = ai->xaip_MasterBase;
  switch(param->xhp_Command)
  {
  case XADHC_WRITE:
    if(param->xhp_DataPos + param->xhp_BufferSize > ai->xaip_OutSize)
      return XADERR_OUTPUT;
    xadCopyMem(XADM param->xhp_BufferPtr, ai->xaip_OutMemory + param->xhp_DataPos,
    param->xhp_BufferSize);
    param->xhp_DataPos += param->xhp_BufferSize;
    break;
  case XADHC_SEEK:
    if(((xadSignSize)param->xhp_DataPos + param->xhp_CommandData < 0) ||
    (param->xhp_DataPos + param->xhp_CommandData > ai->xaip_OutSize))
      return XADERR_OUTPUT;
    param->xhp_DataPos += param->xhp_CommandData;
    break;
  case XADHC_INIT:
#ifdef DEBUG
  DebugHook("OutHookMem: XADHC_INIT");
#endif
    param->xhp_DataPos = 0;
  case XADHC_FREE:
  case XADHC_ABORT:
    break;
  default: return XADERR_NOTSUPPORTED;
  }

  return 0;
}
ENDFUNC

#endif /* XADMASTER_HOOK_MEM_C */