OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [autotest/] [current/] [host/] [tmpfile.c] - Blame information for rev 800

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      tmpfile.c
4
//
5
//      Make a temporary data file for test purposes
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
// ####BSDALTCOPYRIGHTBEGIN####                                             
40
// -------------------------------------------                              
41
// Portions of this software may have been derived from FreeBSD, OpenBSD,   
42
// or other sources, and if so are covered by the appropriate copyright     
43
// and license included herein.                                             
44
// -------------------------------------------                              
45
// ####BSDALTCOPYRIGHTEND####                                               
46
//==========================================================================
47
//#####DESCRIPTIONBEGIN####
48
//
49
// Author(s):    hmt
50
// Contributors: hmt
51
// Date:         2000-10-23
52
//
53
//####DESCRIPTIONEND####
54
//
55
//==========================================================================
56
 
57
#include <stdio.h>
58
#include <errno.h>
59
 
60
int main( int argc, char **argv )
61
{
62
    FILE *f;
63
    int i;
64
    unsigned int size, iirandom, z, csum;
65
    char sizec, scratchc;
66
 
67
    if ( 3 > argc || 4 < argc) {
68
    usage:
69
        fprintf( stderr, "usage: %s filename length [seed]\n", argv[0] );
70
        exit(1);
71
    }
72
 
73
    f = fopen( argv[1], "rb" );
74
    if ( f ) {
75
        fclose( f );
76
        fprintf( stderr, "File %s already exists\n", argv[1] );
77
        goto usage;
78
    }
79
 
80
    i = sscanf( argv[2], "%u%1c%1c", &size, &sizec, &scratchc );
81
    if ( 0 >= i || 2 < i )
82
        goto usage;
83
 
84
    if ( 2 == i )
85
        switch ( sizec ) {
86
        case 'G': size *= 1024;
87
        case 'M': size *= 1024;
88
        case 'k': size *= 1024;
89
            break;
90
        case 'b': size *= 512;
91
            break;
92
        default:
93
            goto usage;
94
        }
95
 
96
    iirandom = 0;
97
    if ( 4 == argc ) {
98
        i = sscanf( argv[3], "%u%1c", &iirandom, &scratchc );
99
        if ( 0 >= i || 1 < i )
100
            goto usage;
101
    }
102
 
103
    f = fopen( argv[1], "wb" );
104
    if ( !f ) {
105
        perror( "fopen [create]" );
106
        goto usage;
107
    }
108
 
109
    csum = 0;
110
    iirandom += 0x23164920; // What date said
111
 
112
    if ( size > 4 ) i = size-4; else i = size;
113
 
114
    for ( /* i */ ; i > 0; i-- ) {
115
        iirandom = iirandom * 91 + 137;
116
        iirandom ^= iirandom >> 14 | iirandom << 7;
117
        z = (i ^ iirandom) & 0xff;
118
        // Keep a simple checksum in case we make some trick to check it in
119
        // the pretend filesystem.
120
        csum += z;
121
        csum = (csum >> (z & 31)) ^ (csum << (32 - (z & 31)));
122
        if ( 0 > putc( z, f ) ) {
123
            perror( "putc" );
124
            fclose( f );
125
            exit( 1 );
126
        }
127
    }
128
    // And bung the checksum on the end.
129
    for ( i = 4 ; i < size && i > 0; i-- ) {
130
        z = csum & 0xff;
131
        csum >>= 8;
132
        if ( 0 > putc( z, f ) ) {
133
            perror( "putc" );
134
            fclose( f );
135
            exit( 1 );
136
        }
137
    }
138
    fclose( f );
139
    exit( 0 );
140
}
141
 
142
// EOF awaitorder.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.