~ubuntu-branches/ubuntu/utopic/cdrdao/utopic

« back to all changes in this revision

Viewing changes to scsilib/libschily/fillbytes.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Suffield
  • Date: 2004-06-24 22:33:16 UTC
  • Revision ID: james.westby@ubuntu.com-20040624223316-534onzugaeeyq61j
Tags: upstream-1.1.9
ImportĀ upstreamĀ versionĀ 1.1.9

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* @(#)fillbytes.c      1.13 03/06/15 Copyright 1987, 1995-2003 J. Schilling */
 
2
/*
 
3
 *      fill memory with data
 
4
 *
 
5
 *      Copyright (c) 1987, 1995-2003 J. Schilling
 
6
 */
 
7
/*
 
8
 * This program is free software; you can redistribute it and/or modify
 
9
 * it under the terms of the GNU General Public License as published by
 
10
 * the Free Software Foundation; either version 2, or (at your option)
 
11
 * any later version.
 
12
 *
 
13
 * This program is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
 * GNU General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU General Public License along with
 
19
 * this program; see the file COPYING.  If not, write to the Free Software
 
20
 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
21
 */
 
22
 
 
23
#include <standard.h>
 
24
#include <align.h>
 
25
#include <schily.h>
 
26
 
 
27
#define DO8(a)  a; a; a; a; a; a; a; a;
 
28
 
 
29
#define cval    ((char) lval)
 
30
 
 
31
#ifdef  PROTOTYPES
 
32
EXPORT char *
 
33
fillbytes(void *tov, int cnt, char val)
 
34
#else
 
35
EXPORT char *
 
36
fillbytes(tov, cnt, val)
 
37
        void    *tov;
 
38
        int     cnt;
 
39
        char    val;
 
40
#endif
 
41
{
 
42
        register char   *to = (char *)tov;
 
43
        register int    n;
 
44
        register long   lval;
 
45
 
 
46
        /*
 
47
         * If we change cnt to be unsigned, check for == instead of <=
 
48
         */
 
49
        if ((n = cnt) <= 0)
 
50
                return (to);
 
51
 
 
52
        lval = val & 0xFF;
 
53
 
 
54
        /*
 
55
         * Assign byte-wise until properly aligned for a long pointer.
 
56
         */
 
57
        while (--n >= 0 && !laligned(to)) {
 
58
                *to++ = cval;
 
59
        }
 
60
        n++;
 
61
 
 
62
        if (n >= (int)(8 * sizeof (long))) {
 
63
                register int rem = n % (8 * sizeof (long));
 
64
 
 
65
                lval |= (lval<<8);
 
66
                lval |= (lval<<16);
 
67
#if SIZE_LONG > SIZE_INT
 
68
                lval |= (lval<<32);
 
69
#endif
 
70
 
 
71
                n /= (8 * sizeof (long));
 
72
                {
 
73
                        register long *tol = (long *)to;
 
74
 
 
75
                        do {
 
76
                                DO8 (*tol++ = lval);
 
77
                        } while (--n > 0);
 
78
 
 
79
                        to = (char *)tol;
 
80
                }
 
81
                n = rem;
 
82
 
 
83
                if (n >= 8) {
 
84
                        n -= 8;
 
85
                        do {
 
86
                                DO8 (*to++ = cval);
 
87
                        } while ((n -= 8) >= 0);
 
88
                        n += 8;
 
89
                }
 
90
                if (n > 0) do {
 
91
                        *to++ = cval;
 
92
                } while (--n > 0);
 
93
                return (to);
 
94
        }
 
95
        if (n > 0) do {
 
96
                *to++ = cval;
 
97
        } while (--n > 0);
 
98
        return (to);
 
99
}