• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Determine fill pattern for a section.
2    Copyright (C) 2002 Red Hat, Inc.
3    Written by Ulrich Drepper <drepper@redhat.com>, 2002.
4 
5    This program is Open Source software; you can redistribute it and/or
6    modify it under the terms of the Open Software License version 1.0 as
7    published by the Open Source Initiative.
8 
9    You should have received a copy of the Open Software License along
10    with this program; if not, you may obtain a copy of the Open Software
11    License version 1.0 from http://www.opensource.org/licenses/osl.php or
12    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
13    3001 King Ranch Road, Ukiah, CA 95482.   */
14 
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
18 
19 #include <stdlib.h>
20 #include <string.h>
21 
22 #include <libasmP.h>
23 #include <system.h>
24 
25 
26 int
asm_fill(asmscn,bytes,len)27 asm_fill (asmscn, bytes, len)
28      AsmScn_t *asmscn;
29      void *bytes;
30      size_t len;
31 {
32   struct FillPattern *pattern;
33   struct FillPattern *old_pattern;
34 
35   if (asmscn == NULL)
36     /* Some earlier error.  */
37     return -1;
38 
39   if (bytes == NULL)
40     /* Use the default pattern.  */
41     pattern = (struct FillPattern *) __libasm_default_pattern;
42   else
43     {
44       /* Allocate appropriate memory.  */
45       pattern = (struct FillPattern *) malloc (sizeof (struct FillPattern)
46 					       + len);
47       if (pattern == NULL)
48 	return -1;
49 
50       pattern->len = len;
51       memcpy (pattern->bytes, bytes, len);
52     }
53 
54   old_pattern = asmscn->pattern;
55   asmscn->pattern = pattern;
56 
57   /* Free the old data structure if we have allocated it.  */
58   if (old_pattern != __libasm_default_pattern)
59     free (old_pattern);
60 
61   return 0;
62 }
63