~ubuntu-branches/ubuntu/precise/arj/precise-security

« back to all changes in this revision

Viewing changes to ext_hdr.c

  • Committer: Bazaar Package Importer
  • Author(s): Guillem Jover
  • Date: 2004-06-27 08:07:09 UTC
  • Revision ID: james.westby@ubuntu.com-20040627080709-1gkxm72ex66gkwe4
Tags: upstream-3.10.21
ImportĀ upstreamĀ versionĀ 3.10.21

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: ext_hdr.c,v 1.1.1.1 2002/03/28 00:02:52 andrew_belov Exp $
 
3
 * ---------------------------------------------------------------------------
 
4
 * Handy functions for dealing with extended headers.
 
5
 *
 
6
 */
 
7
 
 
8
#include "arj.h"
 
9
 
 
10
DEBUGHDR(__FILE__)                      /* Debug information block */
 
11
 
 
12
/* Allocates a per-file extended header structure */
 
13
 
 
14
struct ext_hdr FAR *eh_alloc()
 
15
{
 
16
 struct ext_hdr FAR *rc;
 
17
 
 
18
 rc=(struct ext_hdr FAR *)farmalloc_msg(sizeof(struct ext_hdr));
 
19
 far_memset((char FAR *)rc, 0, sizeof(struct ext_hdr));
 
20
 return(rc);
 
21
}
 
22
 
 
23
/* Locates a block with the specified tag, returning pointer to it */
 
24
 
 
25
struct ext_hdr FAR *eh_lookup(struct ext_hdr FAR *eh, char tag)
 
26
{
 
27
 while(eh->next!=NULL)
 
28
 {
 
29
  if(eh->tag==tag)
 
30
   return(eh);
 
31
  eh=eh->next;
 
32
 }
 
33
 return(NULL);
 
34
}
 
35
 
 
36
/* Locates an unfinalized block */
 
37
 
 
38
struct ext_hdr FAR *eh_find_pending(struct ext_hdr FAR *eh)
 
39
{
 
40
 if(eh==NULL)
 
41
  return(NULL);
 
42
 while(eh->next!=NULL)
 
43
 {
 
44
  if(EH_STATUS(eh)!=EH_FINALIZED)
 
45
   return(eh);
 
46
  eh=eh->next;
 
47
 }
 
48
 return(NULL);
 
49
}
 
50
 
 
51
/* Inserts a new block into an instantiated extended header structure. If the
 
52
   block is given as NULL, performs reallocation only */
 
53
 
 
54
struct ext_hdr FAR *eh_append(struct ext_hdr FAR *eh, char tag, char FAR *block, unsigned int size)
 
55
{
 
56
 struct ext_hdr FAR *p_eh;
 
57
 
 
58
 if((p_eh=eh_lookup(eh, tag))==NULL)
 
59
 {
 
60
  for(p_eh=eh; p_eh->next!=NULL; p_eh=p_eh->next);
 
61
  p_eh->tag=tag;
 
62
  p_eh->next=eh_alloc();
 
63
 }
 
64
 p_eh->raw=(char FAR *)farrealloc_msg(p_eh->raw, p_eh->size+size);
 
65
 if(block!=NULL)
 
66
  far_memmove(p_eh->raw+p_eh->size, block, size);
 
67
 p_eh->size+=size;
 
68
 return(p_eh);
 
69
}
 
70
 
 
71
/* Releases the extended header structure */
 
72
 
 
73
void eh_release(struct ext_hdr FAR *eh)
 
74
{
 
75
 struct ext_hdr FAR *p_eh;
 
76
 
 
77
 while((p_eh=eh->next)!=NULL)
 
78
 {
 
79
  if(eh->raw!=NULL)
 
80
   farfree(eh->raw);
 
81
  farfree(eh);
 
82
  eh=p_eh;
 
83
 }
 
84
}